# Erratic behavior with complex arithmetic, e.g., sin(z) returns NaN My code is producing unexpected results when taking the sine of a complex number.  I wrote the following test function to research the problem.

Function testsine()
variable /c  a

a=cmplx(0,1)

print "a= ", a
print "sin(a)= ", sin(a)
print "sin(sqrt(-1))= ", sin(sqrt(-1))
end

[Click and drag to move]

The results printed in the Command Window are pasted here:

`•testsine()`
`  a=   (0,1)`
`  sin(a)=   0`
`  sin(sqrt(-1))=   NaN`

The built-in sine function is not handling complex numbers as the manual leads me to believe, i.e., sin(x+iy)=sin(x)cosh(y)+ i cos(x)sinh(y). Shouldn't this have produced the result (0, 1.1752) in both cases above, i.e., the sin(a) and sin(sqrt(-1))?

This is rather a 'problem' of the print command not expecting a complex number unless explicitly getting handed one. Try this:

Function testsine()
variable/c a,b,c

a=cmplx(0,1)
b=sin(a)
c=sin(sqrt(-1))

print "a= ", a
print "sin(a)= ", b
print "sin(sqrt(-1))= ", c
End

Will give:

•testsine()
a=   (0,1)
sin(a)=   (0,1.1752)
sin(sqrt(-1))=   (0,1.1752)