RosettaCodeData/Task/Arithmetic-Complex/Smart-BASIC/arithmetic-complex.smart

18 lines
334 B
Plaintext

' complex numbers are native for "smart BASIC"
A=1+2i
B=3-5i
' all math operations and functions work with complex numbers
C=A*B
PRINT SQR(-4)
' example of solving quadratic equation with complex roots
' x^2+2x+5=0
a=1 ! b=2 ! c=5
x1=(-b+sqr(b^2-4*a*c))/(2*a)
x2=(-b-sqr(b^2-4*a*c))/(2*a)
print x1,x2
' gives output
-1+2i -1-2i