I just got a new macbook air and discovered this problem with the system ruby. Here’s a simple implementation of factorial.
When you run it in irb it does what you’d expect:
>> fact(1) => 1 >> fact(0) => 1 >> fact(2) => 2 >> fact(5) => 120 >> fact(10) => 3628800 >> fact(20) => 2432902008176640000
Until the result won’t fit in a Fixnum and needs to fit in a big num. Then it overflows.
My macbook shipped with this version of ruby.
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]
This bug isn’t in ruby, its in the version that Apple is shipping on the newest macbooks. Using rbenv I installed the same patch version and re-ran the factorials.