(j3.2006) SQRT of square to ABS
Van Snyder
Van.Snyder
Tue Jan 8 21:16:28 EST 2008
On Tue, 2008-01-08 at 18:02 -0800, Robert Corbett wrote:
> No. The question was motivated by a user request that SQRT(X**2) be
> optimized to ABS(X). Sun's compiler does not do that optimization,
> but
> apparently some other compilers do. The question about compatibility
> with the IEEE modules originated with me, not the user. I suspect the
> user has no idea that the IEEE modules exist.
> I do not know why the user wrote SQRT(X**2) instead of ABS(X), but I
> doubt it was because he wanted to get overflow, underflow and
> imprecise
> exceptions. I conjecture that the user who asked for the optimization
> is not the programmer who wrote the original code.
Is X complex?
If so, then sqrt(X**2) isn't abs(X), but rather
cmplx(abs(real(X)),aimag(X),kind(X))
More information about the J3
mailing list