Skip to content

Commit

Permalink
use hipparchus.fraction.BigFraction#doubleValue() from latest snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
axkr committed Sep 15, 2023
1 parent d48eec1 commit 763d0dc
Showing 1 changed file with 1 addition and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.math.BigInteger;
import java.util.function.Function;
import org.hipparchus.fraction.BigFraction;
import org.hipparchus.util.FastMath;
import org.matheclipse.core.basic.Config;
import org.matheclipse.core.eval.exception.BigIntegerLimitExceeded;
import org.matheclipse.core.eval.util.SourceCodeProperties;
Expand Down Expand Up @@ -250,16 +249,7 @@ public IInteger[] divideAndRemainder() {

@Override
public double doubleValue() {
// Thanks to org.hipparchus.fraction.BigFraction#doubleValue
BigInteger numerator = fFraction.getNumerator();
BigInteger denominator = fFraction.getDenominator();
double result = numerator.doubleValue() / denominator.doubleValue();
if (Double.isInfinite(result) || Double.isNaN(result)) {
int shift = FastMath.max(numerator.bitLength(),denominator.bitLength()) - FastMath.getExponent(Double.MAX_VALUE);
result = numerator.shiftRight(shift).doubleValue() / denominator.shiftRight(shift).doubleValue();
}

return result;
return fFraction.doubleValue();
}

@Override
Expand Down

0 comments on commit 763d0dc

Please sign in to comment.