Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Sadly, JS weirdness interferes with value semantics:

    > 0 === -0
    true
    > #{v: 0} === #{v: -0}
    ???


That's not a JS thing, 0 and -0 comparing as equal is specified in the IEEE 754 floating point standard.


It's the JS `===` operator. The semantics are defined by JS. JS can use IEEE754 semantics for numeric `===` comparisons if it wants, but it'll be at a cost if there are other ways to distinguish the two. In this case, if you make `#{v: 0} === #{v: -0}` then you're ok with `a === b && 1/a.v !== 1/b.v` being possible.

I could see an argument for `0 == -0 && 0 !== -0`. It would have made it possible to say "if a === b, then a and b can use the same bitwise representation internally without losing information". But that's not what we have.

I guess for maximum consistency, we could use the 3rd JS equality operator `Object.is` with records, so that

    0 == -0
    0 === -0
    ! Object.is(0, -0)
    #{v: 0} == #{v: -0}
    #{v: 0} === #{v: -0}
    ! Object.is(#{v: 0}, #{v: -0})
but then all Record-comparing code would have to do `Object.is()` in order to avoid a recursive comparison. (Well, maybe the engines would get clever and include a "contains -0" flag in Records, and skip the recursion if it's false for both sides?)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: