Content deleted Content added
m →References: Task 16: replaced (2×) / removed (0×) deprecated |dead-url= and |deadurl= with |url-status=; |
Artoria2e5 (talk | contribs) stop saying floating point if you are trying to say REAL NUMBERS. the point does not even float! |
||
Line 1:
{{More citations needed|date=December 2009}}
{{Use dmy dates|date=August 2019|cs1-dates=y}}
'''Binary scaling''' is a [[computer programming]] technique used typically in embedded [[C (programming language)|C]], [[Digital signal processing|DSP]] and [[assembly language|assembler]] programs to implement
==Overview==
A representation of a
A position for the 'binary point' is chosen for each variable to be represented, and binary shifts associated with arithmetic operations are adjusted accordingly. The binary scaling corresponds in [[Q (number format)]] to the first digit, i.e. Q1.15 is a 16 bit integer scaled with one bit as integer and fifteen as fractional. A Bscal 1 or Q1.15 number would represent approximately 1.999 to −2.0.
To give an example, a common way to use [[arbitrary-precision arithmetic|integer arithmetic]] to simulate floating point, using 32 bit numbers, is to multiply the coefficients by 65536.
Line 21 ⟶ 20:
To convert it back to B16, divide it by 2<sup>16</sup>.
This gives 440400B16, which when converted back to a floating point number (by dividing again by 2<sup>16</sup>, but holding the result as floating point) gives 6.71999. The correct
==Re-scaling after multiplication==
Line 44 ⟶ 43:
1.4 @ B2 is 1.4 * (2 ^ (wordsize-2-1)) == 1.4 * 2 ^ 29 == 0x2CCCCCCD
Note that here the 1.4 values is very well represented with 30 fraction bits. A 32 bit [[IEEE floating-point standard|floating-point number]] has 23 bits to store the fraction in. This is why B scaling is always more accurate than floating point of the same word size. This is especially useful in [[integrator]]s or repeated summing of small quantities where [[rounding error]] can be a subtle but very dangerous problem when using floating point.
Now a larger number 15.2 at B4.
Line 64 ⟶ 62:
=={{anchor|BAM}}Binary angles==
<!-- Binary angle (computing), Binary Angular Measurement System, and Binary radian redirect here -->
[[Image:Binary angles.svg|360px|thumb|Binary scaling (B0) Representation of angles. <span style="color:black">Black</span> is traditional degrees representation, <span style="color:green">green</span> is
Binary angles are mapped using B0, with 0 as 0 degrees, 0.5 as 90° (or <math>\frac{\pi}{2}</math>), −1.0 or 0.9999999 as 180° (or π) and −0.5 as 270° (or <math>\frac{3\pi}{2}</math>). When these binary angles are added using normal [[two's complement]] mathematics, the rotation of the angles is correct, even when crossing the sign boundary (this of course does away with checks for angle ≥ 360° when handling normal degrees<ref name="Hargreaves_2010"/>
|