Question on valid transformations for cbrt
Geoff Keating
geoffk@geoffk.org
Fri Apr 2 00:22:00 GMT 2004
Roger Sayle <roger@eyesopen.com> writes:
> i.e. cbrt(-29.7) = -3.1 but pow(-29.7,1.0/3.0) => EDOM.
one reason for this is because 1.0 / 3.0, as a double, gets rounded to
6004799503160661 / 2 ^ 54, and so the result of the pow() is imaginary
and not representable as a 'double'. (If we'd used base-3 arithmetic,
pow() could always provide a result with negative inputs.)
(This also means the same transformations with sqrt() will usually be
safe.)
--
- Geoffrey Keating <geoffk@geoffk.org>
More information about the Gcc
mailing list