Pure Programmer
Blue Matrix


Cluster Map

Project: Complex Number Class

[[Complex_number|Complex numbers]] is a number that can be expressed in the form `a + bi` where `a` and `b` are real numbers and `i` represents the imaginary quantity `sqrt(-1)`. Define a complex number class that can perform multiplication, division, reciprocal, addition, subtraction, absolute value (magnitude), argument (phase), square root, exponential, and natural logarithm functions.

Output
$ javac -Xlint ComplexNumberClass.java $ java -ea ComplexNumberClass a: 1.0+1.0i b: 3.0+4.0i a + b: 4.0+5.0i a - b: -2.0-3.0i a * b: -1.0+7.0i 1 / a: 0.5-0.5i 1 / b: 0.12-0.16i a / b: 0.28-0.04000000000000001i |a|: 1.4142135623730951 |b|: 5.0 φ(a): 0.7853981633974484 φ(b): 0.9272952180016122 sqrt(a): 1.09868411346781+0.4550898605622274i sqrt(b): 2.0+1.0i exp(a): 1.4686939399158854+2.2873552871788427i exp(b): -13.128783081462158-15.200784463067954i ln(a): 0.3465735902799727+0.7853981633974484i ln(b): 1.6094379124341003+0.9272952180016122i

Solution