From ruby-talk Thu Nov 19 02:08:31 2009 From: Ken Bloom Date: Thu, 19 Nov 2009 02:08:31 +0000 To: ruby-talk Subject: Re: Exact (LISP-ish) calculations in Ruby? Message-Id: X-MARC-Message: https://marc.info/?l=ruby-talk&m=125859656022638 On Thu, 19 Nov 2009 02:18:22 +0900, Marnen Laibow-Koser wrote: > Aldric Giacomoni wrote: >> Has anyone written a gem for exact calculations? The kind one would >> find on a LISP REPL, or when using your average HP scientific >> calculator? >>>> 3 / 4 >> => 3/4 >>>> 3 / 6 >> => 1/2 >>>> sqrt(2) >> => sqrt(2) >>>> sqrt(4) >>>> 2 >> >> I couldn't find anything on gemcutter or rubyforge, but maybe I missed >> it.. >> I don't ask because I need it.. I ask because of an idealistic desire >> for exact calculations :) > > Wiring Rational into Numeric#/ shouldn't be too hard. I'm not sure how > to deal with square roots without lots of special cases, however. > Umm, there's a standard library for wiring in Rational: require 'mathn' -- Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/