Class Complex128

java.lang.Object
org.flag4j.algebraic_structures.Complex128
All Implemented Interfaces:
Serializable, Comparable<Complex128>, Field<Complex128>, Ring<Complex128>, Semiring<Complex128>

public class Complex128 extends Object implements Field<Complex128>
Represents an immutable complex number with double-precision floating point components.

This class models a complex number in rectangular (Cartesian) form, defined by its real and imaginary parts, each stored as a 64-bit floating-point number (double). Instances of Complex128 are immutable and thread-safe.

The class provides various operations for complex arithmetic, including addition, subtraction, multiplication, division, exponentiation, logarithms, trigonometric and hyperbolic functions, as well as utilities for comparing and rounding complex numbers.

Usage Example:


 Complex128 a = new Complex128(2.5, 3.2);   // Creates a complex number 2.5 + 3.2i.
 Complex128 b = new Complex128(1, -4);      // Creates a complex number 1 - 4i.
 Complex128 sum = a.add(b);                 // Sum of a and b.
 Complex128 product = a.mult(b);            // Product of a and b.
 

Special Values:

The class defines several constants for common complex numbers:

  • ZERO - Complex number representing zero (0 + 0i).
  • ONE - Complex number representing one (1 + 0i).
  • TWO - Complex number representing two (2 + 0i).
  • THREE - Complex number representing three (3 + 0i).
  • IMAGINARY_UNIT - The imaginary unit (0 + 1i).
  • INV_IMAGINARY_UNIT - Negative imaginary unit (0 - 1i).
  • NaN - Complex number representing a Not-a-Number value.
  • POSITIVE_INFINITY - Complex number with infinite real part.
  • NEGATIVE_INFINITY - Complex number with negative infinite real part.

Mathematical Functions:

