Earlier quoted context omitted.
It's a natural consequence of the IEEE 754 standard for floating point numbers.
To be clear, it was added to the standard because there was user demand for it. Zero is already special cased in IEEE 754 (along with the rest of the denormals, because of the implied leading mantissa bit), the implementation would be no harder if you just only had a single zero. However, back when the standard was being created, when a single zero value was proposed there was pushback from people in the user communi…
In Erlang/OTP 27, +0.0 will no longer be exactly equal to -0.0
171–180 of 236 posts
Re: In Erlang/OTP 27, +0.0 will no longer be exactly equal to -0.0
#172Re: In Erlang/OTP 27, +0.0 will no longer be exactly equal to -0.0
#173Earlier quoted context omitted.
In general, this is good advice. However, there are cases where comparing floating point numbers for equality works just fine. For example, if you have a variable 'v' and want to update it to a new value 'f', you can do 'if (v == f)' to check if the variable would change. Or if you have a sentinel value -1.0, it is perfectly ok to do 'if (a == -1.0)' In general, if you look for a number 'f' in variable 'v', you can s…
cesaref's comment is not good advice, it's not advice at all, it's a snarky take on how floating point is trickier than it looks almost invariably floating-point calculations end up in some kind of comparison; if they didn't we'd probably do the calculations in a galois field or something instead even equality comparison of floats is useful; there are an abundance of seminumerical algorithms which use it correctly on…
Re: In Erlang/OTP 27, +0.0 will no longer be exactly equal to -0.0
#174In Geometry for Programmers, I reference a case when an automated test system caught a "zero-not-zero" bug, and I couldn't reproduce it with a unit test until I finally realized that the test system was comparing XMLs not numbers. In print, "-0." and "0." are, of course, different, although in runtime they pretend to be the same.
Re: In Erlang/OTP 27, +0.0 will no longer be exactly equal to -0.0
#175Earlier quoted context omitted.
I don't think it's just that. 1/0 is infinity but 1/(-0) is -infinity
Shouldn't both of those be NaN? Does Erlang have a NaN?
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 -0.0
#176Re: In Erlang/OTP 27, +0.0 will no longer be exactly equal to -0.0
#177Earlier quoted context omitted.
cesaref's comment is not good advice, it's not advice at all, it's a snarky take on how floating point is trickier than it looks almost invariably floating-point calculations end up in some kind of comparison; if they didn't we'd probably do the calculations in a galois field or something instead even equality comparison of floats is useful; there are an abundance of seminumerical algorithms which use it correctly on…
well you shouldn't expect much if you are comparing floats to doubles
Re: In Erlang/OTP 27, +0.0 will no longer be exactly equal to -0.0
#178Earlier quoted context omitted.
Math notation is to mathematics as poetry is to English. The only acceptable grammar for math is s-expressions.
Well, idiomatic C++23 is an acceptable math notation too.
Re: In Erlang/OTP 27, +0.0 will no longer be exactly equal to -0.0
#179Re: In Erlang/OTP 27, +0.0 will no longer be exactly equal to -0.0
#180There is a huge misconception here which really should be clarified in the title. Erlang has an "exactly equal" or strict equality operator, called =:=, which is different from just usual equality, which is ==. The usual equality operator will keep having +0.0 = -0.0, and floating point arithmetic will keep behaving as you would expect... It's that we no longer have +0.0 =:= -0.0, which is a very different thing (and…
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 patte…
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.