On Dec 18, 11:05=A0am, Fleck Jean-Julien <jeanjulien.fl... / gmail.com>
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 =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??
>
> 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=E9e Kl=E9ber

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 =3D> -3 **correct
-27**2**-1 =3D> -5.19615242270663 **WRONG, its 5.196152i