The complex arithmetic library defines all the basic arithmetic operators. Specifically, the following operators work in the usual way and with the usual precedence:
+ - / * =
The subtraction operator (-) has its usual binary and unary meanings.
In addition, you can use the following operators in the usual way:
Addition assign operator (+=)
Subtraction assign operator (-=)
Multiplication assign operator (*=)
Division assign operator (/=)
However, the preceding four operators do not produce values that you can use in expressions. For example, the following expressions do not work:
complex a, b; ... if ((a+=2)==0) {...}; // illegal b = a *= b; // illegal |
You can also use the equality operator (==) and the inequality operator (!=) in their regular meaning.
When you mix real and complex numbers in an arithmetic expression, C++ uses the complex operator function and converts the real values to complex values.