Annotated Ada Reference ManualLegal Information
Contents   Index   References   Search   Previous   Next 

4.5.6 Highest Precedence Operators

Static Semantics

1
{highest precedence operator} {operator (highest precedence)} {abs operator} {operator (abs)} {absolute value} The highest precedence unary operator abs (absolute value) is predefined for every specific numeric type T, with the following specification: 
2
function "abs"(Right : Treturn T
3
{not operator} {operator (not)} {logical operator: See also not operator} The highest precedence unary operator not (logical negation) is predefined for every boolean type T, every modular type T, and for every one-dimensional array type T whose components are of a boolean type, with the following specification: 
4
function "not"(Right : Treturn T
5
The result of the operator not for a modular type is defined as the difference between the high bound of the base range of the type and the value of the operand. [For a binary modulus, this corresponds to a bit-wise complement of the binary representation of the value of the operand.]
6
The operator not that applies to a one-dimensional array of boolean components yields a one-dimensional boolean array with the same bounds; each component of the result is obtained by logical negation of the corresponding component of the operand (that is, the component that has the same index value). {Range_Check [partial]} {check, language-defined (Range_Check)} {Constraint_Error (raised by failure of run-time check)} A check is made that each component of the result belongs to the component subtype; the exception Constraint_Error is raised if this check fails.
6.a
Discussion: The check against the component subtype is per AI83-00535. 
7
{exponentiation operator} {operator (exponentiation)} {** operator} {operator (**)} The highest precedence exponentiation operator ** is predefined for every specific integer type T with the following specification: 
8
function "**"(Left : T; Right : Natural) return T
9
Exponentiation is also predefined for every specific floating point type as well as root_real, with the following specification (where T is root_real or the floating point type): 
10
function "**"(Left : T; Right : Integer'Base) return T
11
{exponent} The right operand of an exponentiation is the exponent. The expression X**N with the value of the exponent N positive is equivalent to the expression X*X*...X (with N–1 multiplications) except that the multiplications are associated in an arbitrary order. With N equal to zero, the result is one. With the value of N negative [(only defined for a floating point operand)], the result is the reciprocal of the result using the absolute value of N as the exponent. 
11.a
Ramification: The language does not specify the order of association of the multiplications inherent in an exponentiation. For a floating point type, the accuracy of the result might depend on the particular association order chosen. 

Implementation Permissions

12
{Constraint_Error (raised by failure of run-time check)} The implementation of exponentiation for the case of a negative exponent is allowed to raise Constraint_Error if the intermediate result of the repeated multiplications is outside the safe range of the type, even though the final result (after taking the reciprocal) would not be. (The best machine approximation to the final result in this case would generally be 0.0.) 
NOTES
13
19  {Range_Check [partial]} {check, language-defined (Range_Check)} As implied by the specification given above for exponentiation of an integer type, a check is made that the exponent is not negative. {Constraint_Error (raised by failure of run-time check)} Constraint_Error is raised if this check fails. 

Inconsistencies With Ada 83

13.a.1/1
{8652/0100} {AI95-00018-01} {inconsistencies with Ada 83} The definition of "**" allows arbitrary association of the multiplications which make up the result. Ada 83 required left-to-right associations (confirmed by AI83-00137). Thus it is possible that "**" would provide a slightly different (and more potentially accurate) answer in Ada 95 than in the same Ada 83 program. 

Wording Changes from Ada 83

13.a
We now show the specification for "**" for integer types with a parameter subtype of Natural rather than Integer for the exponent. This reflects the fact that Constraint_Error is raised if a negative value is provided for the exponent. 

Contents   Index   References   Search   Previous   Next 
Ada-Europe Sponsored by Ada-Europe