News for hackers. Stuff that matters.
Re:One does not simply calculate the absolute value by titzer on Sunday August 22, 2021 @03:10PM (#28268510)
Haha, -0. After spending literal years of my life dealing with that little encoding nuisance, in everything from the V8 TurboFan JIT, to WebAssembly, to adding floating point to Virgil, I just gotta say, that little turd is so not worth it. I've read a lot of different justifications for it (it's a limit, it represents approaching 0 from the negatives, some algorithms need it, etc), I have to admit, I just don't buy it. It's an encoding artifact that's produced so much accidental complexity that, in my book, has been far more trouble than it's been worth.

Change my mind.

Re:One does not simply calculate the absolute value by nimish on Sunday August 22, 2021 @04:29PM (#28269297)
How else would you represent a branch cut or even a jump at 0?

https://people.freebsd.org/~das/kahan86branch.pdf from the father of ieee-754 is illuminating.

Re:One does not simply calculate the absolute value by FabHK on Sunday August 22, 2021 @05:05PM (#28269595)
Haha, was just going to link that. Here's an ELI5, though not that illuminating:

https://hackernoon.com/negative-zero-bbd5fd790af3

But, bottom line, Kahan (not only the father of IEEE 754, but also, with Golub, father of the SVD!) has thought about it a lot, and though he called the signed zero "a pain in the ass", he also said "There really wasn’t a way around that and you were stuck with it."

http://history.siam.org/pdfs2/Kahan_final.pdf

Re:One does not simply calculate the absolute value by edflsafoiewq on Monday August 23, 2021 @12:31AM (#28272350)
I don't really understand. Why is it important that there be two zeros so that

1/ (+0) = +∞ but 1/ (–0) = –∞

but not that there be two, say, 3s so that

1/ (3⁺ – 3) = +∞ but 1/ (3⁻ – 3) = –∞

Re:One does not simply calculate the absolute value by pests on Monday August 23, 2021 @03:13AM (#28273057)
But we already have two threes: +3 and -3.

It's not that it's important there be two, just every number already had 2 except for 0.

Re:One does not simply calculate the absolute value by croes on Sunday August 22, 2021 @04:38PM (#28269371)
So for programming convenience we ignore correct math?
Re:One does not simply calculate the absolute value by FabHK on Sunday August 22, 2021 @05:08PM (#28269627)
We cannot represent "correct math" on a computer, because the set of reals is uncountable, but in 64 bits we can only represent finitely many numbers, not infinitely many, let alone uncountably many.

And given that we have to implement some sort of approximation to the usual math on a closed subset of the reals (rationals, even), why not extend it with some "numbers" (negative zero, plus/minus infinity, NaNs) that, yes, enable programming convenience?

Re:One does not simply calculate the absolute value by croes on Sunday August 22, 2021 @05:52PM (#28270017)
There is a difference between 2.4987665678 as 2.5 and undefined as ±infinity especially because 1.0/+0.0 is +infinity and 1/0 is just an exception in Java. Shouldn't it be the same result?