When dealing with fractional powers of negative numbers, you need complex numbers. A simple number cannot represent the result.
These can be solved using deMoivre's theorem, relating the power to an angle of rotation in the complex plane
This seems to work:
/*
http://www.suitcaseofdreams.net/De_Moivre_formula.htm
*/
type complex double x,y
function zpower(complex*z, double n)
'Using DeMoivre theorem
double radius,ang,scale
radius = hypot(z.x,z.y)
scale = radius^n
if z.x=0 then
angle=.5*pi '90 degrees
if z.y<0 then angle=1.5*pi
else
angle = atan(z.y,z.x)
end if
angle*=n
z.x = scale * cos(angle)
z.y = scale * sin(angle)
end function
complex n={-2.0 , 0.0}
zpower( n, 0.2)
print str(n.x,6) " + " str(n.y,6) "i"
A good test is -4^.5
expected result: {0 + 2i}