summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Klaassen <justinklaassen@google.com>2014-12-08 19:09:03 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-12-08 19:09:03 +0000
commitd61b039d67720ac522ca0cf40d738baee3cfc326 (patch)
tree19fa9098b2e853dddda9a073984a73a649ab4ef0
parent4785ba546595612f7889f5cc02d4c7351bec47ee (diff)
parent8f27d2a402c9bd909d8f851e8ae323ba427f0f13 (diff)
downloadCalculator-d61b039d67720ac522ca0cf40d738baee3cfc326.tar.gz
am 8f27d2a4: am e61089e5: Increase number of guard digits
* commit '8f27d2a402c9bd909d8f851e8ae323ba427f0f13': Increase number of guard digits
-rw-r--r--src/com/android/calculator2/CalculatorExpressionEvaluator.java10
1 files changed, 9 insertions, 1 deletions
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 @@ import org.javia.arity.Util;
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;