Does there exist an IEEE double x>0
such that sqrt(x*x) ≠ x
, under the condition that the computation x*x
does not overflow or underflow to Inf
, 0
, or a denormal number?
This is given that sqrt
returns the nearest representable result, and so does x*x
(both as mandated by the IEEE standard, "square root operation be calculated as if in infinite precision, and then rounded to one of the two nearest floating-point numbers of the specified precision that surround the infinitely precise result").
Under the assumption that if such doubles would exist, then there are probably examples close to 1, I wrote a program to find these counterexamples, and it failed to find any between 1.0
and 1.0000004780981346
.
The previous similar question perfect squares and floating point numbers answers the question in the negative for situations where the computation of x*x
does not involve rounding. That answer is not sufficient for this question because it may be possible for x*x
to involve rounding in one direction, then sqrt(x*x)
to involve rounding in the same direction, thus producing an answer that is not exactly x
.