From: merch-redmine@... Date: 2020-03-21T15:08:34+00:00 Subject: [ruby-core:97569] [Ruby master Bug#16700] Inconsistent behavior of equal? between Integer and Float Issue #16700 has been updated by jeremyevans0 (Jeremy Evans). Status changed from Open to Rejected On 64-bit in most common build environments, most commonly used `Float` values are embedded in the `VALUE`, instead of the `VALUE` being a pointer to an object slot. This is called `Flonum` internally. `equal?` checks if the `VALUE` for the object is the same, so if two `VALUE`s are the same, it returns true. @thyresias is using 32-bit and @sawa is using 64-bit, that is causing the difference in behavior. Note that behavior depends on the size of the number even in cases `Flonum` is supported, because only a certain range of values can be embedded in the `VALUE`. Example: ```ruby 0.equal?(0) # => true 0.0.equal?(0.0) # => true (2**64).equal?(2**64) # => false (1e303).equal?(1e303) # => false ``` In short, this isn't a bug, it is expected behavior. ---------------------------------------- Bug #16700: Inconsistent behavior of equal? between Integer and Float https://bugs.ruby-lang.org/issues/16700#change-84722 * Author: thyresias (Thierry Lambert) * Status: Rejected * Priority: Normal * ruby -v: ruby 2.6.5p114 (2019-10-01 revision 67812) [i386-mingw32] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- ~~~ruby 0.equal?(0) #=> true 0.0.equal?(0.0) #=> false x = 0.0 x.equal?(x) #=> true ~~~ Since Float objects are immutable, I would expect 0.0.equal?(0.0) to be true. -- https://bugs.ruby-lang.org/ Unsubscribe: