Binary scaling: Difference between revisions

Content deleted Content added
No edit summary
+rcat
 
(167 intermediate revisions by 85 users not shown)
Line 1:
#REDIRECT [[Fixed-point arithmetic#Binary scaling]] {{R from merge}} {{R to section}} {{R with possibilities}}
 
 
== Binary scaling ==
 
Binary scaling is a technique used mainly by embedded C, DSP and assembler programmers to
perform a psuedo floating point using integer arithmetic.
It is faster than floating point and is more accurate, but care must be taken not allow
overflow.
 
A position for the virtual binary point is taken, and then subsequent arithetic operations
determine the resultants binary point.
 
This obeys the mathematical laws of [[Exponentiation]].
 
To give an example, a common way to use integer maths to simulate floating point
is to nmultiply the co-effiecents by 65536.
 
This will place the binary point at B16.
 
For instance to represent 1.2 and 5.6 floating point real numbers as B16 one multiplies them by 2 ^ 16
giving
 
78643B16 and 367001B16
 
Multiplying these together gives
 
28862059643B32
 
The result will however be in B32 (according to the rules of exponentiation)
 
To convert it back to B16 we need to divide it by 2 ^ 16.
 
This gives 440400B16, which when converted back to a floating point number (by diving again by
2 ^ 16, but holding the result as floating point) gives 6.71999.
The correct floating point result is of course 6.72.
 
Various scalings maybe used. B0 for instance can be used to represent
any number between -1 and 0.999999999.
 
Binary angles are mapped using B0, with 0 as 0 degrees, 0.5 as 90 (or pi/4), -1.0 or 0.999999 as 180 (or pi/2)
and 270 as -0.5 (or 3.pi/2).
 
 
This technique was used in the 1970's and 80's for real time computing that was mathematically intensive, such as [[flight simulation]]. The code was often commented with the binary scalings of the
intermediate results of equations.