/** * Returns a <code>String</code> representation of the given * <code>Complex</code> number. * * @param c * @return * */ public static String toString(Complex c) { double real = c.getReal(); double imag = c.getImaginary(); if (imag == 0.0) { return Double.valueOf(real).toString(); } else { if (imag >= 0.0) { return Double.valueOf(real).toString() + "+I*" + Double.valueOf(imag).toString(); } else { return Double.valueOf(real).toString() + "+I*(" + Double.valueOf(imag).toString() + ")"; } } }
/** * Returns a <code>String</code> representation of the given * <code>Complex</code> number. * * @param c the c * @return the string */ public static String toString( Complex c ) { double real = c.getReal(); double imag = c.getImaginary(); if ( imag == 0.0 ) { return Double.valueOf( real ).toString(); } else { if ( imag >= 0.0 ) { return Double.valueOf( real ).toString() + "+I*" + Double.valueOf( imag ).toString(); } else { return Double.valueOf( real ).toString() + "+I*(" + Double.valueOf( imag ).toString() + ")"; } } }
/** * Return the sum of 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 sum * @throws java.lang.NullPointerException if <code>rhs</code> is null */ public Complex add( Complex rhs ) { return createComplex( real + rhs.getReal(), imaginary + rhs.getImaginary() ); }
/** * Hash code. * * @return the int */ @Override public int hashCode() { long rbits = MathUtils.hash( value.getReal() );// Double.doubleToLongBits(value.getReal()); long ibits = MathUtils.hash( value.getImaginary() );// Double.doubleToLongBits(value.getImaginary()); return (int) (rbits ^ (ibits >>> 32)); } }
/** * Return the sum of 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 sum * @throws NullPointerException * if <code>rhs</code> is null */ public Complex add(Complex rhs) { return createComplex(real + rhs.getReal(), imaginary + rhs.getImaginary()); }
public int hashCode() { long rbits = MathUtils.hash(value.getReal());// Double.doubleToLongBits(value.getReal()); long ibits = MathUtils.hash(value.getImaginary());// Double.doubleToLongBits(value.getImaginary()); return (int) (rbits ^ (ibits >>> 32)); } }
ret = this.isNaN(); } else { ret = (real == rhs.getReal()) && (imaginary == rhs.getImaginary());
/** * 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() ); }
ret = (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()); }
double d = rhs.getImaginary(); if ( c == 0.0 && d == 0.0 ) { return NaN;
double d = rhs.getImaginary(); if (c == 0.0 && d == 0.0) { return NaN;