Language-defined conversion, Truncation conversion, Explicit rounding conversion – National Instruments AutoCode NI MATRIX User Manual

Page 94

Advertising
background image

Chapter 3

Ada Language Reference

AutoCode Reference

3-32

ni.com

no chance of overflow. To support these issues there are three types of
conversion functions:

Language-defined conversion

Truncation conversion

Explicit rounding conversion

These conversions are described in the following sections.

Language-Defined Conversion

The Ada language provides four data type conversions. The rules in Ada
that govern the conversion are explicit except for one detail. When
converting between different numeric types, values that cannot be exactly
represented in the type are rounded to the nearest model number. A value
that is exactly halfway between two model numbers (that is, at the
midpoint), can be rounded to the larger or smaller model number. The
choice is left to the implementor of the Ada compiler. Instantiated
conversion functions that use the language-defined conversion do not have
a t or r designator at the end of the function name. Refer to Table 3-10.

Truncation Conversion

This type of conversion implements truncation for values that are at the
midpoint between two model numbers. For example, if a value of 1.5 in the

RT_SBYTE01

type is converted to

RT_SBYTE

, the resulting value is 1.0.

Instantiated functions that implement truncation have a t designator at the
end of the function name. Also, generic functions that use truncation have
the

_TRUNC

suffix as part of those names.

Explicit Rounding Conversion

This type of conversion implements round away from zero rounding mode
for values that are at the midpoint between two model numbers. For
example, if a value of 1.5 in the

RT_SBYTE01

type is converted to

RT_SBYTE

, the resulting value is 2.0. Instantiated functions that implement

this rounding mode have an r designator at the end of the function name.
Also, generic functions that use rounding have the

_ROUND

suffix to those

names.

The choice of which type of conversion function to use depends on the
situation. For example, the Signal Conversion block can use either
truncation or rounding. However, when dealing with fixed-point numerics,
there are many other implicit conversions between data types, such as the
conversion of arguments to an intermediate type for addition or subtraction.

Advertising