Exact evaluation of static universal real expressions AI-00209/06 1
88-05-23 ra WJ
| !standard 04.10 (04) 88-05-23 AI-00209/06
!class ramification 84-03-13
| !status approved by WG9/AJPO 88-02-05
| !status approved by Director, AJPO 88-02-05
| !status approved by WG9/Ada Board 87-12-07
!status approved by Ada Board 87-07-30
!status panel/committee-approved 87-05-06 (reviewed)
!status panel/committee-approved (8-0-0) 87-02-18 (pending editorial review)
!status work-item 87-01-15
!status received 84-03-13
!references AI-00325, 83-00284
!topic Exact evaluation of static universal real expressions
!summary 87-06-11
An implementation can refuse to evaluate a static universal real expression
only if there are insufficient resources to evaluate the expression exactly,
e.g., if there is insufficient memory available. Inexact results must not be
delivered.
!question 84-03-13
Consider the following static expressions:
(a) (1.0/3.0) * 3.0 = 1.0
(b) 1.0E-1000 + 1.0
(c) (1.0E1000 + 1.0) / 1.0E1000 = 1.0
A typical floating point evaluation of expression (a) would yield the value
FALSE, but 4.10(4) requires that the evaluation of static universal real
expressions be exact. Hence, in order to evaluate universal real expressions
exactly, a compiler must include a rational arithmetic package or some even
more complicated expression representation and manipulation package. Such a
rational arithmetic package would consume more than 3000 bits to represent
the exact value of expression (b). Any limitation on the precision of the
arithmetic would result in expression (c) evaluating to TRUE, which would be
incorrect.
Can an implementer employ a limited precision evaluation strategy for static
universal real expressions, rejecting programs that cannot be evaluated
exactly using this strategy?
!response 87-03-24
The requirement to evaluate static universal real expressions exactly was
given careful consideration during Ada's design. It was decided that the
advantage of requiring such evaluations (in terms of increased program
clarity) is worth the implementation burden. In practice, this means that
implementers must evaluate such expressions using a rational arithmetic
package (see "Universal Arithmetic Packages" by G. Fisher in ACM Ada Letters,
Vol. 3, No. 6, pp. 30-47, May-June, 1984.) Consequently, it would not be
consistent with the design intent and AI-00325 for an implementation to
return FALSE as the value of 1.0/3.0 * 3.0 = 1.0. In general, the only
acceptable reason for refusing to evaluate a static universal real expression
exactly is insufficient memory to hold the required values.