On Dec 18, 10:51=A0am, jzakiya <jzak... / mail.com> wrote:
> On Dec 18, 4:52=A0am, "Dasson, Raghav" <raghav.das... / sap.com> wrote:
>
> > jzakiya wrote:
> > > (-3)**3 =3D> -27
>
> > > (-27)**(1/3.0) =A0give NaN instead of -3
>
> > > All odd roots (1/3,1/5,1/7 etc) of negative numbers should give
> > > negative root values, as above, but ruby (in irb) gives NaN (not a
> > > number), even when I require 'complex' .
>
> > > Is this considered an error in Ruby?
>
> > I guess, you are right. THIS IS A 'MATH ERROR' in Ruby.
>
> > The ** method is not able to handle negative numbers raised to Floating=
 points (that are not Integers) =A0
>
> This behavior was shown in ruby ree 1.8.6, 1.8.6, 1.8.7, 1.9.1
>
> -27**1/3.0 =A0 =A0 =A0 =3D> -9.0
> -27 ** 1/3.0 =A0 =A0 =3D> -9.0
> -27 ** (1/3.0) =A0 =3D> -3.0
> -27**(1/3.0) =A0 =A0 =3D> -3.0
> (-27)**(1/3.0) =A0 =3D> NaN
> (-27) ** (1/3.0) =3D> NaN
>
> OK, the first two expression are evaluated as (-27**1)/3 =3D> -9
> The second two are correct (what I expected).
> But the last two, WHY??

And just to verify:

(27)**(1/3.0) =3D> 3.0

So Ruby is messing up parsing (-27)**(1/3.0)