2.0**3 can be a universal_real expression AI-00129/04 1
88-11-04 ra WA
| !standard 04.10 (02) 88-11-04 AI-00129/04
!class ramification 83-11-07
| !status approved by WG9 88-10-28
!status ARG-approved 88-05-10 (reviewed)
!status ARG-approved (15-0-1) 87-09-15 (pending editorial review)
!status panel-approved (6-0-0) 87-09-15
!status work-item 87-07-08
!status received 83-11-07
!references 83-00181
!topic 2.0**3 can be a universal_real expression
!summary 87-07-10
An expression of the form
universal_real_operand ** universal_integer_operand
is allowed as an expression of type universal_real.
!question 87-07-08
4.10(2) says:
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.
4.10(6), which is a note, says:
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.
This note suggests that 2.0**3 is a legal expression of type universal_real,
but this is not clear from the Standard itself. Since ** is predefined for a
left operand of any floating point type and a right operand of one particular
integer type (the predefined type INTEGER), it is not clear that ** qualifies
as either an operation "predefined ... for any integer type" or an operation
"predefined ... for any floating point type." Is 2.0**3 a legal expression
of type universal_real?
!response 88-05-03
4.5.6(4) says:
The highest precedence exponentiating operator ** is predefined
for each integer type and for each floating point type. In
either case the right operand, called the exponent, is of the
predefined type INTEGER.
2.0**3 can be a universal_real expression AI-00129/04 2
88-11-04 ra WA
Thus, ** is an operation that is predefined for any floating point type, even
though only the left operand is of a floating point type, while the right
operand is of the predefined type INTEGER. Hence, by 4.10(2), ** is also
predefined for type universal_real as:
Operator Left operand type Right operand type Result type
** universal_real predefined INTEGER universal_real
4.6(15) defines implicit type conversions:
Apart from the explicit type conversions, the only allowed form
of type conversion is the implicit conversion of a value of the
type universal_integer or universal_real into another numeric
type. An implicit conversion of an operand of type universal_
integer to another integer type, or of an operand of type
universal_real to another real type, can only be applied if the
operand is either a numeric literal, a named number, or an
attribute; such an operand is called a convertible universal
operand in this section. An implicit conversion of a convertible
universal operand is applied if and only if the innermost
complete context (see 8.7) determines a unique (numeric) target
type for the implicit conversion, and there is no legal
interpretation of this context without this conversion.
The expression 2.0**3 is a legal expression of type universal_real because
2.0 is a numeric literal of type universal_real [2.4], 3 is a numeric literal
of type universal_integer [2.4], and by 4.6(15), 3 is implicitly converted to
type INTEGER, since there is no legal interpretation of the expression unless
this implicit conversion is performed. Of course, if the context requires a
non-universal_real expression, e.g.,
X : FLOAT := 2.0 ** 3;
then 2.0 must also be implicitly converted, in this case, to FLOAT.