Re:How does your programming language handle “minus zero” (-...
by chrisseaton on Friday March 05, 2021 @07:25AM
(#26356049)
I don't understand what you think a result could look like here that does distinguish the sign? What are you expecting? -2.0? That doesn't make any sense. 2.0 is the correct answer under all circumstances as far as I can see.
Re:How does your programming language handle “minus zero” (-...
by kzemek on Friday March 05, 2021 @07:18AM
(#26355999)
Isn't that true for all correct implementations of negative zero? It's still a neutral for addition
Re:How does your programming language handle “minus zero” (-...
by worc3131 on Friday March 05, 2021 @07:32AM
(#26356110)
Not quite neutral. You return -0.0 only when needed.
>>> 0.0+0.0
0.0
>>> 0.0+(-0.0)
0.0
>>> (-0.0)+0.0
0.0
>>> (-0.0)+(-0.0)
-0.0
Re:How does your programming language handle “minus zero” (-...
by thaumasiotes on Friday March 05, 2021 @07:42AM
(#26356199)
> Not quite neutral.
Hmm? Your examples show -0.0 being additively neutral in every case. +0.0 is the one that behaves weirdly.
Re:How does your programming language handle “minus zero” (-...
by shultays on Friday March 05, 2021 @09:39AM
(#26357305)
heh, looks like abs(-0.0) is slightly less than abs(+0.0)!
Re:How does your programming language handle “minus zero” (-...
by mcintyre1994 on Friday March 05, 2021 @07:32AM
(#26356106)
I think you're right that they're indistinguishable, in that -0.0 == 0.0
The division by 0 in that article gives the same ArithmeticError in each case, notice the 0.0 in both errors:
iex(8)> 1.0 / -0.0
** (ArithmeticError) bad argument in arithmetic expression: 1.0 / 0.0
:erlang./(1.0, 0.0)
iex(8)> 1.0/0.0
** (ArithmeticError) bad argument in arithmetic expression: 1.0 / 0.0
:erlang./(1.0, 0.0)
It's also ignored when rounding: iex(10)> Float.round(-0.01, 1)
0.0
iex(11)> Float.round(0.01, 1)
0.0
Therefore; -0.0 + 2.0 = 2.0 and 0.0 + 2.0 = 2.0