From: "Michael W. Ryder" <_mwryder@...> Date: 2007-06-22T17:40:10+09:00 Subject: Re: Ruby doesn't know how to multiply Pe�a wrote: > From: Michael W. Ryder [mailto:_mwryder@worldnet.att.net] : > # My simple calculator is more precise for some math operations than my > # expensive PC. Maybe we need to implement something like > # General Decimal > # Arithmetic which is available for C++ and Java at > # http://www2.hursley.ibm.com/decimal/ in Ruby. It may be as simple as > # writing wrappers for the operations, I haven't had to time to look > # closer at the package. > > have you tried bigdecimal? > > irb(main):001:0> require 'bigdecimal' > => true > irb(main):002:0> a=BigDecimal("14.95") > => # > irb(main):003:0> b=BigDecimal("0.6") > => # > irb(main):004:0> c=BigDecimal("8.97") > => # > irb(main):005:0> d=BigDecimal("8.970000001") > => # > irb(main):006:0> a*b == c > => true > irb(main):007:0> a*b == d > => false > irb(main):008:0> c == 8.97 > => true > > bigdecimal notation is very handy for calculator-like applications since the raw input usually is of type string. > > kind regards -botp > > I'm not trying to denigrate the project but it looks like it is still in alpha stage while the IBM project seems to have been releasing production code for a while. It also is an IEEE standard, which may or may not mean anything. I hadn't known about the bigdecimal project before and may try comparing the results of it to the general decimal arithmetic package if I get time.