diff --git a/projects/Math/36/org/apache/commons/math/fraction/BigFraction.java b/projects/Math/36/org/apache/commons/math/fraction/BigFraction.java index 6181ec3..a6672e4 100644 --- a/projects/Math/36/org/apache/commons/math/fraction/BigFraction.java +++ b/projects/Math/36/org/apache/commons/math/fraction/BigFraction.java @@ -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; } @@ -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; }