logoalt Hacker News

n923263 • yesterday at 7:33 PM • 1 reply • view on HN

> 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]

So that's a clear-cut compiler / FP library bug.


Replies

setopt • yesterday at 9:02 PM

Wait, sqrt(-0) is defined as -0 and not +0? Isn’t that surprising behavior?

➕ show 1 reply