From: Gavin Sinclair Date: 2009-11-19T18:30:05+09:00 Subject: Re: Exact (LISP-ish) calculations in Ruby? On Nov 19, 1:35 am, 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 :) That "idealistic desire" would only be needed in very special cases in real programming, so it's not surprising not to find a Ruby library for it. Essentially, you're looking for the capabilities provided by a Computer Algebra System (CAS) like Mathematica, as mentioned, or Maxima (open source, IIRC). You may be able to find an open source CAS that has Ruby bindings, or for which (if you're sufficiently motivated) you can write some bindings. Or you can give it a go! > sqrt(2) * sqrt(3) --> sqrt(6) > sqrt(8) --> 2 * sqrt(2) > 2 * PI * 3.5 --> 7 * PI Not my idea of fun, though. The beauty of Mathematics is best appreciated in the mind, for it's only there that sqrt(2) exists. -- Gavin Sinclair