News for hackers. Stuff that matters.
Re:In Erlang/OTP 27, +0.0 will no longer be exactly equal to... by munk-a on Tuesday May 09, 2023 @07:57PM (#35881912)
Honestly - I rather dislike this change. I'd much rather have 0 & -0 be precisely equal to each other and have some obscure library function like `isNegativeZero` for the extremely rare cases they'd need to be differentiated. 0 and -0 being distinct values is honestly just an accident of convenience with how floats are stored - there are two bit patterns that result in a value of 0 but because they're different patterns we've assigned an unwarranted amount of distinction to them.
Re:In Erlang/OTP 27, +0.0 will no longer be exactly equal to... by sebzim4500 on Tuesday May 09, 2023 @08:12PM (#35882031)
I don't think it's just that.

1/0 is infinity but 1/(-0) is -infinity

Re:In Erlang/OTP 27, +0.0 will no longer be exactly equal to... by distortedsignal on Tuesday May 09, 2023 @10:00PM (#35882739)
Shouldn't both of those be NaN? Does Erlang have a NaN?
Re:In Erlang/OTP 27, +0.0 will no longer be exactly equal to... by lolcatuser on Tuesday May 09, 2023 @10:32PM (#35882972)
The reason division by zero can be a number is that floating-point numbers aren't individual numbers but ranges of numbers. So 0.0 isn't really the integer 0, it is the range of numbers between 0 and the smallest representable non-zero number. So division by 0.0 may be division by zero, or it may be division by a very small number, in which case it would approach infinity.

The same goes for the floating-point infinity: it doesn't represent the concept of infinity, it is a placeholder for every number between the largest representable number and infinity. That's how dividing a very large number by a very small number can result in infinity, a number which is really not a number.

This is the philosophy by which IEEE floating-point numbers were designed, and it's the explanation behind which negative zeroes and infinities make sense in floating point.

The way I find it easiest to reason about is by taking a graph of an asymptote and rounding it to the nearest units. You somehow need a way to say "there is an asymptote here!" even though you might not have all the units, and so you introduce infinities and negative zeroes to maintain as much precision as possible.

Re:In Erlang/OTP 27, +0.0 will no longer be exactly equal to... by adgjlsfhk1 on Wednesday May 10, 2023 @01:06AM (#35883843)
this isn't true. floats don't have semantics of internals. they have semantics of exact points that do math with rounding (otherwise the result of subtracting 2 floats would sometimes be more than 1 float)
Re:In Erlang/OTP 27, +0.0 will no longer be exactly equal to... by throwawaymaths on Wednesday May 10, 2023 @01:27AM (#35883965)
Moreover the spec defines rounding modes (rtnz, rtg, rtfz rtl) that are designed to exactly do interval arithmetic
Re:In Erlang/OTP 27, +0.0 will no longer be exactly equal to... by franknord23 on Tuesday May 09, 2023 @10:03PM (#35882758)
IIRC division by zero throws an exception.
Re:In Erlang/OTP 27, +0.0 will no longer be exactly equal to... by xxs on Wednesday May 10, 2023 @02:47AM (#35884414)
>both of those be NaN

Totally NOT. NaN is defined as 0.0/0.0. That's it.

Re:In Erlang/OTP 27, +0.0 will no longer be exactly equal to... by arcticbull on Wednesday May 10, 2023 @03:12AM (#35884596)
IEEE754 has a separate +Infinity and -Infinity to go along with SNaN and QNaN.

For instance:

- as parent said 1/0 is Inf.

- as parent said 1/(-0) and log(0) is -Inf.

- sqrt(-1) and 0/0 is NaN.

[1] https://www.gnu.org/software/libc/manual/html_node/Infinity-...

Re:In Erlang/OTP 27, +0.0 will no longer be exactly equal to... by fijiaarone on Tuesday May 09, 2023 @10:44PM (#35883048)
There is no negative zero
Re:In Erlang/OTP 27, +0.0 will no longer be exactly equal to... by princeb on Tuesday May 09, 2023 @11:48PM (#35883431)
1/0 is undefined and 1/-0 is also undefined.

what we have is lim(x->0+) 1/x = +inf and lim(x->0-) 1/x = -inf

Re:In Erlang/OTP 27, +0.0 will no longer be exactly equal to... by adgjlsfhk1 on Wednesday May 10, 2023 @01:04AM (#35883829)
this is wrong. ieee defines them
Re:In Erlang/OTP 27, +0.0 will no longer be exactly equal to... by kragen on Wednesday May 10, 2023 @01:05AM (#35883832)
not in ieee-754, only in reality
Re:In Erlang/OTP 27, +0.0 will no longer be exactly equal to... by bawolff on Wednesday May 10, 2023 @06:24AM (#35885610)
Numbers are abstract concepts in general. There is no fundamental reality only "real" numbers.
Re:In Erlang/OTP 27, +0.0 will no longer be exactly equal to... by kragen on Wednesday May 10, 2023 @12:19PM (#35889551)
the question of whether mathematical objects like 53 are more or less real than the historically contingent universe is indeed very interesting

however, it is irrelevant to the fact that a commenter was disagreeing because they had confused ieee-754 division with the division operation on so-called 'real' numbers

Re:In Erlang/OTP 27, +0.0 will no longer be exactly equal to... by rpaddock on Wednesday May 10, 2023 @08:32AM (#35886417)
Rigorously division by zero is "undefined" in mathematics.
Re:In Erlang/OTP 27, +0.0 will no longer be exactly equal to... by pvillano on Wednesday May 10, 2023 @10:20AM (#35887769)
You can totally define division by zero.

"There are mathematical structures in which [dividing by zero] is defined. [...] However, such structures do not satisfy every ordinary rule of arithmetic (the field axioms)." https://wikipedia.org/wiki/Division_by_zero

You're familiar with the ordinary rules of arithmetic (ORA!) applied to the real numbers. However, there are many number systems that follow different rules.

The rules of arithmetic for floats, wraparound ints, elliptic curves, and asymptotic analysis are all different from ORA! (and each other) but they are useful in their own ways.

Re:In Erlang/OTP 27, +0.0 will no longer be exactly equal to... by moonchild on Tuesday May 09, 2023 @10:16PM (#35882856)
> 0 and -0 being distinct values is honestly just an accident of convenience with how floats are stored

That's not at all true. The inclusion of negative zero in ieee 754 was a deliberate design choice, and if it were considered desirable that zero should be unsigned, then the bit pattern assigned to -0 would not have been so designed. See 'much ado about nothing's sign bit'[0], by one of the principal authors of ieee 754.

Whereas -0 and +0 are not operationally equivalent, operational equivalence is an important and useful relation; see the very pattern matching example linked from the OP[1].

0. https://people.freebsd.org/~das/kahan86branch.pdf

1. https://erlangforums.com/t/total-term-order/2477/41

Re:In Erlang/OTP 27, +0.0 will no longer be exactly equal to... by andreareina on Wednesday May 10, 2023 @02:33AM (#35884324)
That is a phenomenal title.
Re:In Erlang/OTP 27, +0.0 will no longer be exactly equal to... by kragen on Wednesday May 10, 2023 @12:41PM (#35889851)
unfortunately this scan of kahan's chapter is missing some pages
Re:In Erlang/OTP 27, +0.0 will no longer be exactly equal to... by kragen on Wednesday May 10, 2023 @01:07AM (#35883846)
the thread explains in the very first message that the existing semantics caused a subtle compiler bug in a way that makes it clear that you are not just wrong about the semantics of ieee-754 floating point but also about the pragmatics of how this affects real programs
Re:In Erlang/OTP 27, +0.0 will no longer be exactly equal to... by throwawaymaths on Wednesday May 10, 2023 @01:17AM (#35883902)
They're still ==.

=:= (=== in elixir) Somewhat means "and has the same binary form"

Fwiw, julia made the exact same choices.

Re:In Erlang/OTP 27, +0.0 will no longer be exactly equal to... by mFixman on Wednesday May 10, 2023 @06:15AM (#35885564)
> 0 and -0 being distinct values is honestly just an accident of convenience with how floats are stored

This is actually a valid distinction because these values can represent different values.

Floating point values are not numbers, but ranges of possible values: float -0 is a number in the range (-FLT_TRUE_MIN / 2, 0] and float +0 is a number in the range [0, FLT_TRUE_MIN).

IMO if I were to redesign IEEE 754 I would add a third float 0 value that always represents exactly 0 and redefine float -0 and float +0 as open limits, but that would probably make everything a lot more complicated.