From: Eric Hodel Date: 2005-07-06T03:19:48+09:00 Subject: Re: Ruby2c and large numbers On 04 Jul 2005, at 15:22, Garance A Drosehn wrote: > Checking out the writeup on Ruby2C at: > > http://www.zenspider.com/~ryand/Ruby2C.pdf > > there is one thing about the example on page 25 (of the pdf) > which concerns me a little bit. The example has: > > class MyTest > def factorial(n) > f = 1 > n.downto(2) { |x| f *= x } > return f > end > end > > turn into: > > static VALUE factorial(VALUE self, > VALUE _n) { > long n = NUM2INT(_n); > long f; > long x; > f = 1; > x = n; > while (x >= 2) { > f = f * x; > x = x - 1; > }; > return INT2NUM(f); > } > > One nice thing about ruby is that the programmer does not have > to worry about supported-ranges for integer values. Ruby just > switches from "fixnum" objects into "bignum" objects, without > any attention from the programmer. It seems to me that the C > code that is listed above just assumes the multiplication of > 'f * x' will not overflow. Is that the case? You are correct. We could add the ability to automatically add the bignum/fixnum auto- conversion stuff, but we've not needed the capability yet. -- Eric Hodel - drbrain@segment7.net - http://segment7.net FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04