Class Complex

    • Field Detail

      • I

        public static final Complex I
        The square root of -1. A number representing "0.0 + 1.0i".
      • MINUS_I

        public static final Complex MINUS_I
        The square root of -1. A number representing "0.0 - 1.0i".
        Since:
        1.7
      • NaN

        public static final Complex NaN
        A complex number representing "NaN + NaNi".
      • INF

        public static final Complex INF
        A complex number representing "+INF + INFi"
      • ONE

        public static final Complex ONE
        A complex number representing "1.0 + 0.0i".
      • MINUS_ONE

        public static final Complex MINUS_ONE
        A complex number representing "-1.0 + 0.0i".
        Since:
        1.7
      • ZERO

        public static final Complex ZERO
        A complex number representing "0.0 + 0.0i".
      • PI

        public static final Complex PI
        A complex number representing "π + 0.0i".
    • Constructor Detail

      • Complex

        public Complex​(double real)
        Create a complex number given only the real part.
        Parameters:
        real - Real part.
      • Complex

        public Complex​(double real,
                       double imaginary)
        Create a complex number given the real and imaginary parts.
        Parameters:
        real - Real part.
        imaginary - Imaginary part.
    • Method Detail

      • abs

        public Complex abs()
        Return the absolute value of this complex number. Returns NaN if either real or imaginary part is NaN and Double.POSITIVE_INFINITY if neither part is NaN, but at least one part is infinite.
        Specified by:
        abs in interface CalculusFieldElement<Complex>
        Returns:
        the norm.
        Since:
        2.0
      • add

        public Complex add​(Complex addend)
                    throws NullArgumentException
        Returns a Complex whose value is (this + addend). Uses the definitional formula

        (a + bi) + (c + di) = (a+c) + (b+d)i

        If either this or addend has a NaN value in either part, NaN is returned; otherwise Infinite and NaN values are returned in the parts of the result according to the rules for Double arithmetic.
        Specified by:
        add in interface FieldElement<Complex>
        Parameters:
        addend - Value to be added to this Complex.
        Returns:
        this + addend.
        Throws:
        NullArgumentException - if addend is null.
      • add

        public Complex add​(double addend)
        Returns a Complex whose value is (this + addend), with addend interpreted as a real number.
        Specified by:
        add in interface CalculusFieldElement<Complex>
        Parameters:
        addend - Value to be added to this Complex.
        Returns:
        this + addend.
        See Also:
        add(Complex)
      • conjugate

        public Complex conjugate()
        Returns the conjugate of this complex number. The conjugate of a + bi is a - bi.

        NaN is returned if either the real or imaginary part of this Complex number equals Double.NaN.

        If the imaginary part is infinite, and the real part is not NaN, the returned value has infinite imaginary part of the opposite sign, e.g. the conjugate of 1 + POSITIVE_INFINITY i is 1 - NEGATIVE_INFINITY i.

        Returns:
        the conjugate of this Complex object.
      • divide

        public Complex divide​(Complex divisor)
                       throws NullArgumentException
        Returns a Complex whose value is (this / divisor). Implements the definitional formula
          
            a + bi          ac + bd + (bc - ad)i
            ----------- = -------------------------
            c + di         c2 + d2
          
         
        but uses prescaling of operands to limit the effects of overflows and underflows in the computation.

        Infinite and NaN values are handled according to the following rules, applied in the order presented:

        • If either this or divisor has a NaN value in either part, NaN is returned.
        • If divisor equals ZERO, NaN is returned.
        • If this and divisor are both infinite, NaN is returned.
        • If this is finite (i.e., has no Infinite or NaN parts) and divisor is infinite (one or both parts infinite), ZERO is returned.
        • If this is infinite and divisor is finite, NaN values are returned in the parts of the result if the Double rules applied to the definitional formula force NaN results.
        Specified by:
        divide in interface FieldElement<Complex>
        Parameters:
        divisor - Value by which this Complex is to be divided.
        Returns:
        this / divisor.
        Throws:
        NullArgumentException - if divisor is null.
      • divide

        public Complex divide​(double divisor)
        Returns a Complex whose value is (this / divisor), with divisor interpreted as a real number.
        Specified by:
        divide in interface CalculusFieldElement<Complex>
        Parameters:
        divisor - Value by which this Complex is to be divided.
        Returns:
        this / divisor.
        See Also:
        divide(Complex)
      • equals

        public boolean equals​(Object other)
        Test for equality with another object. If both the real and imaginary parts of two complex numbers are exactly the same, and neither is Double.NaN, the two Complex objects are considered to be equal. The behavior is the same as for JDK's Double:
        • All NaN values are considered to be equal, i.e, if either (or both) real and imaginary parts of the complex number are equal to Double.NaN, the complex number is equal to NaN.
        • Instances constructed with different representations of zero (i.e. either "0" or "-0") are not considered to be equal.
        Overrides:
        equals in class Object
        Parameters:
        other - Object to test for equality with this instance.
        Returns:
        true if the objects are equal, false if object is null, not an instance of Complex, or not equal to this instance.
      • equals

        public static boolean equals​(Complex x,
                                     Complex y,
                                     int maxUlps)
        Test for the floating-point equality between Complex objects. It returns true if both arguments are equal or within the range of allowed error (inclusive).
        Parameters:
        x - First value (cannot be null).
        y - Second value (cannot be null).
        maxUlps - (maxUlps - 1) is the number of floating point values between the real (resp. imaginary) parts of x and y.
        Returns:
        true if there are fewer than maxUlps floating point values between the real (resp. imaginary) parts of x and y.
        See Also:
        Precision.equals(double,double,int)
      • equals

        public static boolean equals​(Complex x,
                                     Complex y)
        Returns true iff the values are equal as defined by equals(x, y, 1).
        Parameters:
        x - First value (cannot be null).
        y - Second value (cannot be null).
        Returns:
        true if the values are equal.
      • equals

        public static boolean equals​(Complex x,
                                     Complex y,
                                     double eps)
        Returns true if, both for the real part and for the imaginary part, there is no double value strictly between the arguments or the difference between them is within the range of allowed error (inclusive). Returns false if either of the arguments is NaN.
        Parameters:
        x - First value (cannot be null).
        y - Second value (cannot be null).
        eps - Amount of allowed absolute error.
        Returns:
        true if the values are two adjacent floating point numbers or they are within range of each other.
        See Also:
        Precision.equals(double,double,double)
      • equalsWithRelativeTolerance

        public static boolean equalsWithRelativeTolerance​(Complex x,
                                                          Complex y,
                                                          double eps)
        Returns true if, both for the real part and for the imaginary part, there is no double value strictly between the arguments or the relative difference between them is smaller or equal to the given tolerance. Returns false if either of the arguments is NaN.
        Parameters:
        x - First value (cannot be null).
        y - Second value (cannot be null).
        eps - Amount of allowed relative error.
        Returns:
        true if the values are two adjacent floating point numbers or they are within range of each other.
        See Also:
        Precision.equalsWithRelativeTolerance(double,double,double)
      • hashCode

        public int hashCode()
        Get a hashCode for the complex number. Any Double.NaN value in real or imaginary part produces the same hash code 7.
        Overrides:
        hashCode in class Object
        Returns:
        a hash code value for this object.
      • isZero

        public boolean isZero()
        Check if an element is semantically equal to zero.

        The default implementation simply calls equals(getField().getZero()). However, this may need to be overridden in some cases as due to compatibility with hashCode() some classes implements equals(Object) in such a way that -0.0 and +0.0 are different, which may be a problem. It prevents for example identifying a diagonal element is zero and should be avoided when doing partial pivoting in LU decomposition.

        This implementation considers +0.0 and -0.0 to be equal for both real and imaginary components.

        Specified by:
        isZero in interface FieldElement<Complex>
        Returns:
        true if the element is semantically equal to zero
        Since:
        1.8
      • getImaginary

        public double getImaginary()
        Access the imaginary part.
        Returns:
        the imaginary part.
      • getImaginaryPart

        public double getImaginaryPart()
        Access the imaginary part.
        Returns:
        the imaginary part.
        Since:
        2.0
      • getReal

        public double getReal()
        Access the real part.
        Specified by:
        getReal in interface FieldElement<Complex>
        Returns:
        the real part.
      • getRealPart

        public double getRealPart()
        Access the real part.
        Returns:
        the real part.
        Since:
        2.0
      • isNaN

        public boolean isNaN()
        Checks whether either or both parts of this complex number is NaN.
        Specified by:
        isNaN in interface CalculusFieldElement<Complex>
        Returns:
        true if either or both parts of this complex number is NaN; false otherwise.
      • isReal

        public boolean isReal()
        Check whether the instance is real (i.e. imaginary part is zero).
        Returns:
        true if imaginary part is zero
        Since:
        1.7
      • isMathematicalInteger

        public boolean isMathematicalInteger()
        Check whether the instance is an integer (i.e. imaginary part is zero and real part has no fractional part).
        Returns:
        true if imaginary part is zero and real part has no fractional part
        Since:
        1.7
      • isInfinite

        public boolean isInfinite()
        Checks whether either the real or imaginary part of this complex number takes an infinite value (either Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY) and neither part is NaN.
        Specified by:
        isInfinite in interface CalculusFieldElement<Complex>
        Returns:
        true if one or both parts of this complex number are infinite and neither part is NaN.
      • multiply

        public Complex multiply​(Complex factor)
                         throws NullArgumentException
        Returns a Complex whose value is this * factor. Implements preliminary checks for NaN and infinity followed by the definitional formula:

        (a + bi)(c + di) = (ac - bd) + (ad + bc)i

        Returns NaN if either this or factor has one or more NaN parts.

        Returns INF if neither this nor factor has one or more NaN parts and if either this or factor has one or more infinite parts (same result is returned regardless of the sign of the components).

        Returns finite values in components of the result per the definitional formula in all remaining cases.

        Specified by:
        multiply in interface FieldElement<Complex>
        Parameters:
        factor - value to be multiplied by this Complex.
        Returns:
        this * factor.
        Throws:
        NullArgumentException - if factor is null.
      • multiply

        public Complex multiply​(int factor)
        Returns a Complex whose value is this * factor, with factor interpreted as a integer number.
        Specified by:
        multiply in interface FieldElement<Complex>
        Parameters:
        factor - value to be multiplied by this Complex.
        Returns:
        this * factor.
        See Also:
        multiply(Complex)
      • multiply

        public Complex multiply​(double factor)
        Returns a Complex whose value is this * factor, with factor interpreted as a real number.
        Specified by:
        multiply in interface CalculusFieldElement<Complex>
        Parameters:
        factor - value to be multiplied by this Complex.
        Returns:
        this * factor.
        See Also:
        multiply(Complex)
      • multiplyPlusI

        public Complex multiplyPlusI()
        Compute this * i.
        Returns:
        this * i
        Since:
        2.0
      • multiplyMinusI

        public Complex multiplyMinusI()
        Compute this *- -i.
        Returns:
        this * i
        Since:
        2.0
      • negate

        public Complex negate()
        Returns a Complex whose value is (-this). Returns NaN if either real or imaginary part of this Complex number is Double.NaN.
        Specified by:
        negate in interface FieldElement<Complex>
        Returns:
        -this.
      • subtract

        public Complex subtract​(Complex subtrahend)
                         throws NullArgumentException
        Returns a Complex whose value is (this - subtrahend). Uses the definitional formula

        (a + bi) - (c + di) = (a-c) + (b-d)i

        If either this or subtrahend has a NaN] value in either part, NaN is returned; otherwise infinite and NaN values are returned in the parts of the result according to the rules for Double arithmetic.
        Specified by:
        subtract in interface FieldElement<Complex>
        Parameters:
        subtrahend - value to be subtracted from this Complex.
        Returns:
        this - subtrahend.
        Throws:
        NullArgumentException - if subtrahend is null.
      • subtract

        public Complex subtract​(double subtrahend)
        Returns a Complex whose value is (this - subtrahend).
        Specified by:
        subtract in interface CalculusFieldElement<Complex>
        Parameters:
        subtrahend - value to be subtracted from this Complex.
        Returns:
        this - subtrahend.
        See Also:
        subtract(Complex)
      • acos

        public Complex acos()
        Compute the inverse cosine of this complex number. Implements the formula:

        acos(z) = -i (log(z + i (sqrt(1 - z<sup>2</sup>))))

        Returns NaN if either real or imaginary part of the input argument is NaN or infinite.
        Specified by:
        acos in interface CalculusFieldElement<Complex>
        Returns:
        the inverse cosine of this complex number.
      • asin

        public Complex asin()
        Compute the inverse sine of this complex number. Implements the formula:

        asin(z) = -i (log(sqrt(1 - z<sup>2</sup>) + iz))

        Returns NaN if either real or imaginary part of the input argument is NaN or infinite.

        Specified by:
        asin in interface CalculusFieldElement<Complex>
        Returns:
        the inverse sine of this complex number.
      • atan

        public Complex atan()
        Compute the inverse tangent of this complex number. Implements the formula:

        atan(z) = (i/2) log((1 - iz)/(1 + iz))

        Returns NaN if either real or imaginary part of the input argument is NaN or infinite.

        Specified by:
        atan in interface CalculusFieldElement<Complex>
        Returns:
        the inverse tangent of this complex number
      • cos

        public Complex cos()
        Compute the cosine of this complex number. Implements the formula:

        cos(a + bi) = cos(a)cosh(b) - sin(a)sinh(b)i

        where the (real) functions on the right-hand side are FastMath.sin(double), FastMath.cos(double), FastMath.cosh(double) and FastMath.sinh(double).

        Returns NaN if either real or imaginary part of the input argument is NaN.

        Infinite values in real or imaginary parts of the input may result in infinite or NaN values returned in parts of the result.

          Examples:
          
           cos(1 ± INFINITY i) = 1 ∓ INFINITY i
           cos(±INFINITY + i) = NaN + NaN i
           cos(±INFINITY ± INFINITY i) = NaN + NaN i
          
         
        Specified by:
        cos in interface CalculusFieldElement<Complex>
        Returns:
        the cosine of this complex number.
      • cosh

        public Complex cosh()
        Compute the hyperbolic cosine of this complex number. Implements the formula:
          
           cosh(a + bi) = cosh(a)cos(b) + sinh(a)sin(b)i
          
         
        where the (real) functions on the right-hand side are FastMath.sin(double), FastMath.cos(double), FastMath.cosh(double) and FastMath.sinh(double).

        Returns NaN if either real or imaginary part of the input argument is NaN.

        Infinite values in real or imaginary parts of the input may result in infinite or NaN values returned in parts of the result.
          Examples:
          
           cosh(1 ± INFINITY i) = NaN + NaN i
           cosh(±INFINITY + i) = INFINITY ± INFINITY i
           cosh(±INFINITY ± INFINITY i) = NaN + NaN i
          
         
        Specified by:
        cosh in interface CalculusFieldElement<Complex>
        Returns:
        the hyperbolic cosine of this complex number.
      • exp

        public Complex exp()
        Compute the exponential function of this complex number. Implements the formula:
          
           exp(a + bi) = exp(a)cos(b) + exp(a)sin(b)i
          
         
        where the (real) functions on the right-hand side are FastMath.exp(double), FastMath.cos(double), and FastMath.sin(double).

        Returns NaN if either real or imaginary part of the input argument is NaN.

        Infinite values in real or imaginary parts of the input may result in infinite or NaN values returned in parts of the result.
          Examples:
          
           exp(1 ± INFINITY i) = NaN + NaN i
           exp(INFINITY + i) = INFINITY + INFINITY i
           exp(-INFINITY + i) = 0 + 0i
           exp(±INFINITY ± INFINITY i) = NaN + NaN i
          
         
        Specified by:
        exp in interface CalculusFieldElement<Complex>
        Returns:
        ethis.
      • log

        public Complex log()
        Compute the natural logarithm of this complex number. Implements the formula:
          
           log(a + bi) = ln(|a + bi|) + arg(a + bi)i
          
         
        where ln on the right hand side is FastMath.log(double), |a + bi| is the modulus, abs(), and arg(a + bi) = FastMath.atan2(double, double)(b, a).

        Returns NaN if either real or imaginary part of the input argument is NaN.

        Infinite (or critical) values in real or imaginary parts of the input may result in infinite or NaN values returned in parts of the result.
          Examples:
          
           log(1 ± INFINITY i) = INFINITY ± (π/2)i
           log(INFINITY + i) = INFINITY + 0i
           log(-INFINITY + i) = INFINITY + πi
           log(INFINITY ± INFINITY i) = INFINITY ± (π/4)i
           log(-INFINITY ± INFINITY i) = INFINITY ± (3π/4)i
           log(0 + 0i) = -INFINITY + 0i
          
         
        Specified by:
        log in interface CalculusFieldElement<Complex>
        Returns:
        the value ln   this, the natural logarithm of this.
      • pow

        public Complex pow​(Complex x)
                    throws NullArgumentException
        Returns of value of this complex number raised to the power of x.

        If x is a real number whose real part has an integer value, returns pow(int), if both this and x are real and FastMath.pow(double, double) with the corresponding real arguments would return a finite number (neither NaN nor infinite), then returns the same value converted to Complex, with the same special cases. In all other cases real cases, implements yx = exp(x·log(y)).

        Specified by:
        pow in interface CalculusFieldElement<Complex>
        Parameters:
        x - exponent to which this Complex is to be raised.
        Returns:
        thisx.
        Throws:
        NullArgumentException - if x is null.
      • pow

        public Complex pow​(double x)
        Returns of value of this complex number raised to the power of x.

        If x has an integer value, returns pow(int), if this is real and FastMath.pow(double, double) with the corresponding real arguments would return a finite number (neither NaN nor infinite), then returns the same value converted to Complex, with the same special cases. In all other cases real cases, implements yx = exp(x·log(y)).

        Specified by:
        pow in interface CalculusFieldElement<Complex>
        Parameters:
        x - exponent to which this Complex is to be raised.
        Returns:
        thisx.
      • sin

        public Complex sin()
        Compute the sine of this complex number. Implements the formula:
          
           sin(a + bi) = sin(a)cosh(b) + cos(a)sinh(b)i
          
         
        where the (real) functions on the right-hand side are FastMath.sin(double), FastMath.cos(double), FastMath.cosh(double) and FastMath.sinh(double).

        Returns NaN if either real or imaginary part of the input argument is NaN.

        Infinite values in real or imaginary parts of the input may result in infinite or NaN values returned in parts of the result.

          Examples:
          
           sin(1 ± INFINITY i) = 1 ± INFINITY i
           sin(±INFINITY + i) = NaN + NaN i
           sin(±INFINITY ± INFINITY i) = NaN + NaN i
          
         
        Specified by:
        sin in interface CalculusFieldElement<Complex>
        Returns:
        the sine of this complex number.
      • atan2

        public Complex atan2​(Complex x)
        Two arguments arc tangent operation.

        Beware of the order or arguments! As this is based on a two-arguments functions, in order to be consistent with arguments order, the instance is the first argument and the single provided argument is the second argument. In order to be consistent with programming languages atan2, this method computes atan2(this, x), i.e. the instance represents the y argument and the x argument is the one passed as a single argument. This may seem confusing especially for users of Wolfram alpha, as this site is not consistent with programming languages atan2 two-arguments arc tangent and puts x as its first argument.

        Specified by:
        atan2 in interface CalculusFieldElement<Complex>
        Parameters:
        x - second argument of the arc tangent
        Returns:
        atan2(this, x)
        Since:
        1.7
      • acosh

        public Complex acosh()
        Inverse hyperbolic cosine operation.

        Branch cuts are on the real axis, below +1.

        Specified by:
        acosh in interface CalculusFieldElement<Complex>
        Returns:
        acosh(this)
        Since:
        1.7
      • asinh

        public Complex asinh()
        Inverse hyperbolic sine operation.

        Branch cuts are on the imaginary axis, above +i and below -i.

        Specified by:
        asinh in interface CalculusFieldElement<Complex>
        Returns:
        asin(this)
        Since:
        1.7
      • atanh

        public Complex atanh()
        Inverse hyperbolic tangent operation.

        Branch cuts are on the real axis, above +1 and below -1.

        Specified by:
        atanh in interface CalculusFieldElement<Complex>
        Returns:
        atanh(this)
        Since:
        1.7
      • sinh

        public Complex sinh()
        Compute the hyperbolic sine of this complex number. Implements the formula:
          
           sinh(a + bi) = sinh(a)cos(b)) + cosh(a)sin(b)i
          
         
        where the (real) functions on the right-hand side are FastMath.sin(double), FastMath.cos(double), FastMath.cosh(double) and FastMath.sinh(double).

        Returns NaN if either real or imaginary part of the input argument is NaN.

        Infinite values in real or imaginary parts of the input may result in infinite or NaN values returned in parts of the result.

          Examples:
          
           sinh(1 ± INFINITY i) = NaN + NaN i
           sinh(±INFINITY + i) = ± INFINITY + INFINITY i
           sinh(±INFINITY ± INFINITY i) = NaN + NaN i
          
         
        Specified by:
        sinh in interface CalculusFieldElement<Complex>
        Returns:
        the hyperbolic sine of this.
      • sqrt

        public Complex sqrt()
        Compute the square root of this complex number. Implements the following algorithm to compute sqrt(a + bi):
        1. Let t = sqrt((|a| + |a + bi|) / 2)
        2. if  a ≥ 0 return t + (b/2t)i
            else return |b|/2t + sign(b)t i 
        where The real part is therefore always nonnegative.

        Returns NaN if either real or imaginary part of the input argument is NaN.

        Infinite values in real or imaginary parts of the input may result in infinite or NaN values returned in parts of the result.

          Examples:
          
           sqrt(1 ± ∞ i) = ∞ + NaN i
           sqrt(∞ + i) = ∞ + 0i
           sqrt(-∞ + i) = 0 + ∞ i
           sqrt(∞ ± ∞ i) = ∞ + NaN i
           sqrt(-∞ ± ∞ i) = NaN ± ∞ i
          
         
        Specified by:
        sqrt in interface CalculusFieldElement<Complex>
        Returns:
        the square root of this with nonnegative real part.
      • sqrt1z

        public Complex sqrt1z()
        Compute the square root of 1 - this2 for this complex number. Computes the result directly as sqrt(ONE.subtract(z.multiply(z))).

        Returns NaN if either real or imaginary part of the input argument is NaN.

        Infinite values in real or imaginary parts of the input may result in infinite or NaN values returned in parts of the result.
        Returns:
        the square root of 1 - this2.
      • cbrt

        public Complex cbrt()
        Cubic root.

        This implementation compute the principal cube root by using a branch cut along real negative axis.

        Specified by:
        cbrt in interface CalculusFieldElement<Complex>
        Returns:
        cubic root of the instance
        Since:
        1.7
      • rootN

        public Complex rootN​(int n)
        Nth root.

        This implementation compute the principal nth root by using a branch cut along real negative axis.

        Specified by:
        rootN in interface CalculusFieldElement<Complex>
        Parameters:
        n - order of the root
        Returns:
        nth root of the instance
        Since:
        1.7
      • tan

        public Complex tan()
        Compute the tangent of this complex number. Implements the formula:
          
           tan(a + bi) = sin(2a)/(cos(2a)+cosh(2b)) + [sinh(2b)/(cos(2a)+cosh(2b))]i
          
         
        where the (real) functions on the right-hand side are FastMath.sin(double), FastMath.cos(double), FastMath.cosh(double) and FastMath.sinh(double).

        Returns NaN if either real or imaginary part of the input argument is NaN.

        Infinite (or critical) values in real or imaginary parts of the input may result in infinite or NaN values returned in parts of the result.
          Examples:
          
           tan(a ± INFINITY i) = 0 ± i
           tan(±INFINITY + bi) = NaN + NaN i
           tan(±INFINITY ± INFINITY i) = NaN + NaN i
           tan(±π/2 + 0 i) = ±INFINITY + NaN i
          
         
        Specified by:
        tan in interface CalculusFieldElement<Complex>
        Returns:
        the tangent of this.
      • tanh

        public Complex tanh()
        Compute the hyperbolic tangent of this complex number. Implements the formula:
          
           tan(a + bi) = sinh(2a)/(cosh(2a)+cos(2b)) + [sin(2b)/(cosh(2a)+cos(2b))]i
          
         
        where the (real) functions on the right-hand side are FastMath.sin(double), FastMath.cos(double), FastMath.cosh(double) and FastMath.sinh(double).

        Returns NaN if either real or imaginary part of the input argument is NaN.

        Infinite values in real or imaginary parts of the input may result in infinite or NaN values returned in parts of the result.
          Examples:
          
           tanh(a ± INFINITY i) = NaN + NaN i
           tanh(±INFINITY + bi) = ±1 + 0 i
           tanh(±INFINITY ± INFINITY i) = NaN + NaN i
           tanh(0 + (π/2)i) = NaN + INFINITY i
          
         
        Specified by:
        tanh in interface CalculusFieldElement<Complex>
        Returns:
        the hyperbolic tangent of this.
      • getArgument

        public double getArgument()
        Compute the argument of this complex number. The argument is the angle phi between the positive real axis and the point representing this number in the complex plane. The value returned is between -PI (not inclusive) and PI (inclusive), with negative values returned for numbers with negative imaginary parts.

        If either real or imaginary part (or both) is NaN, NaN is returned. Infinite parts are handled as Math.atan2 handles them, essentially treating finite parts as zero in the presence of an infinite coordinate and returning a multiple of pi/4 depending on the signs of the infinite parts. See the javadoc for Math.atan2 for full details.

        Returns:
        the argument of this.
      • nthRoot

        public List<Complex> nthRoot​(int n)
                              throws MathIllegalArgumentException
        Computes the n-th roots of this complex number. The nth roots are defined by the formula:
          
           zk = abs1/n (cos(phi + 2πk/n) + i (sin(phi + 2πk/n))
          
         
        for k=0, 1, ..., n-1, where abs and phi are respectively the modulus and argument of this complex number.

        If one or both parts of this complex number is NaN, a list with just one element, NaN is returned. if neither part is NaN, but at least one part is infinite, the result is a one-element list containing INF.

        Parameters:
        n - Degree of root.
        Returns:
        a List of all n-th roots of this.
        Throws:
        MathIllegalArgumentException - if n <= 0.
      • createComplex

        protected Complex createComplex​(double realPart,
                                        double imaginaryPart)
        Create a complex number given the real and imaginary parts.
        Parameters:
        realPart - Real part.
        imaginaryPart - Imaginary part.
        Returns:
        a new complex number instance.
        See Also:
        valueOf(double, double)
      • valueOf

        public static Complex valueOf​(double realPart,
                                      double imaginaryPart)
        Create a complex number given the real and imaginary parts.
        Parameters:
        realPart - Real part.
        imaginaryPart - Imaginary part.
        Returns:
        a Complex instance.
      • valueOf

        public static Complex valueOf​(double realPart)
        Create a complex number given only the real part.
        Parameters:
        realPart - Real part.
        Returns:
        a Complex instance.
      • newInstance

        public Complex newInstance​(double realPart)
        Create an instance corresponding to a constant real value.
        Specified by:
        newInstance in interface CalculusFieldElement<Complex>
        Parameters:
        realPart - constant real value
        Returns:
        instance corresponding to a constant real value
      • readResolve

        protected final Object readResolve()
        Resolve the transient fields in a deserialized Complex Object. Subclasses will need to override createComplex(double, double) to deserialize properly.
        Returns:
        A Complex instance with all fields resolved.
      • scalb

        public Complex scalb​(int n)
        Multiply the instance by a power of 2.
        Specified by:
        scalb in interface CalculusFieldElement<Complex>
        Parameters:
        n - power of 2
        Returns:
        this × 2n
        Since:
        1.7
      • hypot

        public Complex hypot​(Complex y)
        Returns the hypotenuse of a triangle with sides this and y - sqrt(this2 +y2) avoiding intermediate overflow or underflow.
        • If either argument is infinite, then the result is positive infinity.
        • else, if either argument is NaN then the result is NaN.
        Specified by:
        hypot in interface CalculusFieldElement<Complex>
        Parameters:
        y - a value
        Returns:
        sqrt(this2 +y2)
        Since:
        1.7
      • getPi

        public Complex getPi()
        Get the Archimedes constant π.

        Archimedes constant is the ratio of a circle's circumference to its diameter.

        Specified by:
        getPi in interface CalculusFieldElement<Complex>
        Returns:
        Archimedes constant π
      • rint

        public Complex rint()
        Get the whole number that is the nearest to the instance, or the even one if x is exactly half way between two integers.
        Specified by:
        rint in interface CalculusFieldElement<Complex>
        Returns:
        a double number r such that r is an integer r - 0.5 ≤ this ≤ r + 0.5
        Since:
        1.7
      • remainder

        public Complex remainder​(double a)
        IEEE remainder operator.

        for complex numbers, the integer n corresponding to this.subtract(remainder(a)).divide(a) is a Wikipedia - Gaussian integer.

        Specified by:
        remainder in interface CalculusFieldElement<Complex>
        Parameters:
        a - right hand side parameter of the operator
        Returns:
        this - n × a where n is the closest integer to this/a
        Since:
        1.7
      • remainder

        public Complex remainder​(Complex a)
        IEEE remainder operator.

        for complex numbers, the integer n corresponding to this.subtract(remainder(a)).divide(a) is a Wikipedia - Gaussian integer.

        Specified by:
        remainder in interface CalculusFieldElement<Complex>
        Parameters:
        a - right hand side parameter of the operator
        Returns:
        this - n × a where n is the closest integer to this/a
        Since:
        1.7
      • sign

        public Complex sign()
        Compute the sign of the instance. The sign is -1 for negative numbers, +1 for positive numbers and 0 otherwise, for Complex number, it is extended on the unit circle (equivalent to z/|z|, with special handling for 0 and NaN)
        Specified by:
        sign in interface CalculusFieldElement<Complex>
        Returns:
        -1.0, -0.0, +0.0, +1.0 or NaN depending on sign of a
        Since:
        2.0
      • copySign

        public Complex copySign​(Complex z)
        Returns the instance with the sign of the argument. A NaN sign argument is treated as positive.

        The signs of real and imaginary parts are copied independently.

        Specified by:
        copySign in interface CalculusFieldElement<Complex>
        Parameters:
        z - the sign for the returned value
        Returns:
        the instance with the same sign as the sign argument
        Since:
        1.7
      • copySign

        public Complex copySign​(double r)
        Returns the instance with the sign of the argument. A NaN sign argument is treated as positive.
        Specified by:
        copySign in interface CalculusFieldElement<Complex>
        Parameters:
        r - the sign for the returned value
        Returns:
        the instance with the same sign as the sign argument
        Since:
        1.7
      • compareTo

        public int compareTo​(Complex o)

        Comparison us performed using real ordering as the primary sort order and imaginary ordering as the secondary sort order.

        Specified by:
        compareTo in interface Comparable<Complex>
        Since:
        3.0