Closed matthias-springer closed 9 years ago
Is it reasonable to state something is identical but not equal?
Not sure about semantics here, but just found out that x != x
in Python if x = float('nan')
(what???).
Thats perfectly ok. Holds in Smalltalk and also Ruby:
irb(main):002:0> x = 0 / 0.0
=> NaN
irb(main):003:0> x == x
=> false
irb(main):004:0>
==
is object identity (defined as "pointer address" in Squeak), so why would x == x
ever be false regardless of the value of x?
Explanation:
x == x
in Smalltalk is compiled to a pointer check (or value check for integers only), Since on image level there is only one NaN
, Float nan == Float nan
compares the same objects.x = x
is a message send for #=
, which is a primitive for float. This one explicitly makes sure that two NaN
s never compare equal (by delegating to C semantics)On 16.06.2015, at 20:41, Matthias Springer notifications@github.com wrote:
== is object identity, so why would x == x ever be false regardless of the value of x?
�
Boxed objects would do that. But there are ways around that.
In Squeak:
Float nan = Float nan
is false andFloat nan == Float nan
is true. In RSqueak: both are false