Multiplication and division functions, Bit multiplication, Bit division – National Instruments AutoCode NI MATRIX User Manual

Page 93: Conversion functions, Multiplication and division functions -31, Bit multiplication -31 32-bit division -31, Conversion functions -31

Advertising
background image

Chapter 3

Ada Language Reference

© National Instruments Corporation

3-31

AutoCode Reference

Multiplication and Division Functions

The predefined multiplication and division operators for fixed-point type
based arguments are defined in Ada for any combination of fixed-point
arguments. The result of the computation is exact and of arbitrary accuracy.
Thus, a conversion to the result type of the expression must be performed.
During this conversion, accuracy might be lost. The implementation of the
generic functions that perform multiplication and division use the
predefined operators and perform the conversion to the result type.

32-Bit Multiplication

Multiplication of two 32-bit fixed-point numbers might not necessarily be
exact. The problem is that the predefined operator is sometimes unable to
use an extended 64-bit calculation to perform the operation. Thus, the result
might not be exact. As a rule of thumb, if the sum of the radices of the types
of the operands is less than 31, the result should be exact. If that sum is
larger than 31, loss of precision might occur.

Note

Computation of 32-bit values is compiler vendor dependent. Results compared

against the equivalent floating-point computation can vary significantly. The only solution
is to upgrade to a version of an Ada compiler that implements more robust fixed-point
numerics.

32-Bit Division

Division of two 32-bit fixed-point numbers might not be exact. The
problem is that the predefined operator is sometimes unable to use an
extended 64-bit calculation to perform the operation. Thus, the result might
not be exact. As a rule of thumb, if the radix of the type of the denominator
is less than 16, the result should be exact; otherwise, loss of precision might
occur.

Conversion Functions

Values from one data type (fixed-point or other type) might need to be
converted to another data type (fixed-point or other type). For any
conversion of a value that has type of lesser accuracy to a type with a
greater accuracy, loss of precision will not occur, but overflow is possible.
For example, a value represented in

RT_SSHORT01

converted to

RT_SSHORT03

will not lose accuracy, unless the value overflows.

However, when converting a value that has a type of greater accuracy to
a type that has a lesser accuracy, loss of precision will occur, but there is

Advertising