Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3465c782 authored by Hans Boehm's avatar Hans Boehm
Browse files

Fix COPY string computation in exact case

Bug: 26175989
Bug: 33458621

Fix the determination of whether the currently displayed result is
already exact. The old logic failed to deal with the odd corner
case in which we force an initial scientific notation display because
we don't have room for digit separators.

When we recompute the exact result as part of a copy operation,
and the exact result is an integer, do not add a trailing decimal
point.

Change-Id: I3f673fc428cf6982eeaf6aa1037b9f522ea2d6f9
parent 12874e38
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -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);
+1 −0
Original line number Diff line number Diff line
@@ -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
     */