diff options
author | Hans Boehm <hboehm@google.com> | 2016-12-13 21:45:58 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2016-12-13 21:45:58 +0000 |
commit | fcb1e611dcc6ffd98be6b6847cbeb56966b70721 (patch) | |
tree | ba0ec917b6cf2d4c82c859dcfba1056c7d50a01a | |
parent | 3aa4d05baf344eee378294b77644cc307af8a46c (diff) | |
parent | 3465c782410b9e19f9a4e92cb8c74647e38a5bdc (diff) | |
download | android_packages_apps_ExactCalculator-fcb1e611dcc6ffd98be6b6847cbeb56966b70721.tar.gz android_packages_apps_ExactCalculator-fcb1e611dcc6ffd98be6b6847cbeb56966b70721.tar.bz2 android_packages_apps_ExactCalculator-fcb1e611dcc6ffd98be6b6847cbeb56966b70721.zip |
Merge "Fix COPY string computation in exact case" into ub-calculator-euler
-rw-r--r-- | src/com/android/calculator2/CalculatorResult.java | 15 | ||||
-rw-r--r-- | src/com/android/calculator2/UnifiedReal.java | 1 |
2 files changed, 11 insertions, 5 deletions
diff --git a/src/com/android/calculator2/CalculatorResult.java b/src/com/android/calculator2/CalculatorResult.java index 480c542..a8ab291 100644 --- a/src/com/android/calculator2/CalculatorResult.java +++ b/src/com/android/calculator2/CalculatorResult.java @@ -101,7 +101,7 @@ public class CalculatorResult extends AlignedTextView implements MenuItem.OnMenu // append an exponent insteadd of replacing trailing digits. private final Object mWidthLock = new Object(); // Protects the next five fields. These fields are only - // Updated by the UI thread, and read accesses by the UI thread + // updated by the UI thread, and read accesses by the UI thread // sometimes do not acquire the lock. private int mWidthConstraint = 0; // Our total width in pixels minus space for ellipsis. @@ -837,7 +837,7 @@ public class CalculatorResult extends AlignedTextView implements MenuItem.OnMenu * UI thread only. */ public boolean fullTextIsExact() { - return !mScrollable || (mMaxCharOffset == getCharOffset(mCurrentPos) + return !mScrollable || (getCharOffset(mMaxPos) == getCharOffset(mCurrentPos) && mMaxCharOffset != MAX_RIGHT_SCROLL); } @@ -855,9 +855,14 @@ public class CalculatorResult extends AlignedTextView implements MenuItem.OnMenu return getFullText(false /* withSeparators */); } // It's reasonable to compute and copy the exact result instead. - final int nonNegLsdOffset = Math.max(0, mLsdOffset); - final String rawResult = mEvaluator.getResult(mIndex).toStringTruncated(nonNegLsdOffset); - final String formattedResult = formatResult(rawResult, nonNegLsdOffset, MAX_COPY_SIZE, + int fractionLsdOffset = Math.max(0, mLsdOffset); + String rawResult = mEvaluator.getResult(mIndex).toStringTruncated(fractionLsdOffset); + if (mLsdOffset <= -1) { + // Result has trailing decimal point. Remove it. + rawResult = rawResult.substring(0, rawResult.length() - 1); + fractionLsdOffset = -1; + } + final String formattedResult = formatResult(rawResult, fractionLsdOffset, MAX_COPY_SIZE, false, rawResult.charAt(0) == '-', null, true /* forcePrecision */, false /* forceSciNotation */, false /* insertCommas */); return KeyMaps.translateResult(formattedResult); diff --git a/src/com/android/calculator2/UnifiedReal.java b/src/com/android/calculator2/UnifiedReal.java index 7ccd87f..f6cf50b 100644 --- a/src/com/android/calculator2/UnifiedReal.java +++ b/src/com/android/calculator2/UnifiedReal.java @@ -366,6 +366,7 @@ public class UnifiedReal { * Returns a truncated representation of the result. * If exactlyTruncatable(), we round correctly towards zero. Otherwise the resulting digit * string may occasionally be rounded up instead. + * Always includes a decimal point in the result. * The result includes n digits to the right of the decimal point. * @param n result precision, >= 0 */ |