Package com.quantum4j.core.math
Class Complex
java.lang.Object
com.quantum4j.core.math.Complex
Immutable representation of a complex number.
A complex number z = a + bi is represented with real part a and imaginary part b. This class provides
arithmetic operations and constants for common values.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionComplex(double re, double im) Construct a complex number from real and imaginary parts. -
Method Summary
Modifier and TypeMethodDescriptiondoubleGet the squared absolute value (magnitude squared) of this complex number.Add another complex number to this one.Get the complex conjugate.booleandoublegetIm()Get the imaginary part.doublegetRe()Get the real part.inthashCode()mul(double scalar) Multiply this complex number by a scalar.Multiply this complex number by another.Subtract another complex number from this one.toString()
-
Field Details
-
ZERO
Complex zero: 0 + 0i -
ONE
Complex one: 1 + 0i
-
-
Constructor Details
-
Complex
public Complex(double re, double im) Construct a complex number from real and imaginary parts.- Parameters:
re- the real partim- the imaginary part
-
-
Method Details
-
getRe
public double getRe()Get the real part.- Returns:
- the real part
-
getIm
public double getIm()Get the imaginary part.- Returns:
- the imaginary part
-
add
Add another complex number to this one.- Parameters:
other- the complex number to add- Returns:
- a new complex number representing this + other
-
sub
Subtract another complex number from this one.- Parameters:
other- the complex number to subtract- Returns:
- a new complex number representing this - other
-
mul
Multiply this complex number by another.- Parameters:
other- the complex number to multiply- Returns:
- a new complex number representing this × other
-
mul
Multiply this complex number by a scalar.- Parameters:
scalar- the real scalar to multiply- Returns:
- a new complex number representing this × scalar
-
absSquared
public double absSquared()Get the squared absolute value (magnitude squared) of this complex number.- Returns:
- |z|² = a² + b²
-
conjugate
Get the complex conjugate.- Returns:
- a new complex number with negated imaginary part
-
toString
-
equals
-
hashCode
public int hashCode()
-