From: jzakiya Date: 2009-12-19T01:26:11+09:00 Subject: Re: Math errors On Dec 18, 11:05 am, Fleck Jean-Julien wrote: > Hello, > > > This behavior was shown in ruby ree 1.8.6, 1.8.6, 1.8.7, 1.9.1 > > > -27**1/3.0       => -9.0 > > -27 ** 1/3.0     => -9.0 > > -27 ** (1/3.0)   => -3.0 > > -27**(1/3.0)     => -3.0 > > (-27)**(1/3.0)   => NaN > > (-27) ** (1/3.0) => NaN > > > OK, the first two expression are evaluated as (-27**1)/3 => -9 > > The second two are correct (what I expected). > > But the last two, WHY?? > > As Matz said, the second two are evaluated as - (27**(1/3.0)), that is > you take the cubic root of +27 which is 3 and then distribute the > minus. > That way, you take the cubic root of a positive number which does not > raise any problem. > > Cheers, > > -- > JJ Fleck > PCSI1 Lycée Kléber That is WRONG, you cannot do that. That only works for odd roots of negative numbers. The even root of negative numbers are imaginary. -27**3**-1 => -3 **correct -27**2**-1 => -5.19615242270663 **WRONG, its 5.196152i