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
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 @@
}
/**
- * 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) {