Fleck Jean-Julien wrote:

> > That is WRONG, you cannot do that.
> 
> Well, I never said that you should do that, I just explained how Ruby
> interpreted it...
> 
> > 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
> 
> Sure. That's quite a hint why ** does not accept a negative number
> with a non integer exponent. To take into account all the special
> cases, you should first see if your exponent is a rational and in that
> case, see if the denominator is odd (after all due simplifications of
> course). In this case (and only this case), you could try to decipher
> a root for this negative number.
> 
> Cheers,


def root base, n
  exp = 1.0/n
  return base ** exp if base >= 0 or n.even?
  -( base.abs ** exp )
end

--