Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Fixed-point arithmetic
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Binary fixed-point multiplication=== Consider the task of computing the product of 1.2 and 5.6 with binary fixed point using 16 fraction bits. To represent the two numbers, one multiplies them by 2<sup>16</sup>, obtaining {{thinspace|78|643}}.2 and {{thinspace|367|001}}.6; and round these values the nearest integers, obtaining {{thinspace|78|643}} and {{thinspace|367|002}}. These numbers will fit comfortably into a 32-bit word with two's complement signed format. Multiplying these integers together gives the 35-bit integer {{thinspace|28|862|138|286}} with 32 fraction bits, without any rounding. Note that storing this value directly into a 32-bit integer variable would result in overflow and loss of the most significant bits. In practice, it would probably be stored in a signed 64-bit integer variable or [[register (computing)|register]]. If the result is to be stored in the same format as the data, with 16 fraction bits, that integer should be divided by 2<sup>16</sup>, which gives approximately {{thinspace|440|401}}.28, and then rounded to the nearest integer. This effect can be achieved by adding 2<sup>15</sup> and then shifting the result by 16 bits. The result is {{thinspace|440|401}}, which represents the value 6.{{thinspace|719|985|961|914|062|5}}. Taking into account the precision of the format, that value is better expressed as 6.{{thinspace|719|986}} Β± 0.{{thinspace|000|008}} (not counting the error that comes from the operand approximations). The correct result would be 1.2 Γ 5.6 = 6.72. For a more complicated example, suppose that the two numbers 1.2 and 5.6 are represented in 32-bit fixed point format with 30 and 20 fraction bits, respectively. Scaling by 2<sup>30</sup> and 2<sup>20</sup> gives {{thinspace|1|288|490|188}}.8 and {{thinspace|5|872|025}}.6, that round to {{thinspace|1|288|490|189}} and {{thinspace|5|872|026}}, respectively. Both numbers still fit in a 32-bit signed integer variable, and represent the fractions : 1.{{thinspace|200|000|000|186|264|514|923|095|703|125}} and : 5.{{thinspace|600|000|381|469|726|562|50}} Their product is (exactly) the 53-bit integer {{thinspace|7|566|047|890|552|914}}, which has 30+20 = 50 implied fraction bits and therefore represents the fraction : 6.{{thinspace|720|000|458|806|753|229|623|609|513|510|018|587|112|426|757|812|50}} If we choose to represent this value in signed 16-bit fixed format with 8 fraction bits, we must divide the integer product by 2<sup>50β8</sup> = 2<sup>42</sup> and round the result; which can be achieved by adding 2<sup>41</sup> and shifting by 42 bits. The result is 1720, representing the value 1720/2<sup>8</sup> = 6.{{thinspace|718|75}}, or approximately 6.719 Β± 0.002.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)