diff options
author | Hans Boehm <hboehm@google.com> | 2015-06-18 03:13:07 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-06-18 03:13:07 +0000 |
commit | ff68e1930fbbc48d454314c78f7771912538fe36 (patch) | |
tree | 76b2ee5a54b95f916d53594c5fd57a75647a2852 | |
parent | 7f96022a80ed4a9b255f2f4c63cfab2a078bf1c9 (diff) | |
parent | 052524990a4968cf19928e897d8c520b2e5b7bac (diff) | |
download | android_packages_apps_ExactCalculator-ff68e1930fbbc48d454314c78f7771912538fe36.tar.gz android_packages_apps_ExactCalculator-ff68e1930fbbc48d454314c78f7771912538fe36.tar.bz2 android_packages_apps_ExactCalculator-ff68e1930fbbc48d454314c78f7771912538fe36.zip |
am 05252499: Merge "Fix digitsRequired() for negative denominators" into mnc-dev
* commit '052524990a4968cf19928e897d8c520b2e5b7bac':
Fix digitsRequired() for negative denominators
-rw-r--r-- | src/com/android/calculator2/BoundedRational.java | 5 | ||||
-rw-r--r-- | tests/src/com/android/calculator2/BRTest.java | 6 |
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)) { |