diff options
author | Hans Boehm <hboehm@google.com> | 2015-04-20 10:27:12 -0700 |
---|---|---|
committer | Hans Boehm <hboehm@google.com> | 2015-04-20 18:47:55 -0700 |
commit | 760a9dc6573e35bcbf9097dece06cd90c4abb551 (patch) | |
tree | 4a8eefbed4561fcd7df4a1d10aa41a2fe3e11f30 /src/com/android/calculator2/Evaluator.java | |
parent | 76b78159dc27a365e1cd9fc07379607893d016f6 (diff) | |
download | android_packages_apps_ExactCalculator-760a9dc6573e35bcbf9097dece06cd90c4abb551.tar.gz android_packages_apps_ExactCalculator-760a9dc6573e35bcbf9097dece06cd90c4abb551.tar.bz2 android_packages_apps_ExactCalculator-760a9dc6573e35bcbf9097dece06cd90c4abb551.zip |
Fix result overlap, clear logic, display bugs, etc.
Adjust result padding to prevent overlapping with options menu,
resulting in inability to access options menu.
Reset state correctly after clear, preventing occasional crashes.
Do this at end of animation to prevent animation glitches.
Have clear but the display in a state in which COPY does
nothing interesting.
Treat a not-known-to-be-exact zero result better. Before this
we displayed it as just "0", giving the mistaken impression of
exactness. It is unclear whether we should display it as "0.00000000"
or add an exponent to indicate the real evaluation precision.
The former probably works better for beginners; the latter for
experts. We now do the former, which is probably right.
Also correctly save and restore not-yet analyzed characters.
Change-Id: Iac46d0d3b5a06f61beb6af7d4f0910e43284f52b
Diffstat (limited to 'src/com/android/calculator2/Evaluator.java')
-rw-r--r-- | src/com/android/calculator2/Evaluator.java | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/com/android/calculator2/Evaluator.java b/src/com/android/calculator2/Evaluator.java index 6af3043..25cadae 100644 --- a/src/com/android/calculator2/Evaluator.java +++ b/src/com/android/calculator2/Evaluator.java @@ -153,7 +153,7 @@ class Evaluator { private int mCacheDigsReq; // Number of digits that have been // requested. Only touched by UI // thread. - private final int INVALID_MSD = Integer.MIN_VALUE; + private final int INVALID_MSD = Integer.MAX_VALUE; private int mMsd = INVALID_MSD; // Position of most significant digit // in current cached result, if determined. // This is just the index in mCache @@ -440,7 +440,7 @@ class Evaluator { // have room for and the current string approximation for // the result. // lastDigit is the position of the last digit on the right - // or Integer.MAX_VALUE. + // if there is such a thing, or Integer.MAX_VALUE. // May be called in non-UI thread. int getPreferredPrec(String cache, int msd, int lastDigit) { int lineLength = mResult.getMaxChars(); @@ -459,7 +459,14 @@ class Evaluator { // Treat leading zero as msd. msd = wholeSize - 1; } - return Math.min(msd, MAX_MSD_PREC) - wholeSize + lineLength - 2; + if (msd > wholeSize + MAX_MSD_PREC) { + // Display a probably but uncertain 0 as "0.000000000", + // without exponent. That's a judgment call, but less likely + // to confuse naive users. A more informative and confusing + // option would be to use a large negative exponent. + return lineLength - 2; + } + return msd - wholeSize + lineLength - 2; } // Get a short representation of the value represented by |