4 ms·
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 `isNegativeZe
by munk-a 3y ago
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.
- sebzim4500 3y agoI don't think it's just that. 1/0 is infinity but 1/(-0) is -infinity
- distortedsignal 3y agoShouldn't both of those be NaN? Does Erlang have a NaN?
- franknord23 3y agoIIRC division by zero throws an exception.
- lolcatuser 3y agoThe 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.
- adgjlsfhk1 3y agothis 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)
- throwawaymaths 3y agoMoreover the spec defines rounding modes (rtnz, rtg, rtfz rtl) that are designed to exactly do interval arithmetic
- xxs 3y ago>both of those be NaN Totally NOT. NaN is defined as 0.0/0.0. That's it.
- arcticbull 3y agoIEEE754 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-and-NaN.html https://www.gnu.org/software/libc/manual/html_node/Infinity-...
- fijiaarone 3y agoThere is no negative zero
- princeb 3y ago1/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
- adgjlsfhk1 3y agothis is wrong. ieee defines them
- kragen 3y agonot in ieee-754, only in reality
- bawolff 3y agoNumbers are abstract concepts in general. There is no fundamental reality only "real" numbers.
- kragen 3y agothe 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
- rpaddock 3y agoRigorously division by zero is "undefined" in mathematics.
- pvillano 3y agoYou 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 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.
- moonchild 3y ago> 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 assigned. 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 https://people.freebsd.org/~das/kahan86branch.pdf 1. https://erlangforums.com/t/total-term-order/2477/41 https://erlangforums.com/t/total-term-order/2477/41
- andreareina 3y agoThat is a phenomenal title.
- kragen 3y agounfortunately this scan of kahan's chapter is missing some pages
- kragen 3y agothe 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
- throwawaymaths 3y agoThey're still ==. =:= (=== in elixir) Somewhat means "and has the same binary form" Fwiw, julia made the exact same choices.
- mFixman 3y ago> 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.