Chapter 2
C Language Reference
2-42
ni.com
0^1111111 (n2' = (127,r7)
, decimal value = .9921875)
___________
0^0000000 (n3 = (0,r7)
, decimal value = 0.0)
In Example 2-3, method 1 is more accurate than method 2, but it is also less
efficient because it involves a 16-bit subtraction. This is important for
those using 8-bit processors but will probably not be as significant for
those using 16-bit or 32-bit processors.
Method 2 was inaccurate because of the left-shifting that had to be
performed for alignment to the result radix. If the result radix position had
been the same as the radix position of one of the operands, the resultant
value would have been as accurate as with method 1 even though it used
only 8-bit subtraction.
Selecting Wordsize Extension in the Preprocessor
Macro
You can choose whether or not to use wordsize extension in addition
and subtraction by a preprocessor macro in the
sa_fxp.h
file. The
preprocessor statement:
#define WORDSIZE_EXTEND 1
causes the code to be compiled with wordsize extension. This is the
default. The preprocessor statement:
#define WORDSIZE_EXTEND 0
causes the code to be compiled without wordsize extension.
32-Bit Multiplication and Division Macros
32-bit multiplication and division macros are different from their 8-bit and
16-bit counterparts. This is because the maximum wordsize available is
only 32 bits; therefore, operands cannot be promoted to a higher word
length before or after performing multiplication or division.
32-Bit Multiplication
Before performing the actual multiplication, both operands are split into
upper and lower words. Multiplication is performed in parts—that is,
higher and lower words of each operand are multiplied by each other and
added in a certain fashion to produce a 64-bit intermediate result. This
intermediate result is aligned according to the result’s radix position. After
alignment, if the value cannot be held in 32 bits, the clipped value—that is,