From cd740596f6f8bdacf02f735f116ffc544f922893 Mon Sep 17 00:00:00 2001 From: Hans Boehm Date: Sat, 13 Jun 2015 21:12:23 -0700 Subject: Fix digitsRequired() for negative denominators Bug: 21789679 Also adds some tests for digitsRequired(), including one that fails without this CL. Change-Id: Ib007e753f90c019c37666d71c1cfd02301dcd360 --- src/com/android/calculator2/BoundedRational.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/com/android/calculator2/BoundedRational.java b/src/com/android/calculator2/BoundedRational.java index 8bf2bf5..2602f56 100644 --- a/src/com/android/calculator2/BoundedRational.java +++ b/src/com/android/calculator2/BoundedRational.java @@ -485,6 +485,7 @@ public class BoundedRational { } private static final BigInteger BIG_FIVE = BigInteger.valueOf(5); + private static final BigInteger BIG_MINUS_ONE = BigInteger.valueOf(-1); // Return the number of decimal digits to the right of the // decimal point required to represent the argument exactly, @@ -514,7 +515,9 @@ public class BoundedRational { // (Recall the fraction was in lowest terms to start with.) // Otherwise the powers of 10 we need to cancel the denominator // is the larger of powers_of_two and powers_of_five. - if (!den.equals(BigInteger.ONE)) return Integer.MAX_VALUE; + if (!den.equals(BigInteger.ONE) && !den.equals(BIG_MINUS_ONE)) { + return Integer.MAX_VALUE; + } return Math.max(powers_of_two, powers_of_five); } } -- cgit v1.2.3