Binary scaling: Difference between revisions

Content deleted Content added
Binary angles: multiplying -1.0 by 360 is never going to give you -180...
Line 45:
Consider a 32 bit word size, and two variables, one with a B scaling of 2 and the other with a scaling of 4.
 
1.4 @ B2 is 1.4 * (2<sup> ^ (wordsize-2-1</sup>)) == 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.
Line 52:
Now a larger number 15.2 at B4.
 
15.2 @ B4 is 15.2 * (2 ^ (wordsize-4-1)) == 15.2 * 2 ^ 27 == 0x7999999A
 
Again the number of bits to store the fraction is 28 bits.
Multiplying these 32 bit numbers give the 64 bit result {{mono|0x1547AE14A51EB852}}
 
This result is in B7 in a 64 bit word. Shifting it down by 32 bits gives the result in B7 in 32 bits.
 
0x1547AE14
 
To convert back to floating point, divide this by {{code|1=(2^(wordsize-7-1)) == 21.2800000099}}
 
Various scalings may be used. B0 for instance can be used to represent any number between -1 and 0.999999999.