Class Complex

java.lang.Object
com.quantum4j.core.math.Complex

public final class Complex extends Object
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
    Modifier and Type
    Field
    Description
    static final Complex
    Complex one: 1 + 0i
    static final Complex
    Complex zero: 0 + 0i
  • Constructor Summary

    Constructors
    Constructor
    Description
    Complex(double re, double im)
    Construct a complex number from real and imaginary parts.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Get the squared absolute value (magnitude squared) of this complex number.
    add(Complex other)
    Add another complex number to this one.
    Get the complex conjugate.
    boolean
     
    double
    Get the imaginary part.
    double
    Get the real part.
    int
     
    mul(double scalar)
    Multiply this complex number by a scalar.
    mul(Complex other)
    Multiply this complex number by another.
    sub(Complex other)
    Subtract another complex number from this one.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • ZERO

      public static final Complex ZERO
      Complex zero: 0 + 0i
    • ONE

      public static final Complex 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 part
      im - 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

      public Complex add(Complex other)
      Add another complex number to this one.
      Parameters:
      other - the complex number to add
      Returns:
      a new complex number representing this + other
    • sub

      public Complex sub(Complex other)
      Subtract another complex number from this one.
      Parameters:
      other - the complex number to subtract
      Returns:
      a new complex number representing this - other
    • mul

      public Complex mul(Complex other)
      Multiply this complex number by another.
      Parameters:
      other - the complex number to multiply
      Returns:
      a new complex number representing this × other
    • mul

      public Complex mul(double scalar)
      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

      public Complex conjugate()
      Get the complex conjugate.
      Returns:
      a new complex number with negated imaginary part
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object