summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Boehm <hboehm@google.com>2015-10-11 14:06:52 (GMT)
committerAndroid Git Automerger <android-git-automerger@android.com>2015-10-11 14:06:52 (GMT)
commit3be0cbfe04a40b1e6c7b676f02cda351b4c5df3e (patch)
tree7fe88654e8f4a1aa916fa53db2fd565d695332b9
parent0af1bd1ccbc02454b781b2fbd98143517007447a (diff)
parent4727061654f6f7fea8e90d3e87d835839121ed8d (diff)
downloadandroid_packages_apps_ExactCalculator-3be0cbfe04a40b1e6c7b676f02cda351b4c5df3e.zip
android_packages_apps_ExactCalculator-3be0cbfe04a40b1e6c7b676f02cda351b4c5df3e.tar.gz
android_packages_apps_ExactCalculator-3be0cbfe04a40b1e6c7b676f02cda351b4c5df3e.tar.bz2
am 47270616: am e4b8ff7c: Don\'t evaluate a lone decimal point to zero
* commit '4727061654f6f7fea8e90d3e87d835839121ed8d': Don't evaluate a lone decimal point to zero
-rw-r--r--src/com/android/calculator2/CalculatorExpr.java15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/com/android/calculator2/CalculatorExpr.java b/src/com/android/calculator2/CalculatorExpr.java
index b387e8b..77e53ea 100644
--- a/src/com/android/calculator2/CalculatorExpr.java
+++ b/src/com/android/calculator2/CalculatorExpr.java
@@ -217,12 +217,19 @@ class CalculatorExpr {
}
/**
- * Return BoundedRational representation of constant.
- * Never null.
+ * Return BoundedRational representation of constant, if well-formed.
+ * Result is never null.
*/
- public BoundedRational toRational() {
+ public BoundedRational toRational() throws SyntaxException {
String whole = mWhole;
- if (whole.isEmpty()) whole = "0";
+ if (whole.isEmpty()) {
+ if (mFraction.isEmpty()) {
+ // Decimal point without digits.
+ throw new SyntaxException();
+ } else {
+ whole = "0";
+ }
+ }
BigInteger num = new BigInteger(whole + mFraction);
BigInteger den = BigInteger.TEN.pow(mFraction.length());
if (mExponent > 0) {