Exponentiation with floating point operand 86-07-23 AI-00137/05 1
| !standard 04.05.06 (06) 86-07-23 AI-00137/05
| !class ramification 84-02-06
| !status approved by WG9/AJPO 86-07-22
| !status approved by Director, AJPO 86-07-22
| !status approved by WG9/Ada Board 86-07-22
| !status approved by Ada Board 86-07-22
!status approved by WG9/ADA Board 85-02-26
!status board-approved 84-06-29
!status committee-approved 84-02-06
!status received 83-11-07
!references 83-00192, 83-00312
!topic Exponentiation with floating point operand
!summary 84-03-16
Since the model interval for X*X*X*X is sometimes smaller than the interval
for (X*X)*(X*X), an implementation cannot compute X**4 as sqr(sqr(X)), where
sqr(Y) computes Y*Y. In general, exponentation to the Nth power must be
implemented using N-1 multiplications to ensure the required accuracy is
obtained.
!question 84-08-29
Can fewer than N-1 multiplications be used in computing X**N (for N > 0) even
though the Standard defines the model interval of the result in terms of
repeated multiplications?
!response 84-08-29
Any method can be used that provides results within the limits permitted by
4.5.7(9). In general, however, the error bounds for X*X*X*X can be smaller
than the bounds for (X**2)**2, so the result of (X**2)**2 can lie outside the
bounds for X*X*X*X for some values of X. Consequently, the only method
guaranteed to stay within the error bounds specified by 4.5.7(9) is to
perform N-1 multiplications when N > 0.
In practice, performing N-1 multiplications is not inefficient, because 90%
of the time the exponent is 2, 7% of the time, it is 3, and only in 3% of the
cases is the exponent larger than three [Wichmann, B. A., "Algol 60
Compilation and Assessment," Academic Press, 1973]. So the possibility of
reducing the number of multiplications does not arise very often.
It should also be noted that X**N for negative N should not be computed as
(1.0/X)**(abs N). For example, if X is 3.0 and N is 3, 81.0 is a model
number and 1.0/81.0 must lie within the smallest possible model interval.
But 1.0/3.0 is not a model number and so is not exactly representable as a
binary floating point value. The accumulated error in multiplying an
approximation to 1/3 by itself will yield a result outside the model interval
required by Ada if the exponent is made sufficiently large.