  /*
  http://www.suitcaseofdreams.net/De_Moivre_formula.htm
  */

  type complex double x,y


  function zpower(complex*z, double n)
  'Using DeMoivre theorem
  double radius,angle,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=-angle
  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={-4.0 , 0.0}

  zpower( n, 0.5)

  print str(n.x,6) " + " str(n.y,6) "i"
