Binary scaling: Difference between revisions

Content deleted Content added
Overview: Fixed tautological reasoning
CE, improved refs
Line 1:
{{Refimprove|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 pseudo -[[floating point]] operations by using the native [[integer]] arithmetic of the processor.
 
==Overview==
A representation of a floating point value using binary scaling is more precise than a floating point representation occupying the same number of bits, but typically represents values of a more limited range, therefore more easily leading to [[arithmetic overflow]] during computation. Implementation of operations using integer arithmetic instructions is often (but not always) faster than the corresponding floating point instructions.
 
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 Binarybinary 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 approx 1.999 to -2.0 as [[floating point]].
 
To give an example, a common way to use [[Arbitraryarbitrary-precision arithmetic|integer arithmetic]] to simulate floating point, using 32 bit numbers, is to multiply the coefficients by 65536.
 
Using [[binary scientific notation]], this will place the binary point at B16. That is to say, the most significant 16 bits represent the integer part the remainder are represent the fractional part. This means, as a signed two's complement integer B16 number can hold a highest value of <math> \approx 32767.9999847 </math> and a lowest value of −32768.0. Put another way, the B number, is the number of integer bits used to represent the number which defines its value range. Remaining low bits (i.e. the non-integer bits) are used to store fractional quantities and supply more accuracy.
 
For instance, to represent 1.2 and 5.6 as B16 one multiplies them by 2<sup>16</sup>, giving 78643 and 367001.
Line 65 ⟶ 66:
[[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 floating point representation and <span style="color:red">red</span> is [[hexadecimal]] 32-bit representation.]]
 
Binary angles are mapped using B0, with 0 as 0 degrees, 0.5 as 90° (or <math>\frac{\pi}{2}</math>), &minus;1.0 or 0.9999999 as 180° (or π) and &minus;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>[http://blogs.msdn.com/shawnhar/archive/2010/01/04/angles-integers-and-modulo-arithmetic.aspx Angles, integers, and modulo arithmetic] Shawn Hargreaves, ''blogs.msdn.com''<name="Hargreaves_2010"/ref>).
 
The terms '''binary angular measurement''' ('''BAM''')<ref name="ship">{{cite web |url=http://www.tpub.com/content/fc/14100/css/14100_314.htm |title=Binary angular measurement |archive-url=https://web.archive.org/web/20091221160257/http://www.tpub.com/content/fc/14100/css/14100_314.htm |archive-date=2009-12-21}}</ref> and '''binary angular measurement system''' ('''BAMS''')<ref>{{cite web |urlname=http:"BAMS"//acronyms.thefreedictionary.com/Binary+Angular+Measurement+System |title=Binary Angular Measurement System |work=acronyms.thefreedictionary}}</ref> as well as '''brads''' ('''binary radians''' or '''binary degree''') refer to implementations of binary angles. They find use in robotics, navigation,<ref>[http://www.globalspec.com/reference/14722/160210/Chapter-7-5-3-Binary-Angular-Measure Real-Time Systems Design and Analysis] Chapter 7.5.3, Binary Angular Measure , Phillip A. LaPlante, page via ''www.globalspec.com''<name="LaPlante_2004"/ref> computer games,<ref>[http://fabiensanglard.net/doomIphone/doomClassicRenderer.php Doom 1993 code review] Fabien Sanglard, section name="WallsSanglard_1993", 13/1/2010, ''fabiensanglard.net''</ref> and digital sensors.<ref>[http://www.hobbyengineering.com/specs/PX-29123.pdf Hitachi HM55B Compass Module (#29123)] {{webarchive |urlname=https:"Parallax_2005"//web.archive.org/web/20110711172521/http://www.hobbyengineering.com/specs/PX-29123.pdf |date=July 11, 2011 }} pdf via ''www.parallax.com'' via ''www.hobbyengineering.com''</ref>
 
No matter what bit-pattern is stored in a binary angle, when it is multiplied by 180° (or π) using standard signed [[fixed-point arithmetic]], the result is always a valid angle in the range of −180° [[degree (angle)|degree]]s (−π [[radian]]s) to +180° degrees (+π radians).
Line 74 ⟶ 75:
 
==Application of binary scaling techniques==
Binary scaling techniques were used in the 1970s and 1980s for real-time computing that was mathematically intensive, such as [[flight simulation]] and in [[Nuclear Power Plant]] control algorithms since the late 1960's1960s. The code was often commented with the binary scalings of the intermediate results of equations.
 
Binary scaling is still used in many [[digital signal processing|DSP]] applications and custom made microprocessors are usually based on binary scaling techniques.
Line 90 ⟶ 91:
 
==References==
{{Reflist}}|refs=
<ref name="Hargreaves_2010">{{cite web |title=Angles, integers, and modulo arithmetic |author-first=Shawn |author-last=Hargreaves |publisher=blogs.msdn.com |url=http://blogs.msdn.com/shawnhar/archive/2010/01/04/angles-integers-and-modulo-arithmetic.aspx |access-date=2019-08-05 |dead-url=no |archive-url=https://web.archive.org/web/20190630223817/http://www.shawnhargreaves.com/blogindex.html |archive-date=2019-06-03}}</ref>
<ref name="ship">{{cite web |title=Binary angular measurement |url=http://www.tpub.com/content/fc/14100/css/14100_314.htm |archive-url=https://web.archive.org/web/20091221160257/http://www.tpub.com/content/fc/14100/css/14100_314.htm |archive-date=2009-12-21}}</ref>
<ref name="BAMS">{{cite web |title=Binary Angular Measurement System |work=acronyms.thefreedictionary |url=http://acronyms.thefreedictionary.com/Binary+Angular+Measurement+System}}</ref>
<ref name="LaPlante_2004">{{cite book |title=Real-Time Systems Design and Analysis |chapter=Chapter 7.5.3, Binary Angular Measure |author-first=Phillip A. |author-last=LaPlante |date=2004 |website=www.globalspec.com |chapter-url=http://www.globalspec.com/reference/14722/160210/Chapter-7-5-3-Binary-Angular-Measure}}</ref>
<ref name="Sanglard_1993">{{cite web |title=Doom 1993 code review - Section "Walls" |author-first=Fabien |author-last=Sanglard |date=2010-01-13 |website=fabiensanglard.net |url=http://fabiensanglard.net/doomIphone/doomClassicRenderer.php}}</ref>
<ref name="Parallax_2005">{{cite web |title=Hitachi HM55B Compass Module (#29123) |series=Parallax Digital Compass Sensor (#29123) |publisher=[[Parallax, Inc. (company)|Parallax, Inc.]] |date=May 2005 |website=www.hobbyengineering.com |via=www.parallax.com |url=http://www.hobbyengineering.com/specs/PX-29123.pdf |dead-url=yes |archive-url=https://web.archive.org/web/20110711172521/http://www.hobbyengineering.com/specs/PX-29123.pdf |archive-date=2011-07-11}}</ref>
}}
 
{{DEFAULTSORT:Binary Scaling}}