/** * Returns true if either the real or imaginary part of this complex number * takes an infinite value (either <code>Double.POSITIVE_INFINITY</code> or * <code>Double.NEGATIVE_INFINITY</code>) and neither part is * <code>NaN</code>. * * @return true if one or both parts of this complex number are infinite and * neither part is <code>NaN</code> */ public boolean isInfinite() { return !isNaN() && (Double.isInfinite( real ) || Double.isInfinite( imaginary )); }
/** * Returns true if either the real or imaginary part of this complex number * takes an infinite value (either <code>Double.POSITIVE_INFINITY</code> or * <code>Double.NEGATIVE_INFINITY</code>) and neither part is <code>NaN</code> * . * * @return true if one or both parts of this complex number are infinite and * neither part is <code>NaN</code> */ public boolean isInfinite() { return !isNaN() && (Double.isInfinite(real) || Double.isInfinite(imaginary)); }
/** * Return the additive inverse of this complex number. Returns * <code>Complex.NaN</code> if either real or imaginary part of this Complex * number equals <code>Double.NaN</code>. * * @return the negation of this complex number */ public Complex negate() { if ( isNaN() ) { return NaN; } return createComplex( -real, -imaginary ); }
/** * Return the additive inverse of this complex number. * <p> * Returns <code>Complex.NaN</code> if either real or imaginary part of this * Complex number equals <code>Double.NaN</code>. * </p> * * @return the negation of this complex number */ public Complex negate() { if (isNaN()) { return NaN; } return createComplex(-real, -imaginary); }
/** * Return the conjugate of this complex number. The conjugate of "A + Bi" is * "A - Bi". {@link #NaN} is returned if either the real or imaginary part * of this Complex number equals <code>Double.NaN</code>. * * 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 <code>1 + POSITIVE_INFINITY i</code> is * <code>1 - NEGATIVE_INFINITY i</code> * * @return the conjugate of this Complex object */ public Complex conjugate() { if ( isNaN() ) { return NaN; } return createComplex( real, -imaginary ); }
/** * Return the conjugate of this complex number. The conjugate of "A + Bi" is * "A - Bi". * <p> * {@link #NaN} is returned if either the real or imaginary part of this * Complex number equals <code>Double.NaN</code>. * </p> * <p> * 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 <code>1 + POSITIVE_INFINITY i</code> is * <code>1 - NEGATIVE_INFINITY i</code> * </p> * * @return the conjugate of this Complex object */ public Complex conjugate() { if (isNaN()) { return NaN; } return createComplex(real, -imaginary); }
/** * Return the absolute value of this complex number. Returns * <code>NaN</code> if either real or imaginary part is <code>NaN</code> and * <code>Double.POSITIVE_INFINITY</code> if neither part is * <code>NaN</code>, but at least one part takes an infinite value. * * @return the absolute value */ public double abs() { if ( isNaN() ) { return Double.NaN; } if ( isInfinite() ) { return Double.POSITIVE_INFINITY; } if ( Math.abs( real ) < Math.abs( imaginary ) ) { if ( imaginary == 0.0 ) { return Math.abs( real ); } double q = real / imaginary; return (Math.abs( imaginary ) * Math.sqrt( 1 + q * q )); } else { if ( real == 0.0 ) { return Math.abs( imaginary ); } double q = imaginary / real; return (Math.abs( real ) * Math.sqrt( 1 + q * q )); } }
if (isNaN()) { return Double.NaN;
if ( isNaN() ) { return Complex.NaN;
/** * Get a hashCode for the complex number. All NaN values have the same hash * code. * * @return a hash code value for this object */ @Override public int hashCode() { if ( isNaN() ) { return 7; } return 37 * (17 * MathUtils.hash( imaginary ) + MathUtils.hash( real )); }
/** * Get a hashCode for the complex number. * <p> * All NaN values have the same hash code. * </p> * * @return a hash code value for this object */ public int hashCode() { if (isNaN()) { return 7; } return 37 * (17 * MathUtils.hash(imaginary) + MathUtils.hash(real)); }
/** * Return the difference between this complex number and the given complex * number. Uses the definitional formula * * <pre> * (a + bi) - (c + di) = (a-c) + (b-d)i * </pre> * * If either this or <code>rhs</code> has a NaN value in either part, * {@link #NaN} is returned; otherwise inifinite and NaN values are returned * in the parts of the result according to the rules for * {@link java.lang.Double} arithmetic. * * @param rhs the other complex number * @return the complex number difference * @throws java.lang.NullPointerException if <code>rhs</code> is null */ public Complex subtract( Complex rhs ) { if ( isNaN() || rhs.isNaN() ) { return NaN; } return createComplex( real - rhs.getReal(), imaginary - rhs.getImaginary() ); }
/** * Return the difference between this complex number and the given complex * number. * <p> * Uses the definitional formula * * <pre> * (a + bi) - (c + di) = (a-c) + (b-d)i * </pre> * * </p> * <p> * If either this or <code>rhs</code> has a NaN value in either part, * {@link #NaN} is returned; otherwise inifinite and NaN values are returned * in the parts of the result according to the rules for * {@link java.lang.Double} arithmetic. * </p> * * @param rhs * the other complex number * @return the complex number difference * @throws NullPointerException * if <code>rhs</code> is null */ public Complex subtract(Complex rhs) { if (isNaN() || rhs.isNaN()) { return NaN; } return createComplex(real - rhs.getReal(), imaginary - rhs.getImaginary()); }
if ( isNaN() ) { return Complex.NaN;
/** * Compute the * <a href="http://mathworld.wolfram.com/InverseCosine.html" TARGET="_top"> * inverse cosine</a> of this complex number. Implements the formula: * * <pre> * <code> acos(z) = -i (log(z + i (sqrt(1 - z<sup>2</sup>))))</code> * </pre> * * Returns {@link org.matheclipse.parser.client.math.Complex#NaN} if either * real or imaginary part of the input argument is <code>NaN</code> or * infinite. * * @return the inverse cosine of this complex number * @since 1.2 */ public Complex acos() { if ( isNaN() ) { return Complex.NaN; } return this.add( this.sqrt1z().multiply( Complex.I ) ).log().multiply( Complex.I.negate() ); }
/** * Compute the <a href="http://mathworld.wolfram.com/InverseCosine.html" * TARGET="_top"> inverse cosine</a> of this complex number. * <p> * Implements the formula: * * <pre> * <code> acos(z) = -i (log(z + i (sqrt(1 - z<sup>2</sup>))))</code> * </pre> * * </p> * <p> * Returns {@link Complex#NaN} if either real or imaginary part of the input * argument is <code>NaN</code> or infinite. * </p> * * @return the inverse cosine of this complex number * @since 1.2 */ public Complex acos() { if (isNaN()) { return Complex.NaN; } return this.add(this.sqrt1z().multiply(Complex.I)).log().multiply(Complex.I.negate()); }
/** * Compute the * <a href="http://mathworld.wolfram.com/InverseSine.html" TARGET="_top"> * inverse sine</a> of this complex number. Implements the formula: * * <pre> * <code> asin(z) = -i (log(sqrt(1 - z<sup>2</sup>) + iz)) </code> * </pre> * * Returns {@link org.matheclipse.parser.client.math.Complex#NaN} if either * real or imaginary part of the input argument is <code>NaN</code> or * infinite. * * @return the inverse sine of this complex number. * @since 1.2 */ public Complex asin() { if ( isNaN() ) { return Complex.NaN; } return sqrt1z().add( this.multiply( Complex.I ) ).log().multiply( Complex.I.negate() ); }
/** * Compute the <a href="http://mathworld.wolfram.com/InverseSine.html" * TARGET="_top"> inverse sine</a> of this complex number. * <p> * Implements the formula: * * <pre> * <code> asin(z) = -i (log(sqrt(1 - z<sup>2</sup>) + iz)) </code> * </pre> * * </p> * <p> * Returns {@link Complex#NaN} if either real or imaginary part of the input * argument is <code>NaN</code> or infinite. * </p> * * @return the inverse sine of this complex number. * @since 1.2 */ public Complex asin() { if (isNaN()) { return Complex.NaN; } return sqrt1z().add(this.multiply(Complex.I)).log().multiply(Complex.I.negate()); }
/** * Compute the * <a href="http://mathworld.wolfram.com/InverseTangent.html" TARGET="_top"> * inverse tangent</a> of this complex number. Implements the formula: * * <pre> * <code> atan(z) = (i/2) log((i + z)/(i - z)) </code> * </pre> * * Returns {@link org.matheclipse.parser.client.math.Complex#NaN} if either * real or imaginary part of the input argument is <code>NaN</code> or * infinite. * * @return the inverse tangent of this complex number * @since 1.2 */ public Complex atan() { if ( isNaN() ) { return Complex.NaN; } return this.add( Complex.I ).divide( Complex.I.subtract( this ) ).log().multiply( Complex.I.divide( createComplex( 2.0, 0.0 ) ) ); }
/** * Compute the <a href="http://mathworld.wolfram.com/InverseTangent.html" * TARGET="_top"> inverse tangent</a> of this complex number. * <p> * Implements the formula: * * <pre> * <code> atan(z) = (i/2) log((i + z)/(i - z)) </code> * </pre> * * </p> * <p> * Returns {@link Complex#NaN} if either real or imaginary part of the input * argument is <code>NaN</code> or infinite. * </p> * * @return the inverse tangent of this complex number * @since 1.2 */ public Complex atan() { if (isNaN()) { return Complex.NaN; } return this.add(Complex.I).divide(Complex.I.subtract(this)).log().multiply(Complex.I.divide(createComplex(2.0, 0.0))); }