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

Commit 73ecff20 authored by Hans Boehm's avatar Hans Boehm
Browse files

Check for decimal point after adding ellipsis

Bug: 23728152

This avoids the one case in which we displayed neither a decimal
point nor an exponent, and the decimal point was not just to the
right of the number.

Remove a redundant test, which obscured the logic.

Add a couple of suggested manual tests that helped me find a
(newly introduced, not submitted) bug.

Change-Id: Iead1efa0a4e8ea74512e9e1f77334f80bbcdd202
parent 99374da7
Loading
Loading
Loading
Loading
+35 −35
Original line number Diff line number Diff line
@@ -370,8 +370,12 @@ public class CalculatorResult extends AlignedTextView {
            boolean negative, int lastDisplayedOffset[], boolean forcePrecision) {
        final int minusSpace = negative ? 1 : 0;
        final int msdIndex = truncated ? -1 : getNaiveMsdIndexOf(in);  // INVALID_MSD is OK.
        final int decIndex = in.indexOf('.');
        String result = in;
        if (truncated || (negative && result.charAt(0) != '-')) {
            result = KeyMaps.ELLIPSIS + result.substring(1, result.length());
            // Ellipsis may be removed again in the type(1) scientific notation case.
        }
        final int decIndex = result.indexOf('.');
        lastDisplayedOffset[0] = precOffset;
        if ((decIndex == -1 || msdIndex != Evaluator.INVALID_MSD
                && msdIndex - decIndex > MAX_LEADING_ZEROES + 1) &&  precOffset != -1) {
@@ -400,7 +404,7 @@ public class CalculatorResult extends AlignedTextView {
                exponent = initExponent + resLen - msdIndex - 1;
                hasPoint = true;
            }
            if (exponent != 0 || truncated) {
            // Exponent can't be zero.
            // Actually add the exponent of either type:
            if (!forcePrecision) {
                int dropDigits;  // Digits to drop to make room for exponent.
@@ -432,10 +436,6 @@ public class CalculatorResult extends AlignedTextView {
                lastDisplayedOffset[0] -= dropDigits;
            }
            result = result + "E" + Integer.toString(exponent);
            } // else don't add zero exponent
        }
        if (truncated || negative && result.charAt(0) != '-') {
            result = KeyMaps.ELLIPSIS + result.substring(1, result.length());
        }
        return result;
    }
+2 −0
Original line number Diff line number Diff line
@@ -39,6 +39,8 @@ Some interesting manual test cases:
-10^30 - 10^10
-1.2x10^-9
-1.2x10^-8
-1.2x10^-10
-10^-12
1 - 10^-98
1 - 10^-100
1 - 10^-300