8000 `uniq` treats `-0.0` and `0.0` differently on BEAM vs walker · Issue #703 · kexhq/kex · GitHub
[go: up one dir, main page]

Skip to content

uniq treats -0.0 and 0.0 differently on BEAM vs walker #703

Open

Description

@akoskovacs

== 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?

Seen on kex 0.4.0-rc.3 (2fea09b0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0