summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHans Boehm <hboehm@google.com>2015-06-13 21:12:23 -0700
committerHans Boehm <hboehm@google.com>2015-06-13 21:12:23 -0700
commitcd740596f6f8bdacf02f735f116ffc544f922893 (patch)
treeb0a71b8f4b6b51c2ca9dbe4ce19b2a6172d15b42 /src
parentb3f7278ab5464a9358bb5b57372e124aafe837d1 (diff)
downloadandroid_packages_apps_ExactCalculator-cd740596f6f8bdacf02f735f116ffc544f922893.tar.gz
android_packages_apps_ExactCalculator-cd740596f6f8bdacf02f735f116ffc544f922893.tar.bz2
android_packages_apps_ExactCalculator-cd740596f6f8bdacf02f735f116ffc544f922893.zip
Fix digitsRequired() for negative denominators
Bug: 21789679 Also adds some tests for digitsRequired(), including one that fails without this CL. Change-Id: Ib007e753f90c019c37666d71c1cfd02301dcd360
Diffstat (limited to 'src')
-rw-r--r--src/com/android/calculator2/BoundedRational.java5
1 files changed, 4 insertions, 1 deletions
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);
}
}