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


  'Solving fractional powers of negative values using complex numbers
  'OxygenBasic


  type ComplexType(double x,y)
  ============================

  function Complex(double x,y) as complexType*
  ============================================
  let r=new ComplexType
  r.x  = x
  r.y  = y
  return @r
  end function

  function zpower(ComplexType*z, double n) as ComplexType*
  ========================================================
  'Using DeMoivre theorem
  double radius,angle,scale
  radius = hypot(z.x,z.y)
  scale = pow(radius,n)
  if z.x=0 then
    angle=.5*pi 'equiv 90 degrees
    if z.y<0 then angle=-angle
  else
    angle = atan(z.y,z.x)
  end if
  angle*=n
  return Complex scale * cos(angle), scale * sin(angle)
  end function


  TEST:
  =====

  ComplexType n=Complex(-2.0 , 0.0)
  ComplexType r=zpower(n , 0.5)
  print str(r.x,6) " , " str(r.y,6) "i"
