Skip to content

Commit

Permalink
fixed files form Math #36
Browse files Browse the repository at this point in the history
  • Loading branch information
tdurieux committed Mar 7, 2017
1 parent 3166c1a commit 1849c13
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions projects/Math/36/org/apache/commons/math/fraction/BigFraction.java
Original file line number Diff line number Diff line change
Expand Up @@ -683,8 +683,14 @@ public BigFraction divide(final BigFraction fraction) {
@Override
public double doubleValue() {
double result = numerator.doubleValue() / denominator.doubleValue();
if (Double.isNaN(result)) {
// Numerator and/or denominator must be out of range:
// Calculate how far to shift them to put them in range.
int shift = Math.max(numerator.bitLength(),
denominator.bitLength()) - Double.MAX_EXPONENT;
result = numerator.shiftRight(shift).doubleValue() /
denominator.shiftRight(shift).doubleValue();
}
return result;
}

Expand Down Expand Up @@ -730,8 +736,14 @@ public boolean equals(final Object other) {
@Override
public float floatValue() {
float result = numerator.floatValue() / denominator.floatValue();
if (Double.isNaN(result)) {
// Numerator and/or denominator must be out of range:
// Calculate how far to shift them to put them in range.
int shift = Math.max(numerator.bitLength(),
denominator.bitLength()) - Float.MAX_EXPONENT;
result = numerator.shiftRight(shift).floatValue() /
denominator.shiftRight(shift).floatValue();
}
return result;
}

Expand Down

0 comments on commit 1849c13

Please sign in to comment.