Content deleted Content added
m Date/fix the maintenance tags using AWB |
m -wikify notice |
||
Line 1:
{{Mergeto|Fixed-point arithmetic|date=December 2006}}
'''Binary scaling''' is a [[computer programming]] technique used mainly by embedded [[C programming language|C]], [[Digital signal processing|DSP]] and [[assembly language|assembler]] programmers to perform a psuedo [[floating point]] using [[integer]] arithmetic.▼
It is faster than directly using floating point instructions and is more accurate, but care must be taken not allow [[overflow]].▼
▲'''Binary scaling''' is a [[computer programming]] technique used mainly by embedded [[C programming language|C]], [[Digital signal processing|DSP]] and [[assembly language|assembler]] programmers to
▲It is faster than floating point and is more accurate, but care must be taken not allow
A position for the virtual 'binary point' is taken, and then subsequent arithetic operations
determine the resultants 'binary point'.
Binary points obey the mathematical laws of [[
To give an example, a common way to use integer maths to simulate floating point
is to multiply the co-
utility [[nxcal]] to linearise the output of [[touchscreen]]s.
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
78643 and 367001
Line 26 ⟶ 22:
28862059643
To convert it back to B16
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
The scaling range here is for any number between 65535.9999 and -65536.0 with 16 bits to hold fractional quantities (of course assuming the use of a 64 bit result register). Note that some computer architectures may restrict arithmetic to 32 bit results. In this case extreme care must be taken not to overflow the 32 bit register. For other number ranges the binary scale can be adjusted for optimum accuracy.
== Re-Scaling after Multiplication ==
Line 60 ⟶ 54:
Note that here the 1.4 values is very well represented with 30 fraction bits ! A 32 bit [[IEEE floating-point standard|real number]] has 23 bits to store the fraction in. This is why B scaling
is always more accurate than floating point of the same wordsize.
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 75 ⟶ 68:
0x1547AE14
To convert back to floating point,
Various scalings maybe used. B0 for instance can be used to represent any number between -1 and 0.999999999.
== Binary Angles ==
Binary angles are mapped using B0, with 0 as 0 degrees, 0.5 as 90 (or pi/4), -1.0 or 0.9999999 as 180 (or pi/2) and 270 as -0.5 (or 3.pi/2). When these binary angles are added using normal [[twos complement]] mathematics the rotation of the angles is correct, even when crossing the sign boundary (this of course does away with check like ((if >= 360.0) when handling normal degrees).
[[Image:Binary angles.png|250px|thumb|Binary Angles Diagram]]
Line 90 ⟶ 80:
== Application of Binary Scaling Techniques ==
Binary scaling
Binary scalling is still used in many [[digital Signal Processing|DSP]] applications and custom made microprocessors are usually based on binary scaling techniques.
Binary scaling is currently used in the
Although floating point has taken over to a large degree, where speed and extra accuracy are required, binary scaling is faster and more accurate.
|