From: Charles Mills Date: 2005-10-27T05:23:44+09:00 Subject: Re: Time for built-in Rational and Complex classes? On Oct 26, 2005, at 7:51 AM, Gavin Sinclair wrote: > On 10/26/05, Mathieu Bouchard wrote: > >> On Wed, 26 Oct 2005, Charles Mills wrote: >> >>> A C version could be created using the regular extension >>> mechanisms. I >>> personally would like to see a faster complex class. Also >>> implementing GCD in >>> C would speed up the rational class substantially. >>> >> >> I think that just recoding the GCD in C would make a big >> difference that >> would reduce the need for recoding the rest of Rational in C. >> >> For the Complexes, I hope that recoding it in C wouldn't reduce its >> functionality. Right now, one can make not only Complex Floats, >> but also >> Complex Rationals and Complex (Gaussian) Integers. >> > > Wouldn't it be a matter of doing a direct port from the current Ruby > code, which hasn't changed in at least two years, to C? Even better, > to "Ruby extension C"? I.e. no loss of functionality. > > Gavin > I don't see why not. But using GCD as an example the C version would have to handle fixnums, bignums and arbitrary types that respond to +,-,*,/,etc. You could just do a straight translation into C using rb_funcall(), but if you wanted to see a speed up for the common case (fixnum and bignum) than it would require handling those cases specially (using arithmetic in C and the rb_big_*() functions). Is there a more straight forward solution? -Charlie