summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHans Boehm <hboehm@google.com>2015-08-17 16:14:52 -0700
committerHans Boehm <hboehm@google.com>2015-10-11 05:37:12 +0000
commite4b8ff7c9c8a041ab451cdc78a019b2a4a666b99 (patch)
tree75f75bb20bd41f31daaf869da41676b3d9d05f71 /src
parentb7bd34886fb39401b6e38ad97634655a0d025902 (diff)
downloadandroid_packages_apps_ExactCalculator-e4b8ff7c9c8a041ab451cdc78a019b2a4a666b99.tar.gz
android_packages_apps_ExactCalculator-e4b8ff7c9c8a041ab451cdc78a019b2a4a666b99.tar.bz2
android_packages_apps_ExactCalculator-e4b8ff7c9c8a041ab451cdc78a019b2a4a666b99.zip
Don't evaluate a lone decimal point to zero
Bug: 22917707 Make a constant consisting of just a decimal point produce an error when evaluated. Change-Id: I970c8b396894f301553171dad3c325ffac09ff57 (cherry picked from commit fa5203c051fb5139c8fc678cae3997c8a7293c84)
Diffstat (limited to 'src')
-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) {