Chapter 3
Ada Language Reference
3-30
ni.com
The selection of the intermediate type is performed by the code generator.
The selection involves a set of rules that rely upon word size extension.
Word size extension is selecting a fixed-point type with a larger number of
bits that can be used to represent model numbers. Also, the radix of the
intermediate type is chosen to be the radix of the result fixed-point type.
For all combinations of all the
RT_SBYTE
,
RT_UBYTE
,
RT_SSHORT
and
RT_USHORT
types, word size extension is possible. However, if any of
the
RT_SLONG
or
RT_ULONG
fixed-point types is one of the operator’s
operands, word size extension is not possible because there are no 64-bit
fixed-point types. Example 3-4 and Example 3-5 illustrate that accuracy is
maximized when a word-sized extended intermediate type is used in the
calculation.
Example 3-4
Word Size Extended Intermediate Type Subtraction Example
Given: n1 is an
RT_SBYTE04
, n2 is an
RT_SBYTE05
and n3 is an
RT_SBYTE07
.
n1 = 1.0625, n2 = 1.0, perform n3 = n1 – n2.
Select
intermediate type
of
RT_SSHORT07
and convert n1 and n2 to that
type resulting in n1a = 1.0625 and n2a = 1.0.
Perform t = n1a – n2a = 0.0625.
Assign n3 = t, performing a conversion from
RT_SSHORT07
to
RT_SBYTE07
resulting in n3 = 0.0625
Example 3-5
Result Type As Intermediate Type Subtraction Example
Given: n1 is an
RT_SBYTE04
, n2 is an
RT_SBYTE05
and n3 is an
RT_SBYTE07
.
n1 = 1.0625, n2 = 1.0, perform n3 = n1 – 0n2.
Convert n1 and n2 to the type of n3,
RT_SBYTE07
. Both values of
n1(1.0625) and n2(1.0) are not model numbers of the
RT_SBYTE07
type, thus both overflow when converted. The largest model number
is substituted so that n1a = 0.9921875 and n2a = 0.9921875.
Perform n3 = n1a – n2a = 0.0
Note
The type that is to be used as the intermediate type is represented as a formal
parameter to the addition and subtraction generic functions. There is no requirement that
the implementation of the function use the intermediate type in the calculation of the result.
However, the default implementations do use the intermediate type.