if o = "+" then return (a+c)&(the itemdelimiter)&(b+d)
if o = "-" then return (a-c)&(the itemdelimiter)&(b-d)
if o = "*" then return ((a*c)-(b*d))&(the itemdelimiter)&((b*c)+(c*d))
if o = "/" then return (((a*c)/((c^2)+(d^2)))+((b*d)/((c^2)+(d^2))))&(the itemdelimiter)&(((b*c)/((c^2)+(d^2)))+((c*d)/(((c^2)+(d^2))^2)))
if o = "¥" or h = "div" then return (((a*c)DIV((c^2)+(d^2)))+((b*d)DIV((c^2)+(d^2))))&(the itemdelimiter)&(((b*c)DIV((c^2)+(d^2)))+((c*d)DIV(((c^2)+(d^2))^2)))
if o = "mod" then return (((a*c)MOD((c^2)+(d^2)))+((b*d)MOD((c^2)+(d^2))))&(the itemdelimiter)&(((b*c)MOD((c^2)+(d^2)))+((c*d)MOD(((c^2)+(d^2))^2)))
if o = "^" then return exp((c*ln(sqrt((a^2)+(b^2))))-(d*theta(a,b)))*cos((d*ln(sqrt((a^2)+(b^2))))+(c*theta(a,b)))&(the itemdelimiter)&exp((c*ln(sqrt((a^2)+(b^2))))-(d*theta(a,b)))*sin((d*ln(sqrt((a^2)+(b^2))))+(c*theta(a,b)))
if o = "竏" or h = "root" then return complexNumbers(a,b,"^",c/((c^2)+(d^2)),d/((c^2)+(d^2)))
if a = "|" or a = "abs" then return sqrt((b^2)+(o^2))&(the itemdelimiter)&"0"
if a = "sin" then return sin(b)*cosh(o)&(the itemdelimiter)&cos(b)*sinh(o)
if a = "cos" then return cos(b)*cosh(o)&(the itemdelimiter)&sin(b)*sinh(o)
if a = "tan" then return complexnumbers(sin(b)*cosh(o),cos(b)*sinh(o),"/",cos(b)*cosh(o),sin(b)*sinh(o))
if a = "atan" then return ((theta(1-o,b)/2)-(theta(1+o,-b)/2))&(the itemdelimiter)&(ln(((b^2)+((o+1)^2))/((b^2)+((o-1)^2)))/4)
if a = "/" then return (b/((b^2)+(o^2)))&(the itemdelimiter)&(o/((b^2)+(o^2)))
if a = "ln" or a = "log" or a = "loge" then
if c is a number then return ln(abs(b))&(the itemdelimiter)&(theta(b,o)+(2*pi*c))
return ln(abs(b))&(the itemdelimiter)&theta(b,o)
end if
if a = "log2" then return complexNumbers(item 1 of complexNumbers("ln",b,o,c),item 2 of complexNumbers("ln",b,o,c),"/",ln(2),0)
if a = "log10" then return complexNumbers(item 1 of complexNumbers("ln",b,o,c),item 2 of complexNumbers("ln",b,o,c),"/",ln(10),0)
if a = "exp" then return (exp(b)*cos(o))&(the itemdelimiter)&(cos(o)*sin(o))
if a = "竏" or a = "sqrt" or a = "sqr" then return complexnumbers(b,o,"^",0.5,0)
if a = "sgn" then
if b < 0 then put "-1" into ta
if b > 0 then put "1" into ta
if b = 0 then put "0" into ta
put (the itemdelimiter) after ta
if o > 0 then put "1" after ta
if o < 0 then put "-1" after ta
if o = 0 then put "0" after ta
return ta
end if
if a = "P>R" then return (b*cos(o))&(the itemdelimiter)&(b*sin(o))
if a = "R>P" then return sqrt((b^2)+(o^2))&(the itemdelimiter)&theta(b,o)
if a = "BC" or a = "BaseConv" or a = "BaseConvert" or a = "BaseConvertReal" then
put baseconvertreal(b,c,d) into ta
put (the itemdelimiter) after ta
put baseconvertreal(o,c,d) after ta
return ta
end if
return "Error: Unsupported operation."
end complexNumbers
function cn l,m,n,o,p
return complexNumbers(l,m,n,o,p)
end cn
function cpxAdd a,b,c,d
return cn(a,b,"+",c,d)
end cpxAdd
function cpxSub a,b,c,d
return cn(a,b,"-",c,d)
end cpxSub
function cpxMul a,b,c,d
return cn(a,b,"*",c,d)
end cpxMul
function cpxDiv a,b,c,d
return cn(a,b,"/",c,d)
end cpxDiv
function cpxPower a,b,c,d
return cn(a,b,"^",c,d)
end cpxPower
function cpxLog a,b,v
return cn("ln",a,b,v)
end cpxlog
function cpxExp a,b
return cn("exp",a,b)
end cpxExp
function cpxSin a,b
return cn("sin",a,b)
end cpxSin
function cpxCos a,b
return cn("cos",a,b)
end cpxCos
function cpxAbs a,b
return cn("|",a,b)
end cpxAbs
function cpxRecip a,b
return cn("/",a,b)
end cpxRecip
function cpxSgn a,b
return cn("sgn",a,b)
end cpxSgn
function cpxIntDiv a,b,c,d
return cn(a,b,"¥",c,d)
end cpxIntDiv
function cpxMod a,b,c,d
return cn(a,b,"mod",c,d)
end cpxMod
function cpxSqrt a,b
return cn("sqrt",a,b)
end cpxSqrt
function cpxRoot a,b,c,d
return cn(a,b,"竏",c,d)
end cpxRoot
function cpxTan a,b
return cn("tan",a,b)
end cpxTan
function cpxstrtoval x
put the itemdelimiter into z
if x is a number then return (x*1)&z&"0"
if the last char of x <> "i" then return "ERROR: Expected complex number here."
if "+" is not in x and "-" is not in x then
delete last char of x
return "0"&z&(x*1)
end if
if "+" is in x and "-+" is not in x then
set the itemdelimiter to "+"
delete last char of x
put ((item 1 of x)*1)&z&((item 2 of x)*1) into y
set the itemdelimiter to z
return y
end if
if the first char of x is "-" and "+-" is not in x then
set the itemdelimiter to "-"
delete last char of x
put ((item 2 of x)*-1)&z&-((item 3 of x)*1) into y