MACHINE_OVERFLOWS for correct extended safe results AI-00021/16 1
90-07-06 BI WA
| !standard 13.07.03 (04) 90-07-06 AI-00021/16
!standard 04.05.07 (07)
!class binding interpretation 84-01-29
| !status WG9-approved 90-06-15
!status ARG-approved 89-10-25 (reviewed)
!status ARG-approved (10-0-1) 89-06-15 (pending editorial review)
!status work-item 88-11-04
!status returned to ARG by WG9 88-10-28
!status ARG-approved 88-05-10 (reviewed)
!status ARG-approved (13-0-0) 88-01-18 (pending editorial review)
!status work-item 87-12-28
!status returned to ARG by WG9 87-12-07
!status approved by Ada Board 87-07-30
!status panel/committee-approved 87-05-06 (reviewed)
!status panel/committee-approved (7-0-1) 87-02-18 (pending editorial review)
!status work-item 83-10-10
!references AI-00387, 83-00028, 83-00160, 83-00891, 83-00905
!topic MACHINE_OVERFLOWS for correct extended safe results
!summary 89-07-27
No exception need be raised if a predefined real operation returns a correct
result, whether or not MACHINE_OVERFLOWS is true for the type. CONSTRAINT_
ERROR (or NUMERIC_ERROR; see AI-00387) must be raised, however, if MACHINE_
OVERFLOWS is true for the type and the underlying machine operation
overflows, since a correct result is not obtained in this case.
If MACHINE_OVERFLOWS is true for a numeric type, CONSTRAINT_ERROR (or
NUMERIC_ERROR; see AI-00387) need not be raised if a correct result is
produced, even though the actual result lies outside the range of safe
numbers for the type.
The exception CONSTRAINT_ERROR is raised by the evaluation of a numeric type
conversion if the result of the conversion fails to satisfy a constraint
imposed by the type mark, whether or not the value of MACHINE_OVERFLOWS is
true for the target type.
!question 87-08-20
For MACHINE_OVERFLOWS, 13.7.3(4) says:
Yields the value TRUE if every predefined operation on values of
[a fixed or floating point type] either provides a correct
result, or raises the exception NUMERIC_ERROR in overflow
situations (see 4.5.7).
4.5.7(7) says:
The result model interval is undefined if the absolute value of
[the mathematical result] exceeds the largest safe number of the
result type. Whenever the result model interval is undefined, it
is highly desirable that the exception NUMERIC_ERROR be raised if
the implementation cannot produce an actual result that is in the
MACHINE_OVERFLOWS for correct extended safe results AI-00021/16 2
90-07-06 BI WA
range of safe numbers. This is, however, not required by the
language rules, in recognition of the fact that certain target
machines do not permit easy detection of overflow situations.
The value of the attribute MACHINE_OVERFLOWS indicates whether
the target machine raises the exception NUMERIC_ERROR in overflow
situations (see 13.7.3).
The range of a floating point base type can exceed the range of safe numbers
because the mantissa and range of the exponent for the base type can be
larger than the mantissa and exponent range for the safe numbers. If
MACHINE_OVERFLOWS is true, must an implementation raise NUMERIC_ERROR for
every result that lies outside the range of safe numbers, even if the result
lies within the range of the base type?
!recommendation 88-04-04
A predefined real operation produces a CORRECT RESULT if the result lies in
an interval defined by the rules for safe numbers but using a set of EXTENDED
safe numbers, defined as follows:
For a floating point type, the extended safe numbers have the
same definition as the safe numbers except the exponent range has
no upper bound.
For a fixed point type, the extended safe numbers are all integer
multiples of SAFE_SMALL for the type.
T'MACHINE_OVERFLOWS yields the value TRUE if every predefined operation on
values of T's base type either provides a correct result (in the above
sense), or raises the exception CONSTRAINT_ERROR (or NUMERIC_ERROR; see
AI-00387) when the result lies outside the range of safe numbers.
!discussion 89-07-27
4.5.7(7) suggests that an "overflow situation" occurs whenever a result lies
outside the range of safe numbers. 13.7.3(4) can then be read as suggesting
that MACHINE_OVERFLOWS should be FALSE if the result of a predefined numeric
operation lies outside the range of safe numbers and NUMERIC_ERROR is not
raised. Such a reading would make MACHINE_OVERFLOWS false for most
implementations, since few implementations will make the effort to raise an
exception when a result lies outside the range of safe numbers and overflow
is not signaled.
On the other hand, 13.7.3(4) can be read as saying that MACHINE_OVERFLOWS is
TRUE as long as a "correct" result is provided, even if the result lies
outside the range of safe numbers and no exception is raised. The problem
then is in understanding what it means for a result to be correct when it
lies in an undefined model interval.
The purpose of MACHINE_OVERFLOWS is to indicate whether an exception will be
raised when overflow occurs, i.e., when the result of a predefined real
operation cannot be represented. To achieve this intent, 13.7.3(4) should be
interpreted as saying that MACHINE_OVERFLOWS can be true as long as correct
MACHINE_OVERFLOWS for correct extended safe results AI-00021/16 3
90-07-06 BI WA
results are provided when the result lies outside the range of safe numbers.
An appropriate interpretation of "correct result" in this case is obtained by
extending the rules for safe numbers in the natural way. This extension is
specified by the recommended interpretation. Consequently, if the result of
a predefined real operation lies outside the range of safe numbers and
MACHINE_OVERFLOWS is true, CONSTRAINT_ERROR (or NUMERIC_ERROR; see AI-00387)
need only be raised if a correct result (in the recommended sense) is not
provided. For machines whose real arithmetic conforms to the Ada model, this
means CONSTRAINT_ERROR will only be raised when overflow occurs, i.e., when
no result is produced. Note that CONSTRAINT_ERROR (or NUMERIC_ERROR) can be
raised if a correct result lies within the range of the base type but outside
the range of safe numbers, even though in this case, no machine overflow has
occurred.
Underflow is said to occur when the exponent value needed to represent the
result correctly is more negative than the most negative value supported by
an implementation. The notion of extended safe numbers avoids consideration
of underflow by giving safe numbers and extended safe numbers the same lower
exponent bound. Hence, all extended safe numbers that are not safe numbers
lie outside the range of safe numbers.
Conversion to a real subtype is a predefined real operation. For a numeric
type conversion, 4.6(7) says:
the value of the operand is converted to the target type ...
4.6(12) then continues by saying:
the exception CONSTRAINT_ERROR is raised by the evaluation of a
type conversion if the result of the conversion fails to satisfy
a constraint imposed by the type mark.
Consequently, if the converted result lies outside the range of the type
mark, CONSTRAINT_ERROR is raised, whether or not the value of MACHINE_
OVERFLOWS is true for the type.