Chapter 3 Ada Language Reference
© National Instruments Corporation 3-29 AutoCode Reference
function “>=” is new SA_FIXED_GENERICS.GREATEREQUAL(SA_FIXED.RT_SSHORT14,
SA_FIXED.RT_SSHORT08);
--pragma inline (">=");
function ">=" (LEFT, RIGHT : SA_FIXED.RT_SSHORT13) return BOOLEAN
renames SA_FIXED.">=";
--pragma inline (">=");
function RT_US11 is new
SA_FIXED_GENERICS.FLOATFIXEDCAST(SA_FIXED.RT_USHORT11);
--pragma inline (RT_US11);
-- Conversion Function Instantiations --
function RT_US13r is new
SA_FIXED_GENERICS.FLOATFIXEDCAST_ROUND(SA_FIXED.RT_USHORT13);
--pragma inline (RT_US13r);
function RT_SS12_It is new
SA_FIXED_GENERICS.INTCAST_TRUNC(SA_FIXED.RT_SSHORT12);
--pragma inline (RT_SS12_It);
end RT_FIXED_OPERATORS;
Addition and Subtraction Functions
The FIXED_ADD and FIXED_SUB generic functions implement addition
and subtraction of fixed-point types. Unlike the predefined Ada fixed-point
operators, these generics support mixed-type operators, that is, the types of
the operands do not have to be the same. To achieve results as accurate as
possible without introducing overflow requires the use of an intermediate
type in the calculation. The intermediate type is chosen such that the
following properties are maintained: the values of each operand do not
overflow when converted to the intermediate type; the result of the
operation does not overflow when represented in the intermediate type.
Ifsu ch an intermediate type can be found for the two operands of the
operation, the result is guaranteed to be exact. Therefore, addition and
subtraction uses the intermediate type for the calculation of the result such
that the operations are defined as:
c = a + b ==> c = RESULT_TYPE( IT(a) + IT(b) )
c = a - b ==> c = RESULT_TYPE( IT(a) - IT(b) )
The two operands are converted to the intermediate type (IT), and then
the operation is performed. Then, the result is converted to the result type
(RESULT_TYPE). Loss of significance can occur when converting to the
result type.