Lady Ada

Ada '83 Language Reference Manual

Copyright 1980, 1982, 1983 owned by the United States Government. Direct reproduction and usage requests to the Ada Information Clearinghouse.

4.10. Universal Expressions


A universal_expression is either an expression that delivers a result of type universal_integer or one that delivers a result of type universal_real.

The same operations are predefined for the type universal_integer as for any integer type. The same operations are predefined for the type universal_real as for any floating point type. In addition, these operations include the following multiplication and division operators:

Operator  Operation  Left operand       Right operand       Result type
                     type               type

   *      multiply   universal_real     universal_integer   universal_real
                     universal_integer  universal_real      universal_real

   /      divide     universal_real     universal_integer   universal_real

The accuracy of the evaluation of a universal expression of type universal_real is at least as good as that of the most accurate predefined floating point type supported by the implementation, apart from universal_real itself. Furthermore, if a universal expression is a static expression, then the evaluation must be exact.

For the evaluation of an operation of a nonstatic universal expression, an implementation is allowed to raise the exception NUMERIC_ERROR only if the result of the operation is a real value whose absolute value exceeds the largest safe number of the most accurate predefined floating point type (excluding universal_real), or an integer value greater than SYSTEM.MAX_INT or less than SYSTEM.MIN_INT.


It is a consequence of the above rules that the type of a universal expression is universal_integer if every primary contained in the expression is of this type (excluding actual parameters of attributes that are functions, and excluding right operands of exponentiation operators) and that otherwise the type is universal_real.


    1 + 1       -- 2
    abs(-10)*3  -- 30

    KILO : constant := 1000;
    MEGA : constant := KILO*KILO;   -- 1_000_000
    LONG : constant := FLOAT'DIGITS*2;

    HALF_PI    : constant := PI/2;           -- see 3.2.2
    DEG_TO_RAD : constant := HALF_PI/90;
    RAD_TO_DEG : constant := 1.0/DEG_TO_RAD; -- equivalent to

References: actual parameter, attribute, evaluation of an expression, floating point type, function, integer type, multiplying operator, and 4.5.5, predefined operation, primary, real type, safe number, system.max_int, system.min_int, type, universal_integer type, universal_real type. Rationale references: 3.6 Expressions


[Ada Information Clearinghouse]

Address any questions or comments to