Ticket #22361 (closed defect: fixed)
Ruby 1.87 Hash equivalence fails on large Fixnums
| Reported by: | ben@… | Owned by: | kimuraw@… |
|---|---|---|---|
| Priority: | Normal | Milestone: | |
| Component: | ports | Version: | 1.8.1 |
| Keywords: | Cc: | visnupx@… | |
| Port: | ruby |
Description (last modified by macsforever2000@…) (diff)
On MacOS Leopard 10.5.8 with Ruby 1.87 (all patchlevels <= 174) and all compatible versions of MacPorts (<= 1.8.1)
Hash equivalence fails when a value is a Fixnum > 536870911.
>> {:a => 536870911}.hash == {:a => 536870911}.hash
=> true
>> {:a => 536870912}.hash == {:a => 536870912}.hash
=> false
Change History
comment:3 Changed 4 years ago by macsforever2000@…
- Keywords ruby hash removed
- Owner changed from macports-tickets@… to kimuraw@…
- Port set to ruby
comment:6 Changed 4 years ago by kimuraw@…
- Status changed from new to assigned
I reproduced this on snow leopard built-in ruby.
% arch -x86_64 /usr/bin/ruby -e 'p ({:a=>2**61}.hash == {:a=>2**61}.hash)'
false
% arch -i386 /usr/bin/ruby -e 'p ({:a=>2**29}.hash == {:a=>2**29}.hash)'
false
comment:7 Changed 4 years ago by kimuraw@…
Hash#hash returns different values from each invocations.
% ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10]
% irb --simple-prompt
>> h = {:a => 2**61}
=> {:a=>2305843009213693952}
>> h.hash
=> 3933384
>> h.hash
=> 4179968
I think this is a problem of ruby. I filed a ticket for redmine.ruby-lang.org (in japanese).
Note: See
TracTickets for help on using
tickets.


btw, 229 == 536870912. also, works on snow leopard:
>> {:a => 2**29-1}.hash => 2146753031 >> {:a => 2**29-1}.hash => 2146753031 >> {:a => 2**29}.hash => -2146753029 >> {:a => 2**29}.hash => -2146753029