4 ms·
Elixir does not distinguish signs in zero, 0. Therefore; -0.0 + 2.0 = 2.0 and 0.0 + 2.0 = 2.0
by kaladin_1 6y ago
Elixir does not distinguish signs in zero, 0.
Therefore; -0.0 + 2.0 = 2.0 and 0.0 + 2.0 = 2.0
- kzemek 6y agoIsn't that true for all correct implementations of negative zero? It's still a neutral for addition
- worc3131 6y agoNot 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
- thaumasiotes 6y ago> Not quite neutral. Hmm? Your examples show -0.0 being additively neutral in every case. +0.0 is the one that behaves weirdly.
- shultays 6y agoheh, looks like abs(-0.0) is slightly less than abs(+0.0)!
- chrisseaton 6y agoI 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.
- mcintyre1994 6y agoI 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
- deleted 6y ago[deleted]