> The square root then looks at the sign bit and fails.
Every FP standard I know of that has negative zero requires that sqrt(-0) == 0. Eg (IEEE754-2008, probably the most popular and I don't have a PDF for 1985 or whatever):
> The operation squareRoot(x) computes √ x. It has a positive sign for all operands ≥ 0, except that squareRoot(−0) shall be −0.
> [Invalid operation if] g) squareRoot if the operand is less than zero [emphasis added]
Every FP standard I know of that has negative zero requires that sqrt(-0) == 0. Eg (IEEE754-2008, probably the most popular and I don't have a PDF for 1985 or whatever):
> The operation squareRoot(x) computes √ x. It has a positive sign for all operands ≥ 0, except that squareRoot(−0) shall be −0.
> [Invalid operation if] g) squareRoot if the operand is less than zero [emphasis added]
So that's a clear-cut compiler / FP library bug.
Replies (1)
Replies (2)
The real answer would be something like 0i, but that's not available.
Replies (2)
Replies (2)
Honestly it doesn't really matter but that's because you can't actually tell i and -i apart.
A result of -0.0 can mean two things (not counting it just being wrong):
a: the real (as in number) result is exactly zero, with a negative sign by coincidence (eg (1-1)/(0-1)).
b: the real result is strictly less than zero, but even tinier than the smallest denormal, so it was rounded up to zero.
Case (a) means you must have sqrt(-0) == 0, or you get problems like derf_'s.
In case of case (b), having a square root be negative (impossible!) is the best indication we can squeeze in that something might be weird.