From: Benoit Daloze Date: 2009-12-18T17:00:21+09:00 Subject: Re: Math errors --0016e65aedc658c79e047afc2138 Content-Type: text/plain; charset=ISO-8859-1 IN 1.9.2 I got: ~ $> ruby -ve 'p v=Math.cbrt(-27); p v**3' ruby 1.9.2dev (2009-12-11 trunk 26067) [x86_64-darwin10.2.0] -3.0 -27.0 ~ $> ruby -ve 'p v=(-27)**(1/3.0); p v**3' (1.5000000000000004+2.598076211353316i) (-27.000000000000007+1.2434497875801753e-14i) ~ $> ruby -ve 'p v=(-27)**(Rational(1,3)); p v**3' (1.5+2.5980762113533156i) (-26.99999999999999+3.552713678800501e-15i) Got easy results, but with all different values ... So, the first is right, of course. The second is a good approximation, for floats ... And the last is almost good, while I would expect to be exact (I think it should use Math.cbrt in this case) I would probably interested to use BigDecimal, but it's impossible I think to use it for Complex. (And actually it accept only Fixnum exponent) Another error in the exception: TypeError: wrong argument type BigDecimal (expected Fixnum) But it accept Float, really ;) 2009/12/18 Tanaka Akira > 2009/12/18 jzakiya : > > (-3)**3 => -27 > > > > (-27)**(1/3.0) give NaN instead of -3 > > Ruby 1.9 has Math.cbrt. > > % ruby -e 'p Math.cbrt(-27)' > -3.0 > -- > Tanaka Akira > > --0016e65aedc658c79e047afc2138--