You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
uniq treats -0.0 and 0.0 differently on BEAM vs walker #703
== treats -0.0 and 0.0 as equal on both backends, but uniq keeps both on BEAM and only one on the walker.
main do
let n = 0.0 * -1.0
IO.printLine("${[n, 0.0].uniq}")
end
expression
BEAM (OTP 29)
walker
"${n}"
-0.0
-0.0
n == 0.0, -0.0 == 0.0
true
true
n < 0.0
false
false
[0.0].contains?(n)
true
true
match n do 0.0 => …
matches
matches
[n, 0.0].sort
[-0.0, 0.0]
[-0.0, 0.0]
[n, 0.0].uniq
[-0.0, 0.0]
[-0.0]
BEAM's uniq probably uses term identity. Since OTP 27, 0.0 =:= -0.0 is false (and the Erlang pattern 0.0 no longer matches -0.0), while 0.0 == -0.0 is still true. So on BEAM, uniq disagrees with kex's own == and contains?.
Anything that keys or hashes floats is probably affected the same way (Set, Map keys, groupBy, tally, …). Worth checking all of them.
Design decision needed: kex float equality is IEEE-style (-0.0 == 0.0). Should collections follow it (normalise -0.0 to 0.0 for keys), or use term identity? Either way, both backends must agree and a spec should pin it.
Side observations:
IO.inspect({n: 1, 0.0: 2}) prints { 0.0: 2, n: 1 } on BEAM and { n: 1, 0.0: 2 } on the walker. Fine if map order is unspecified, but it makes map output unusable in cross-backend goldens.
That literal parses inside IO.inspect(...), but let m = {0.0: "pos"} is Unexpected token: :. Are float keys allowed in map literals?
Activity