Package smile.math

Record Class Complex

Record Components:
re - the real part.
im - the imaginary part.
All Implemented Interfaces:
Serializable

public record Complex(double re, double im) extends Record implements Serializable
Complex number. The object is immutable so once you create and initialize a Complex object, you cannot modify it.
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Packed array of complex numbers for better memory efficiency.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Complex(double re, double im)
    Creates an instance of a Complex record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    abs()
    Returns the abs/modulus/magnitude.
    Returns this + b.
    Returns the conjugate.
    cos()
    Returns the complex cosine.
    Returns a / b.
    final boolean
    Indicates whether some other object is "equal to" this one.
    exp()
    Returns the complex exponential.
    final int
    Returns a hash code value for this object.
    double
    im()
    Returns the value of the im record component.
    Returns this * b.
    static Complex
    of(double real)
    Returns a Complex instance representing the specified value.
    static Complex
    of(double real, double imag)
    Returns a Complex instance representing the specified value.
    double
    Returns the angle/phase/argument between -pi and pi.
    double
    re()
    Returns the value of the re record component.
    Returns the reciprocal.
    scale(double b)
    Scalar multiplication.
    sin()
    Returns the complex sine.
    Returns this - b.
    tan()
    Returns the complex tangent.
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

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

    • Complex

      public Complex(double re, double im)
      Creates an instance of a Complex record class.
      Parameters:
      re - the value for the re record component
      im - the value for the im record component
  • Method Details

    • of

      public static Complex of(double real)
      Returns a Complex instance representing the specified value.
      Parameters:
      real - the real part.
      Returns:
      the complex object.
    • of

      public static Complex of(double real, double imag)
      Returns a Complex instance representing the specified value.
      Parameters:
      real - the real part.
      imag - the imaginary part.
      Returns:
      the complex object.
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • add

      public Complex add(Complex b)
      Returns this + b.
      Parameters:
      b - the operand.
      Returns:
      the result.
    • sub

      public Complex sub(Complex b)
      Returns this - b.
      Parameters:
      b - the operand.
      Returns:
      the result.
    • mul

      public Complex mul(Complex b)
      Returns this * b.
      Parameters:
      b - the operand.
      Returns:
      the result.
    • scale

      public Complex scale(double b)
      Scalar multiplication.
      Parameters:
      b - the operand.
      Returns:
      the result.
    • div

      public Complex div(Complex b)
      Returns a / b.
      Parameters:
      b - the operand.
      Returns:
      the result.
    • abs

      public double abs()
      Returns the abs/modulus/magnitude.
      Returns:
      the modulus.
    • phase

      public double phase()
      Returns the angle/phase/argument between -pi and pi.
      Returns:
      the phase between -pi and pi.
    • conjugate

      public Complex conjugate()
      Returns the conjugate.
      Returns:
      the conjugate.
    • reciprocal

      public Complex reciprocal()
      Returns the reciprocal.
      Returns:
      the reciprocal.
    • exp

      public Complex exp()
      Returns the complex exponential.
      Returns:
      the complex exponential.
    • sin

      public Complex sin()
      Returns the complex sine.
      Returns:
      the complex sine.
    • cos

      public Complex cos()
      Returns the complex cosine.
      Returns:
      the complex cosine.
    • tan

      public Complex tan()
      Returns the complex tangent.
      Returns:
      the complex tangent.
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • re

      public double re()
      Returns the value of the re record component.
      Returns:
      the value of the re record component
    • im

      public double im()
      Returns the value of the im record component.
      Returns:
      the value of the im record component