Increase number of guard digits
Bug: 18544929
In order to decrease the visibility of floating point errors, maximize
the number of guard digits.
Change-Id: I5c12f4e7e00c4d3e3a281cc2383c3bb12c530e39
diff --git a/src/com/android/calculator2/CalculatorExpressionEvaluator.java b/src/com/android/calculator2/CalculatorExpressionEvaluator.java
index 26cd404..85d719b 100644
--- a/src/com/android/calculator2/CalculatorExpressionEvaluator.java
+++ b/src/com/android/calculator2/CalculatorExpressionEvaluator.java
@@ -22,8 +22,16 @@
public class CalculatorExpressionEvaluator {
+ /**
+ * The maximum number of significant digits to display.
+ */
private static final int MAX_DIGITS = 12;
- private static final int ROUNDING_DIGITS = 2;
+
+ /**
+ * A {@link Double} has at least 17 significant digits, we show the first {@link #MAX_DIGITS}
+ * and use the remaining digits as guard digits to hide floating point precision errors.
+ */
+ private static final int ROUNDING_DIGITS = Math.max(17 - MAX_DIGITS, 0);
private final Symbols mSymbols;
private final CalculatorExpressionTokenizer mTokenizer;