Class ImmutableComplex

  • All Implemented Interfaces:
    java.io.Serializable

    public class ImmutableComplex
    extends Complex.NonPropagatingImmutableComplex
    An Immutable version of the Complex numbers. In this class the values of complex numbers can never be changed, further any operation like conj() or add(Complex) will also return an ImmutableComplex.
    Since:
    Jep 4.0
    See Also:
    Serialized Form
    • Field Detail

      • U_ZERO

        public static final Complex U_ZERO
        Unmodifiable constant 0+0 i
      • U_ONE

        public static final Complex U_ONE
        Unmodifiable constant 1+0 i
      • U_MINUS_ONE

        public static final Complex U_MINUS_ONE
        Unmodifiable constant -1+0 i
      • U_I

        public static final Complex U_I
        Unmodifiable constant 0+1 i
      • U_MINUS_I

        public static final Complex U_MINUS_I
        Unmodifiable constant 0-1 i
    • Constructor Detail

      • ImmutableComplex

        public ImmutableComplex()
      • ImmutableComplex

        public ImmutableComplex​(Complex z)
      • ImmutableComplex

        public ImmutableComplex​(double x,
                                double y)
      • ImmutableComplex

        public ImmutableComplex​(double x)
      • ImmutableComplex

        public ImmutableComplex​(java.lang.Number x)
    • Method Detail

      • polarValueOf

        public static ImmutableComplex polarValueOf​(java.lang.Number r,
                                                    java.lang.Number theta)
      • neg

        public ImmutableComplex neg()
        Description copied from class: Complex
        Returns the negative value of this complex number.
        Overrides:
        neg in class Complex
        Returns:
        -(x+i y)
      • mul

        public ImmutableComplex mul​(double b)
        Description copied from class: Complex
        Multiply the complex number with a double value.
        Overrides:
        mul in class Complex
        Parameters:
        b - real number to multiply by
        Returns:
        The result of the multiplication
      • add

        public ImmutableComplex add​(Complex z)
        Description copied from class: Complex
        Adds the complex number with another complex value.
        Overrides:
        add in class Complex
        Parameters:
        z - complex number to add
        Returns:
        The result of the addition
      • sub

        public ImmutableComplex sub​(Complex z)
        Description copied from class: Complex
        Subtracts a complex number from this
        Overrides:
        sub in class Complex
        Parameters:
        z - complex number to subtract
        Returns:
        (this) - z
      • mul

        public ImmutableComplex mul​(Complex z)
        Description copied from class: Complex
        Multiply the complex number with another complex value.
        Overrides:
        mul in class Complex
        Parameters:
        z - complex number to multiply
        Returns:
        The result of the multiplication
      • div

        public ImmutableComplex div​(Complex z)
        Description copied from class: Complex
        Returns the result of dividing this complex number by the parameter. Algorithm adapted from Numerical Recipes in C - The Art of Scientific Computing ISBN 0-521-43108-5
        Overrides:
        div in class Complex
        Parameters:
        z - complex number to divide by
        Returns:
        (this)/z
      • reciprocal

        public ImmutableComplex reciprocal()
        Description copied from class: Complex
        Returns the reciprocal of a complex number 1/z. This was broken in version < 4.0.
        Overrides:
        reciprocal in class Complex
        Returns:
        1/(this)
      • power

        public ImmutableComplex power​(int n)
        Description copied from class: Complex
        Raise this complex to an integer power. For small power use the Complex.fastPower(int) method which does repeated multiplication and is generally faster. For larger power use Complex.powerI(int) which can be more accurate.
        Overrides:
        power in class Complex
        Parameters:
        n - the power
        Returns:
        (this)^n
      • fastPower

        public ImmutableComplex fastPower​(int n)
        Description copied from class: Complex
        Calculate integer powers by repeated multiplications. So z^5 = z*(z*z)*(z*z). This routine is generally faster but can accumulate errors for large exponents.
        Overrides:
        fastPower in class Complex
        Returns:
      • powerD

        public ImmutableComplex powerD​(double exponent)
        Description copied from class: Complex
        Returns the value of this complex number raised to the power of a real component (in double precision).

        This method considers special cases where a simpler algorithm would return "ugly" results.
        For example when the expression (-1e40)^0.5 is evaluated without considering the special case, the argument of the base is the double number closest to pi. When sin and cos are used for the final evaluation of the result, the slight difference of the argument from pi causes a non-zero value for the real component of the result. Because the value of the base is so high, the error is magnified. Although the error is normal for floating point calculations, the consideration of commonly occurring special cases improves the accuracy and aesthetics of the results.

        If you know a more elegant way to solve this problem, please let me know at [email protected] .

        Testing with roots of unity show errors are typically within 128 * ulp, so |actual-result|/|actual| < 1e-13.

        Overrides:
        powerD in class Complex
        Parameters:
        exponent - exponent
        Returns:
        (this)^exponent
      • power

        public ImmutableComplex power​(Complex exponent)
        Description copied from class: Complex
        Returns the value of this complex number raised to the power of a complex exponent If the this is zero return this. If the exponent has zero imaginary part use
        Overrides:
        power in class Complex
        Parameters:
        exponent - exponent
        Returns:
        (this)^exponent
      • log

        public ImmutableComplex log()
        Description copied from class: Complex
        Returns the logarithm of this complex number. The real part is Math.log(this.abs()) and the complex part is this.arg(), in the range -pi .. pi.
        Overrides:
        log in class Complex
        Returns:
        ln(z) = ln(r) + i th
      • sqrt

        public ImmutableComplex sqrt()
        Description copied from class: Complex
        Calculates the square root of this object. Adapted from Numerical Recipes in C - The Art of Scientific Computing (ISBN 0-521-43108-5)
        Overrides:
        sqrt in class Complex
        Returns:
        sqrt(z)
      • sin

        public ImmutableComplex sin()
        Description copied from class: Complex
        Returns the sine of this complex number.
        Overrides:
        sin in class Complex
        Returns:
        sin(this)
      • cos

        public ImmutableComplex cos()
        Description copied from class: Complex
        Returns the cosine of this complex number.
        Overrides:
        cos in class Complex
        Returns:
        cos(this)
      • tan

        public ImmutableComplex tan()
        Description copied from class: Complex
        Returns the tangent of this complex number.
        Overrides:
        tan in class Complex
        Returns:
        tan(this)
      • asin

        public ImmutableComplex asin()
        Description copied from class: Complex
        Returns the arcsin of this complex number.
        Overrides:
        asin in class Complex
        Returns:
        asin(this)
      • acos

        public ImmutableComplex acos()
        Description copied from class: Complex
        Returns the arccos of this complex number.
        Overrides:
        acos in class Complex
        Returns:
        acos(this)
      • atan

        public ImmutableComplex atan()
        Description copied from class: Complex
        Returns the arc tangent of this complex number.
        Overrides:
        atan in class Complex
        Returns:
        atan(this)
      • sinh

        public ImmutableComplex sinh()
        Description copied from class: Complex
        Returns the hyperbolic sine of this complex number.
        Overrides:
        sinh in class Complex
        Returns:
        sinh(this)
      • cosh

        public ImmutableComplex cosh()
        Description copied from class: Complex
        Returns the hyperbolic cosine of this complex number.
        Overrides:
        cosh in class Complex
        Returns:
        cosh(this)
      • tanh

        public ImmutableComplex tanh()
        Description copied from class: Complex
        Returns the hyperbolic tangent of this complex number.
        Overrides:
        tanh in class Complex
        Returns:
        tanh(this)
      • asinh

        public ImmutableComplex asinh()
        Description copied from class: Complex
        Returns the inverse hyperbolic sine of this complex number.
        Overrides:
        asinh in class Complex
        Returns:
        asinh(this)
      • acosh

        public ImmutableComplex acosh()
        Description copied from class: Complex
        Returns the inverse hyperbolic cosine of this complex number.
        Overrides:
        acosh in class Complex
        Returns:
        acosh(this)
      • atanh

        public ImmutableComplex atanh()
        Description copied from class: Complex
        Returns the inverse hyperbolic tangent of this complex number.
        Overrides:
        atanh in class Complex
        Returns:
        atanh(this)