summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Boehm <hboehm@google.com>2015-06-18 03:06:07 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-06-18 03:06:07 +0000
commit052524990a4968cf19928e897d8c520b2e5b7bac (patch)
tree64e6710b60d79bf7059b0cc53f2622b34646ccc4
parentfb8a6542ab41c6e823f426d4ffd23f6e0c59fc9c (diff)
parentcd740596f6f8bdacf02f735f116ffc544f922893 (diff)
downloadandroid_packages_apps_ExactCalculator-052524990a4968cf19928e897d8c520b2e5b7bac.tar.gz
android_packages_apps_ExactCalculator-052524990a4968cf19928e897d8c520b2e5b7bac.tar.bz2
android_packages_apps_ExactCalculator-052524990a4968cf19928e897d8c520b2e5b7bac.zip
Merge "Fix digitsRequired() for negative denominators" into mnc-dev
-rw-r--r--src/com/android/calculator2/BoundedRational.java5
-rw-r--r--tests/src/com/android/calculator2/BRTest.java6
2 files changed, 10 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);
}
}
diff --git a/tests/src/com/android/calculator2/BRTest.java b/tests/src/com/android/calculator2/BRTest.java
index 29a5ae9..77d4bf0 100644
--- a/tests/src/com/android/calculator2/BRTest.java
+++ b/tests/src/com/android/calculator2/BRTest.java
@@ -139,6 +139,12 @@ public class BRTest extends TestCase {
check(BR_0.signum() == 0, "signum(0)");
check(BR_M1.signum() == -1, "signum(-1)");
check(BR_2.signum() == 1, "signum(2)");
+ check(BoundedRational.digitsRequired(BoundedRational.ZERO) == 0, "digitsRequired(0)");
+ check(BoundedRational.digitsRequired(BoundedRational.HALF) == 1, "digitsRequired(1/2)");
+ check(BoundedRational.digitsRequired(BoundedRational.MINUS_HALF) == 1,
+ "digitsRequired(-1/2)");
+ check(BoundedRational.digitsRequired(new BoundedRational(1,-2)) == 1,
+ "digitsRequired(1/-2)");
// We check values that include all interesting degree values.
BoundedRational r = BR_M390;
while (!r.equals(BR_390)) {