(j3.2006) SQRT of square to ABS
Tue Jan 8 20:37:47 EST 2008
On Tue, 08 Jan 2008 14:34:55 +0900, Robert Corbett <Robert.Corbett at sun.com> wrote:
> If the modules IEEE_EXCEPTIONS and IEEE_FEATURES are used in a
> program unit, may a standard-conforming implementation transform
> the expression SQRT(X**2) into ABS(X)?
Probably. **2 is not an IEEE operation, and neither is ABS(X).
OTOH, it probably ought not to transform SQRT(X*X) into ABS(X).
> The first expression might signal
Never mind signalling, if X*X overflows it returns a different result,
viz +INF. You only need to use the relevant constants out of IEEE_FEATURES
to get that guaranteed. Maybe.
(Maybe not on x87, but that's a horse of a different colour;
754 isn't a sharp enough instrument for that analysis.)
Didn't the user write SQRT(X**2) instead of ABS(X) deliberately because he
wanted to get the infinity/overflow stuff? If he also wrote
it is more than reasonable to think that he wanted what he asked for!
We shouldn't make him have to assign all intermediate results to VOLATILE
variables just to get the IEEE semantics he already asked for...
................Malcolm Cohen (malcolm at nag-j.co.jp)
More information about the J3