'COMPLEX OPERATIONS
=============
class Complex
=============
double x,y
method set(double*bx,*by)
x=bx
y=by
end method
method set(complex*b)
x=b.x
y=b.y
end method
method get(double*bx,*by)
bx=x
by=y
end method
method get(complex*b)
b.x=x
b.y=y
end method
method add(complex*b)
x+=b.x
y+=b.y
end method
method sub(complex*b)
x-=b.x
y-=b.y
end method
method mul(complex*b)
double d
d=x
x = x * b.x - y * b.y
y = y * b.x + d * b.y
end method
method div(complex*b)
double d,v
v=1/(b.x * b.x + b.y * b.y)
d=x
x = (x * b.x + y * b.y) * v
y = (y * b.x - d * b.y) * v
end method
method power(double n)
'Using DeMoivre theorem
double r,an,mg
r = hypot(x,y)
mg = r^n
if x=0 then
an=.5*pi '90 degrees
if y<0 then an=-an
else
an = atan(y,x)
end if
an *= n
x = mg * cos(an)
y = mg * sin(an)
end method
method show() as string
return str(x,14) ", " str(y,14)
end method
end class
complex ca,cb,cc
cc.set 1,2
cc.add ca
cc.mul cb