4 ms·
It applies to Ruby as well, just in different cases: irb(main):020:0> 10.0.__id__ => 81064793292668930 irb(main):021:0> 10.__id__ => 21 irb
by viraptor 7y ago
It applies to Ruby as well, just in different cases:
irb(main):020:0> 10.0.__id__
=> 81064793292668930
irb(main):021:0> 10.__id__
=> 21
irb(main):022:0> 10==10.0
=> true
And for very large numbers:
irb(main):031:0> 1e200.__id__
=> 340
irb(main):032:0> 1e200.__id__
=> 360
So it's a different threshold and different cases, but as a general rule, "equality and identity are different" still holds.
- matheusmoreira 7y agoYes. Floating point numbers cannot be folded into object pointers and are always copied into newly allocated objects. Integers larger than ((sizeof(long) * CHAR_BIT) - 1) will actually become an arbitrary precision integer object.