From: Tomasz Wegrzanowski Date: 2002-01-03T09:03:38+09:00 Subject: [ruby-talk:30088] Re: mathn questions On Thu, Jan 03, 2002 at 08:12:58AM +0900, Joel VanderWerf wrote: > > I'm writing some numerical stuff in Ruby and C, and I'd like to use > mathn.rb for the Ruby part. This is what irb's math mode uses to give > you '1/2 ==> 1/2' rather than '1/2 ==> 0'. Two questions: > > 1. Does changing integer division in this way interfere with anything in > the standard library? Any other consequences I should be aware of? > The performance cost of using rationals is not a concern to me, even > considering the garbage creation, since C code is doing all the heavy > lifting anyway. I just want the Ruby front end to preserve as much > precision as possible. > > 2. Prime generation seems to happen redundantly in mathn.rb. It looks > like each time ** or gcd2 is called, the sequence of primes are > enumerated (partially, of course) *twice*. It would be better to treat > this sequence as static data and continue the enumeration as needed. > This is not a big deal for me, just a suggestion for whoever is > maintaining the code. > > I have the Ruby 1.6.6 version of mathn.rb (which is dated 1998/01/16). One more advertisement: I made incomplete Ruby bindings to libGMP. You may consider using this instead of standard Ruby modules. It supports rational numbers. See http://freebsd.orzeszkowej.ble.pl/~taw/ Newest version is: http://freebsd.orzeszkowej.ble.pl/~taw/ruby_gmp.alpha6.tar.bz2