]> granicus.if.org Git - icu/commitdiff
ICU-13634 Fixes for NumberFormatTest/TestExponential.
authorShane Carr <shane@unicode.org>
Fri, 30 Mar 2018 07:22:24 +0000 (07:22 +0000)
committerShane Carr <shane@unicode.org>
Fri, 30 Mar 2018 07:22:24 +0000 (07:22 +0000)
X-SVN-Rev: 41177

icu4c/source/i18n/fmtable.cpp
icu4c/source/i18n/number_decimalquantity.cpp
icu4c/source/i18n/number_decimalquantity.h
icu4c/source/i18n/numparse_parsednumber.cpp
icu4c/source/test/intltest/numbertest_decimalquantity.cpp
icu4c/source/test/intltest/numfmtst.cpp

index 862b5f912e55f57c0e2be42bf5665c03fd234569..e4c119aea6731a48f82803f869f68d3c7d243f6c 100644 (file)
@@ -768,17 +768,14 @@ Formattable::adoptDecimalQuantity(DecimalQuantity *dq) {
     }
 
     // Set the value into the Union of simple type values.
-    // Cannot use the set() functions because they would delete the fDecimalNum value,
-    // TODO: fDecimalQuantity->fitsInInt() to kLong type.
-    /*
-    if (fDecimalQuantity->fitsInInt()) {
-        fType = kLong;
-        fValue.fInt64 = fDecimalNum->getLong();
-    } else
-    */
+    // Cannot use the set() functions because they would delete the fDecimalNum value.
     if (fDecimalQuantity->fitsInLong()) {
-        fType = kInt64;
         fValue.fInt64 = fDecimalQuantity->toLong();
+        if (fValue.fInt64 <= INT32_MAX && fValue.fInt64 >= INT32_MIN) {
+            fType = kLong;
+        } else {
+            fType = kInt64;
+        }
     } else {
         fType = kDouble;
         fValue.fDouble = fDecimalQuantity->toDouble();
index 1d712b5ce42cb73cfb0f0c805395a6b047ab2076..a63044f9812c228774d7a0185ecfd4a09442ff17 100644 (file)
@@ -202,6 +202,10 @@ void DecimalQuantity::multiplyBy(int32_t multiplicand) {
     setToDouble(temp);
 }
 
+void DecimalQuantity::negate() {
+    flags ^= NEGATIVE_FLAG;
+}
+
 int32_t DecimalQuantity::getMagnitude() const {
     U_ASSERT(precision != 0);
     return scale + precision - 1;
index 10f2e669b8a91580c0aae131fa2882b74f6365ab..74c85248c4a9f033fe44064482e078cbec889d4d 100644 (file)
@@ -95,6 +95,9 @@ class U_I18N_API DecimalQuantity : public IFixedDecimal, public UMemory {
      */
     void multiplyBy(int32_t multiplicand);
 
+    /** Flips the sign from positive to negative and back. C++-only: not currently needed in Java. */
+    void negate();
+
     /**
      * Scales the number by a power of ten. For example, if the value is currently "1234.56", calling
      * this method with delta=-3 will change the value to "1.23456".
index b9cc54e6272ca4e99fbe1c398fab2d71b10bc091..16da923459e5df4b438c5b72b8906189aebded2f 100644 (file)
@@ -108,7 +108,7 @@ void ParsedNumber::populateFormattable(Formattable& output) const {
     // All other numbers
     LocalPointer<DecimalQuantity> actualQuantity(new DecimalQuantity(quantity));
     if (0 != (flags & FLAG_NEGATIVE)) {
-        actualQuantity->multiplyBy(-1);
+        actualQuantity->negate();
     }
     output.adoptDecimalQuantity(actualQuantity.orphan());
 }
index b260614dff585111aa12a70716f0962d525e6aee..2b313808791c9a0550788d5d2d088131fe59f068 100644 (file)
@@ -296,6 +296,7 @@ void DecimalQuantityTest::testHardDoubleConversion() {
 }
 
 void DecimalQuantityTest::testToDouble() {
+    IcuTestErrorCode status(*this, "testToDouble");
     static const struct TestCase {
         const char* input; // char* for the decNumber constructor
         double expected;
@@ -304,8 +305,9 @@ void DecimalQuantityTest::testToDouble() {
             { "-3.142E-271", -3.142e-271 } };
 
     for (auto& cas : cases) {
+        status.setScope(cas.input);
         DecimalQuantity q;
-        q.setToDecNumber({cas.input, -1});
+        q.setToDecNumber({cas.input, -1}, status);
         double actual = q.toDouble();
         assertEquals("Doubles should exactly equal", cas.expected, actual);
     }
index ee638ea36aa2c3fbd59023b6593d3fd10bde9954..d042ccd7c8658b119255e850a29a29296bc0dcdb 100644 (file)
@@ -927,7 +927,7 @@ NumberFormatTest::TestExponential(void)
 #endif
             }
             else {
-                errln((UnicodeString)"FAIL: Non-numeric Formattable returned");
+                errln(UnicodeString("FAIL: Non-numeric Formattable returned: ") + pattern + " " + s);
                 continue;
             }
             if (pos.getIndex() == s.length())
@@ -938,7 +938,8 @@ NumberFormatTest::TestExponential(void)
                     (uprv_fabs(a - valParse[v+ival]) / a > (2*DBL_EPSILON))) ||
                     (!useEpsilon && a != valParse[v+ival]))
                 {
-                    errln((UnicodeString)"FAIL: Expected " + valParse[v+ival]);
+                    errln((UnicodeString)"FAIL: Expected " + valParse[v+ival] + " but got " + a
+                        + " on input " + s);
                 }
             }
             else {
@@ -965,7 +966,7 @@ NumberFormatTest::TestExponential(void)
                 {
                     logln((UnicodeString)"  -parse-> " + a);
                     if (a != lvalParse[v+ilval])
-                        errln((UnicodeString)"FAIL: Expected " + lvalParse[v+ilval]);
+                        errln((UnicodeString)"FAIL: Expected " + lvalParse[v+ilval] + " but got " + a);
                 }
                 else
                     errln((UnicodeString)"FAIL: Partial parse (" + pos.getIndex() + " chars) -> " + a);