Skip to content

Commit

Permalink
fixed files form Math #47
Browse files Browse the repository at this point in the history
  • Loading branch information
tdurieux committed Mar 7, 2017
1 parent 057bb09 commit 6326282
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions projects/Math/47/org/apache/commons/math/complex/Complex.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class Complex implements FieldElement<Complex>, Serializable {
/** Record whether this complex number is infinite. */
private final transient boolean isInfinite;
/** Record whether this complex number is zero. */
private final transient boolean isZero;

/**
* Create a complex number given only the real part.
Expand All @@ -102,6 +103,7 @@ public Complex(double real, double imaginary) {
isNaN = Double.isNaN(real) || Double.isNaN(imaginary);
isInfinite = !isNaN &&
(Double.isInfinite(real) || Double.isInfinite(imaginary));
isZero = real == 0 && imaginary == 0;
}

/**
Expand Down Expand Up @@ -253,8 +255,8 @@ public Complex divide(Complex divisor)
return NaN;
}

if (divisor.getReal() == 0.0 && divisor.getImaginary() == 0.0) {
return NaN;
if (divisor.isZero) {
return isZero ? NaN : INF;
}

if (divisor.isInfinite() && !isInfinite()) {
Expand Down Expand Up @@ -290,7 +292,7 @@ public Complex divide(double divisor) {
return NaN;
}
if (divisor == 0d) {
return NaN;
return isZero ? NaN : INF;
}
if (Double.isInfinite(divisor)) {
return !isInfinite() ? ZERO : NaN;
Expand Down

0 comments on commit 6326282

Please sign in to comment.