The class provides methods for several mathematical functions:

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final double
    Imaginary component of the complex number.
    static final Complex128
    The imaginary unit i.
    static final Complex128
    The additive inverse of the imaginary unit, -i.
    static final Complex128
    Complex number with real and imaginary parts equal to Double.NaN.
    static final Complex128
    Complex number with real part equal to Double.NEGATIVE_INFINITY.
    static final Complex128
    The complex number with zero imaginary part and one real part.
    static final Complex128
    Complex number with real part equal to Double.POSITIVE_INFINITY.
    final double
    Real component of the complex number.
    static final Complex128
    The double value closer than any other to the square root of 3,
    static final Complex128
    The double value closer than any other to the square root of 2.
    static final Complex128
    The complex number with zero imaginary part and three real part.
    static final Complex128
    The complex number with zero imaginary part and two real part.
    static final Complex128
    The complex number with zero imaginary and real parts.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Complex128(double re)
    Constructs a complex number with specified real component and zero imaginary component.
    Complex128(double re, double im)
    Constructs a complex number with specified complex and real components.
    Constructs a complex number from a string of the form "a +/- bi" where a and b are real values where either may be omitted. i.e.
    Constructs a 128-bit complex number from a 64-bit complex number.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Complex128
    Computes the inverse cosine of a complex value.
    add(double b)
    Sums an elements of this field with a real number.
    Sums two elements of this field (associative and commutative).
    Computes the additive inverse for an element of this field.
    static double
    Computes the complex argument function for a complex number.
    static int
    argmax(Complex128... values)
    Computes the index of the maximum magnitude from an array of complex numbers.
    static int
    Computes the index of the minimum real component from an array of complex numbers.
    static int
    argmin(Complex128... values)
    Computes the index of the minimum magnitude from an array of complex numbers.
    static int
    Computes the index of the minimum real component from an array of complex numbers.
    static Complex128
    Computes the inverse sine of a complex value.
    static Complex128
    Computes the inverse tangent of a complex value.
    static double
    Computes the 2 argument arc-tangent function for a complex number.
    int
    Compares this element of the field with b.
    Computes the conjugate of this field element.
    static Complex128
    Computes the trigonometric cosine value of a complex value.
    static Complex128
    Computes the hyperbolic cosine of a complex value.
    div(double b)
    Computes the quotient of an elements of this field and a real number.
    Computes the quotient of two elements of this field.
    double
    Converts this complex number to an equivalent double.
    boolean
    equals(double b)
    Checks if this complex has zero imaginary part and real part equal to a double.
    boolean
    Checks if an object is equal to this Field element.
    static Complex128
    exp(Complex128 exponent)
    Computes the exponential function with the given input.
    static Complex128
    fromPolar(double r, double theta)
    Converts a complex number expressed in polar from to the rectangular form.
    Gets the multiplicative identity for this semiring.
    Gets the additive identity for this semiring.
    int
    Generates the hashcode for this complex number.
    double
    im()
    Gets the imaginary component of this complex number.
    boolean
    Checks if this complex number has non-zero imaginary part.
    boolean
    Checks if this complex number is a real valued double.
    boolean
    Checks if this field element is finite in magnitude.
    boolean
    Checks if this complex number has zero real part.
    boolean
    Checks if this field element is infinite in magnitude.
    boolean
    Checks if this complex number is a real valued integer.
    boolean
    Checks if this field element is NaN in magnitude.
    boolean
    Checks if this value is a multiplicative identity for this semiring.
    boolean
    Checks if this complex number has zero imaginary part.
    boolean
    Checks if this value is an additive identity for this semiring.
    static int
    Gets the length of the string representation of this complex number.
    static Complex128
    ln(double num)
    Computes the natural logarithm of a double.
    static Complex128
    Computes the complex natural logarithm of a complex number.
    static Complex128
    log(double num)
    Computes the complex logarithm base 10 of a complex number.
    static Complex128
    log(double base, double num)
    Computes the complex logarithm, with specified base, of a complex number.
    static Complex128
    log(double base, Complex128 num)
    Computes the complex logarithm, with specified base, of a complex number.
    static Complex128
    Computes the complex logarithm base 10 of a complex number.
    static Complex128
    Computes the complex logarithm, with specified base, of a complex number.
    double
    mag()
    Computes the magnitude of this field element.
    double
    Squares this magnitude of this complex number.
    static Complex128
    max(Complex128... values)
    Computes the maximum magnitude from an array of complex numbers.
    static Complex128
    maxRe(Complex128... values)
    Computes the minimum real component from an array of complex numbers.
    static Complex128
    min(Complex128... values)
    Computes the minimum magnitude from an array of complex numbers.
    static Complex128
    minRe(Complex128... values)
    Computes the minimum real component from an array of complex numbers.
    mult(double b)
    Multiplies an element of this field with a real number.
    Multiplies two elements of this field (associative and commutative).
    Computes the multiplicative inverse of this complex number.
    static boolean
    nearZero(Complex128 n, double tol)
    Checks if a number is near zero in magnitude.
    static Complex128
    pow(double a, Complex128 b)
    Compute a raised to the power of b.
    static Complex128
    pow(Complex128 a, double b)
    Computes a raised to the power of b.
    static Complex128
    Compute a raised to the power of b.
    double
    re()
    Gets the real component of this complex number.
    static Complex128
    Rounds both components of a complex number to the nearest respective integer.
    static Complex128
    round(Complex128 n, int decimals)
    Rounds number to specified number of decimal places.
    static Complex128
    roundToZero(Complex128 n, double tol)
    Rounds a complex numbers to zero if its magnitude within the specified tolerance from zero.
    static Complex128
    sgn(Complex128 value)
    The complex signum function.
    static Complex128
    Computes the trigonometric sine of a complex value.
    static Complex128
    Computes the hyperbolic sine of a complex value.
    Computes the square root of this field element.
    static Complex128
    sqrt(double num)
    Computes the principle square root of a number.
    sub(double b)
    Computes difference of an element of this field and a real number.
    Computes difference of two elements of this field.
    static Complex128
    sum(Complex128... numbers)
    Computes the sum of all data of specified array.
    static Complex128
    Computes the trigonometric tangent value of a complex value.
    static Complex128
    Computes the hyperbolic tangent of a complex value.
    double[]
    Converts a complex number to an equivalent polar from.
    Converts the complex number to a string representation.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.flag4j.algebraic_structures.Ring

    abs
  • Field Details

    • ZERO

      public static final Complex128 ZERO
      The complex number with zero imaginary and real parts.
    • ONE

      public static final Complex128 ONE
      The complex number with zero imaginary part and one real part.
    • TWO

      public static final Complex128 TWO
      The complex number with zero imaginary part and two real part.
    • THREE

      public static final Complex128 THREE
      The complex number with zero imaginary part and three real part.
    • ROOT_THREE

      public static final Complex128 ROOT_THREE
      The double value closer than any other to the square root of 3,
    • ROOT_TWO

      public static final Complex128 ROOT_TWO
      The double value closer than any other to the square root of 2.
    • IMAGINARY_UNIT

      public static final Complex128 IMAGINARY_UNIT
      The imaginary unit i.
    • INV_IMAGINARY_UNIT

      public static final Complex128 INV_IMAGINARY_UNIT
      The additive inverse of the imaginary unit, -i.
    • POSITIVE_INFINITY

      public static final Complex128 POSITIVE_INFINITY
      Complex number with real part equal to Double.POSITIVE_INFINITY.
    • NEGATIVE_INFINITY

      public static final Complex128 NEGATIVE_INFINITY
      Complex number with real part equal to Double.NEGATIVE_INFINITY.
    • NaN

      public static final Complex128 NaN
      Complex number with real and imaginary parts equal to Double.NaN.
    • re

      public final double re
      Real component of the complex number.
    • im

      public final double im
      Imaginary component of the complex number.
  • Constructor Details

    • Complex128

      public Complex128(double re)
      Constructs a complex number with specified real component and zero imaginary component.
      Parameters:
      re - Real component of complex number.
    • Complex128

      public Complex128(double re, double im)
      Constructs a complex number with specified complex and real components.
      Parameters:
      re - Real component of complex number.
      im - Imaginary component of complex number.
    • Complex128

      public Complex128(String num)
      Constructs a complex number from a string of the form "a +/- bi" where a and b are real values where either may be omitted. i.e. "a", "bi", "a +/- i", and "i" are all also valid. Excess white space is ignored.
      Parameters:
      num - The string representation of a complex number. Must be parsable by ComplexNumberParser.parseNumberToComplex128(String).
      Throws:
      Flag4jParsingException - If num cannot be parsed.
    • Complex128

      public Complex128(Complex64 num)
      Constructs a 128-bit complex number from a 64-bit complex number.
      Parameters:
      num - The 64-bit complex number.
  • Method Details

    • equals

      public boolean equals(double b)
      Checks if this complex has zero imaginary part and real part equal to a double.
      Returns:
      True if this.re == b && this.im == 0. False otherwise.
    • equals

      public boolean equals(Object b)
      Checks if an object is equal to this Field element.
      Overrides:
      equals in class Object
      Parameters:
      b - Object to compare to this Field element.
      Returns:
      True if the objects are the same or are both Complex128's and have equal real and imaginary parts.
    • hashCode

      public int hashCode()
      Generates the hashcode for this complex number.
      Overrides:
      hashCode in class Object
      Returns:
      An integer hash for this complex number.
    • isReal

      public boolean isReal()
      Checks if this complex number has zero imaginary part.
      Returns:
      True if this complex number has zero imaginary part. False otherwise.
      See Also:
    • isImaginary

      public boolean isImaginary()
      Checks if this complex number has zero real part.
      Returns:
      True if this complex number has zero real part. False otherwise.
      See Also:
    • isComplex

      public boolean isComplex()
      Checks if this complex number has non-zero imaginary part.
      Returns:
      True if this complex number has non-zero imaginary part. False otherwise.
      See Also:
    • add

      public Complex128 add(Complex128 b)
      Sums two elements of this field (associative and commutative).
      Specified by:
      add in interface Semiring<Complex128>
      Parameters:
      b - Second field element in sum.
      Returns:
      The sum of this element and b.
    • add

      public Complex128 add(double b)
      Sums an elements of this field with a real number.
      Specified by:
      add in interface Field<Complex128>
      Parameters:
      b - Second element in sum.
      Returns:
      The sum of this element and b.
    • sub

      public Complex128 sub(Complex128 b)
      Computes difference of two elements of this field.
      Specified by:
      sub in interface Ring<Complex128>
      Parameters:
      b - Second field element in difference.
      Returns:
      The difference of this field element and b.
    • sub

      public Complex128 sub(double b)
      Computes difference of an element of this field and a real number.
      Specified by:
      sub in interface Field<Complex128>
      Parameters:
      b - Second element in difference.
      Returns:
      The difference of this field element and b.
    • sum

      public static Complex128 sum(Complex128... numbers)
      Computes the sum of all data of specified array.
      Parameters:
      values - Values to compute product of.
      Returns:
      The sum of all values in values.
    • mult

      public Complex128 mult(Complex128 b)
      Multiplies two elements of this field (associative and commutative).
      Specified by:
      mult in interface Semiring<Complex128>
      Parameters:
      b - Second field element in product.
      Returns:
      The product of this field element and b.
    • isZero

      public boolean isZero()

      Checks if this value is an additive identity for this semiring.

      An element 0 is an additive identity if a + 0 = a for any a in the semiring.

      Specified by:
      isZero in interface Semiring<Complex128>
      Returns:
      True if this value is an additive identity for this semiring. Otherwise, false.
    • isOne

      public boolean isOne()

      Checks if this value is a multiplicative identity for this semiring.

      An element 1 is a multiplicative identity if a * 1 = a for any a in the semiring.

      Specified by:
      isOne in interface Semiring<Complex128>
      Returns:
      True if this value is a multiplicative identity for this semiring. Otherwise, false.
    • getZero

      public Complex128 getZero()

      Gets the additive identity for this semiring.

      An element 0 is an additive identity if a + 0 = a for any a in the semiring.

      Specified by:
      getZero in interface Semiring<Complex128>
      Returns:
      The additive identity for this semiring.
    • getOne

      public Complex128 getOne()

      Gets the multiplicative identity for this semiring.

      An element 1 is a multiplicative identity if a * 1 = a for any a in the semiring.

      Specified by:
      getOne in interface Semiring<Complex128>
      Returns:
      The multiplicative identity for this semiring.
    • mult

      public Complex128 mult(double b)
      Multiplies an element of this field with a real number.
      Specified by:
      mult in interface Field<Complex128>
      Parameters:
      b - Second element in product.
      Returns:
      The product of this field element and b.
    • div

      public Complex128 div(Complex128 b)
      Computes the quotient of two elements of this field.
      Specified by:
      div in interface Field<Complex128>
      Parameters:
      b - Second field element in quotient.
      Returns:
      The quotient of this field element and b.
    • div

      public Complex128 div(double b)
      Computes the quotient of an elements of this field and a real number.
      Specified by:
      div in interface Field<Complex128>
      Parameters:
      b - Second element in quotient.
      Returns:
      The quotient of this field element and b.
    • mag

      public double mag()
      Computes the magnitude of this field element.
      Specified by:
      mag in interface Ring<Complex128>
      Returns:
      The magnitude of this field element.
    • sqrt

      public Complex128 sqrt()
      Computes the square root of this field element.
      Specified by:
      sqrt in interface Field<Complex128>
      Returns:
      The square root of this field element.
    • magSquared

      public double magSquared()

      Squares this magnitude of this complex number.

      Returns:
      The square of the magnitude of this complex number as a real value.
    • addInv

      public Complex128 addInv()

      Computes the additive inverse for an element of this field.

      An element -x is an additive inverse for a field element x if -x + x = 0 where 0 is the additive identity.

      Specified by:
      addInv in interface Ring<Complex128>
      Returns:
      The additive inverse for this field element.
    • multInv

      public Complex128 multInv()
      Computes the multiplicative inverse of this complex number.
      Specified by:
      multInv in interface Field<Complex128>
      Returns:
      The multiplicative inverse of this complex number.
    • conj

      public Complex128 conj()
      Computes the conjugate of this field element.
      Specified by:
      conj in interface Ring<Complex128>
      Returns:
      The conjugate of this field element.
    • pow

      public static Complex128 pow(double a, Complex128 b)
      Compute a raised to the power of b. and returns a Complex128.
      Parameters:
      a - The base.
      b - The exponent.
      Returns:
      a to the power of b.
    • pow

      public static Complex128 pow(Complex128 a, Complex128 b)
      Compute a raised to the power of b. and returns a Complex128.
      Parameters:
      a - The base.
      b - The exponent.
      Returns:
      a to the power of b.
    • pow

      public static Complex128 pow(Complex128 a, double b)
      Computes a raised to the power of b.
      Parameters:
      a - The base.
      b - The exponent.
      Returns:
      a raised to the power of b.
    • exp

      public static Complex128 exp(Complex128 exponent)
      Computes the exponential function with the given input.
      Parameters:
      exponent - Input to the exponential function.
      Returns:
      The output of the exponential function.
    • ln

      public static Complex128 ln(double num)
      Computes the natural logarithm of a double. For non-negative values this function is equivalent to Math.log(double). If the number is negative, then it is passed on as a complex value to ln(Complex128).
      Parameters:
      num - Input to the complex natural logarithm function.
      Returns:
      The principle value of the complex natural logarithm for the given input.
    • ln

      public static Complex128 ln(Complex128 num)
      Computes the complex natural logarithm of a complex number. This function is the analytic continuation of the natural logarithm, that is the log base e.
      Parameters:
      num - Input to the complex natural logarithm function.
      Returns:
      The principle value of the complex natural logarithm for the given input.
    • log

      public static Complex128 log(double num)
      Computes the complex logarithm base 10 of a complex number. Please note, this is NOT the natural logarithm. If the complex natural logarithm is desired see ln(double). To specify a base, see log(double, Complex128) or log(Complex128, Complex128). If the argument is non-negative, then this function is equivalent to Math.log(double).
      Parameters:
      num - Input to the complex logarithm base 10 function.
      Returns:
      The principle value of the complex logarithm base 10 for the given input.
    • log

      public static Complex128 log(Complex128 num)
      Computes the complex logarithm base 10 of a complex number. Please note, this is NOT the complex natural logarithm. If the complex natural logarithm is desired see ln(Complex128). To specify a base, see log(double, Complex128) or log(Complex128, Complex128).
      Parameters:
      num - Input to the complex logarithm base 10 function.
      Returns:
      The principle value of the complex logarithm base 10 for the given input.
    • log

      public static Complex128 log(double base, double num)
      Computes the complex logarithm, with specified base, of a complex number.
      Parameters:
      base - Base of the logarithm.
      num - Input to the complex logarithm function with specified base.
      Returns:
      The principle value of the complex logarithm, with specified base, for the given input.
    • log

      public static Complex128 log(double base, Complex128 num)
      Computes the complex logarithm, with specified base, of a complex number.
      Parameters:
      base - Base of the logarithm.
      num - Input to the complex logarithm function with specified base.
      Returns:
      The principle value of the complex logarithm, with specified base, for the given input.
    • log

      public static Complex128 log(Complex128 base, Complex128 num)
      Computes the complex logarithm, with specified base, of a complex number.
      Parameters:
      base - Base of the logarithm.
      num - Input to the complex logarithm function with specified base.
      Returns:
      The principle value of the complex logarithm, with specified base, for the given input.
    • sqrt

      public static Complex128 sqrt(double num)
      Computes the principle square root of a number. This method wraps Math.sqrt(double) and returns a Complex128.
      Parameters:
      num - Input to square root.
      Returns:
      The principle square root of num.
    • toPolar

      public double[] toPolar()
      Converts a complex number to an equivalent polar from.
      Returns:
      An array of length 2 containing in order, the radius and angle (in radians) if the complex number.
    • fromPolar

      public static Complex128 fromPolar(double r, double theta)
      Converts a complex number expressed in polar from to the rectangular form.
      Parameters:
      r - Radius of complex number.
      theta - Angle of the complex number in radians.
      Returns:
      An equivalent complex number in rectangular form.
    • atan2

      public static double atan2(Complex128 num)
      Computes the 2 argument arc-tangent function for a complex number. That is, for a complex number a+bi, atan2(b, a) is computed. This method wraps Math.atan2(double, double).
      Parameters:
      num - The input to the atan2 function.
      Returns:
      The output of the atan2 function given the specified input. If the complex number is zero, then Double.NaN is returned.
    • arg

      public static double arg(Complex128 num)
      Computes the complex argument function for a complex number. is computed. This method is equivalent to atan2(Complex128).
      Parameters:
      num - The input to the atan2 function.
      Returns:
      The output of the atan2 function given the specified input. If the complex number is zero, then Double.NaN is returned.
    • sin

      public static Complex128 sin(Complex128 num)
      Computes the trigonometric sine of a complex value.
      Parameters:
      num - Complex valued input to the sine function. If num is real, then this is an angle in radians.
      Returns:
      The trigonometric sine function evaluated at the specified value.
    • asin

      public static Complex128 asin(Complex128 num)
      Computes the inverse sine of a complex value.
      Parameters:
      num - Input to the inverse sine function.
      Returns:
      The inverse sine of the input value.
    • sinh

      public static Complex128 sinh(Complex128 num)
      Computes the hyperbolic sine of a complex value.
      Parameters:
      num - Input to the hyperbolic sine function.
      Returns:
      The hyperbolic sine of the input value.
    • cos

      public static Complex128 cos(Complex128 num)
      Computes the trigonometric cosine value of a complex value.
      Parameters:
      num - Complex valued input to the cosine function. If num is real, then this is an angle in radians.
      Returns:
      The trigonometric cosine function evaluated at the specified value.
    • acos

      public static Complex128 acos(Complex128 num)
      Computes the inverse cosine of a complex value.
      Parameters:
      num - Input to the inverse cosine function.
      Returns:
      The inverse cosine of the input value.
    • cosh

      public static Complex128 cosh(Complex128 num)
      Computes the hyperbolic cosine of a complex value.
      Parameters:
      num - Input to the hyperbolic cosine function.
      Returns:
      The hyperbolic cosine of the input value.
    • tan

      public static Complex128 tan(Complex128 num)
      Computes the trigonometric tangent value of a complex value.
      Parameters:
      num - Complex valued input to the tangent function. If num is real, then this is an angle in radians.
      Returns:
      The trigonometric tangent function evaluated at the specified value.
    • atan

      public static Complex128 atan(Complex128 num)
      Computes the inverse tangent of a complex value.
      Parameters:
      num - Input to the inverse tangent function.
      Returns:
      The inverse tangent of the input value.
    • tanh

      public static Complex128 tanh(Complex128 num)
      Computes the hyperbolic tangent of a complex value.
      Parameters:
      num - Input to the hyperbolic tangent function.
      Returns:
      The hyperbolic tangent of the input value.
    • sgn

      public static Complex128 sgn(Complex128 value)
      The complex signum function. Please note, if the value passed to this method is zero, the function will return zero.
      Parameters:
      value - Value to evaluate the signum function at.
      Returns:
      If the number is zero then this function returns zero. Otherwise, returns the number divided by its magnitude.
    • round

      public static Complex128 round(Complex128 n)
      Rounds both components of a complex number to the nearest respective integer.
      Parameters:
      n - The complex number to round.
      Returns:
      A complex number with integer real and imaginary components closest to the real and imaginary components of the parameter n
      Throws:
      NumberFormatException - If n is Double.NaN, Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY
      See Also:
    • round

      public static Complex128 round(Complex128 n, int decimals)
      Rounds number to specified number of decimal places. If the number is complex, both the real and imaginary parts will be rounded.
      Parameters:
      n - Number to round.
      decimals - Number of decimals to round to.
      Returns:
      The number rounded to the specified number of decimals.
      Throws:
      IllegalArgumentException - If decimals is less than zero.
      NumberFormatException - If n is Double.NaN, Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY
      See Also:
    • roundToZero

      public static Complex128 roundToZero(Complex128 n, double tol)
      Rounds a complex numbers to zero if its magnitude within the specified tolerance from zero.
      Parameters:
      n - Number to round.
      tol - Max distances in complex plane for which number should be rounded to zero.
      Returns:
      The
    • nearZero

      public static boolean nearZero(Complex128 n, double tol)
      Checks if a number is near zero in magnitude.
      Parameters:
      n - Number to round.
      tol - Tolerance of how close to zero is considered "near".
      Returns:
      Returns true if magnitude of number is less than or equal to tol; false otherwise.
      Throws:
      IllegalArgumentException - If tol is less than 0.
    • compareTo

      public int compareTo(Complex128 b)
      Compares this element of the field with b.
      Specified by:
      compareTo in interface Comparable<Complex128>
      Specified by:
      compareTo in interface Semiring<Complex128>
      Parameters:
      b - Second element of the field.
      Returns:
      An int value:
      • 0 if this field element is equal to b in magnitude.
      • invalid input: '<' 0 if this field element is less than b in magnitude.
      • > 0 if this field element is greater than b in magnitude.
      • Hence, this method returns zero if and only if the two field elements are equal in magnitude, a negative value if and only the field element it was called on is less than b in magnitude and positive if and only if the field element it was called on is greater than b in magnitude.
    • doubleValue

      public double doubleValue()
      Converts this complex number to an equivalent double. This will be the magnitude of the complex number.
      Specified by:
      doubleValue in interface Semiring<Complex128>
      Returns:
      A double value equivalent to this complex number. This will be the magnitude of the complex number.
    • min

      public static Complex128 min(Complex128... values)
      Computes the minimum magnitude from an array of complex numbers.
      Parameters:
      values - Array of values to compute the minimum magnitude from.
      Returns:
      The minimum magnitude from the values array. If the array has zero length, thennull is returned.
    • minRe

      public static Complex128 minRe(Complex128... values)
      Computes the minimum real component from an array of complex numbers. All imaginary components are ignored.
      Parameters:
      values - Array of values to compute the minimum real component from.
      Returns:
      The minimum magnitude from the values array. If the array has zero length, Double.NaN is returned.
    • max

      public static Complex128 max(Complex128... values)
      Computes the maximum magnitude from an array of complex numbers.
      Parameters:
      values - Array of values to compute the maximum magnitude from.
      Returns:
      The minimum magnitude from the values array. If the array has zero length, then -1 is returned.
    • maxRe

      public static Complex128 maxRe(Complex128... values)
      Computes the minimum real component from an array of complex numbers. All imaginary components are ignored.
      Parameters:
      values - Array of values to compute the minimum real component from.
      Returns:
      The minimum magnitude from the values array. If the array has zero length, Double.NaN is returned.
    • argmin

      public static int argmin(Complex128... values)
      Computes the index of the minimum magnitude from an array of complex numbers.
      Parameters:
      values - Array of values to compute the index of the minimum magnitude from.
      Returns:
      The index of the minimum magnitude from the values array. If the array has zero length, then -1 is returned.
    • argminReal

      public static int argminReal(Complex128... values)
      Computes the index of the minimum real component from an array of complex numbers. All imaginary components are ignored.
      Parameters:
      values - Array of values to compute the index of the minimum real component from.
      Returns:
      The index of the minimum magnitude from the values array. If the array has zero length, -1 is returned.
    • argmax

      public static int argmax(Complex128... values)
      Computes the index of the maximum magnitude from an array of complex numbers.
      Parameters:
      values - Array of values to compute the index of the maximum magnitude from.
      Returns:
      The index of the minimum magnitude from the values array. If the array has zero length, then -1 is returned.
    • argmaxReal

      public static int argmaxReal(Complex128... values)
      Computes the index of the minimum real component from an array of complex numbers. All imaginary components are ignored.
      Parameters:
      values - Array of values to compute the index of the minimum real component from.
      Returns:
      The index of the minimum magnitude from the values array. If the array has zero length, -1 is returned.
    • isInt

      public boolean isInt()
      Checks if this complex number is a real valued integer.
      Returns:
      true if the real component of this number is an integer and the complex component is zero; false otherwise.
    • isDouble

      public boolean isDouble()
      Checks if this complex number is a real valued double.
      Returns:
      true if the complex component is zero; false otherwise.
    • isFinite

      public boolean isFinite()

      Checks if this field element is finite in magnitude.

      NOTE: It may be possible for this method to return true and mag() to return Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, or Double.NaN if both components are finite but computing the magnitude explicitly results in an overflow.

      Specified by:
      isFinite in interface Field<Complex128>
      Returns:
      True if this field element is finite in magnitude. False otherwise (i.e. infinite, NaN etc.).
    • isInfinite

      public boolean isInfinite()
      Checks if this field element is infinite in magnitude.
      Specified by:
      isInfinite in interface Field<Complex128>
      Returns:
      True if this field element is infinite in magnitude. False otherwise (i.e. finite, NaN, etc.).
    • isNaN

      public boolean isNaN()
      Checks if this field element is NaN in magnitude.
      Specified by:
      isNaN in interface Field<Complex128>
      Returns:
      True if this field element is NaN in magnitude. False otherwise (i.e. finite, NaN, etc.).
    • re

      public double re()
      Gets the real component of this complex number.
      Returns:
      The real component of this complex number.
    • im

      public double im()
      Gets the imaginary component of this complex number.
      Returns:
      The imaginary component of this complex number.
    • length

      public static int length(Complex128 a)
      Gets the length of the string representation of this complex number.
      Parameters:
      a - Complex number.
      Returns:
      The length of the string representation of the number.
    • toString

      public String toString()
      Converts the complex number to a string representation.
      Overrides:
      toString in class Object
      Returns:
      A string representation of the complex number.