]> granicus.if.org Git - icu/commitdiff
ICU-13177 Fixing minor NumberTest unit test failures.
authorShane Carr <shane@unicode.org>
Wed, 27 Sep 2017 03:21:29 +0000 (03:21 +0000)
committerShane Carr <shane@unicode.org>
Wed, 27 Sep 2017 03:21:29 +0000 (03:21 +0000)
X-SVN-Rev: 40469

icu4c/source/i18n/number_decimalquantity.cpp
icu4c/source/test/intltest/numbertest_decimalquantity.cpp

index a355f96d3f1b2008ebb144497017c921c0c2ea5a..b9ede4117c558bb903a8645017d8effc041f520d 100644 (file)
@@ -33,7 +33,8 @@ void stringToDecNumber(StringPiece n, decNumber &dn) {
 
 /** Helper function for safe subtraction (no overflow). */
 inline int32_t safeSubtract(int32_t a, int32_t b) {
-    int32_t diff = a - b;
+    // Note: In C++, signed integer subtraction is undefined behavior.
+    int32_t diff = static_cast<int32_t>(static_cast<uint32_t>(a) - static_cast<uint32_t>(b));
     if (b < 0 && diff < a) { return INT32_MAX; }
     if (b > 0 && diff > a) { return INT32_MIN; }
     return diff;
@@ -153,7 +154,7 @@ void DecimalQuantity::roundToIncrement(double roundingIncrement, RoundingMode ro
     setToDouble(temp);
     // Since we reset the value to a double, we need to specify the rounding boundary
     // in order to get the DecimalQuantity out of approximation mode.
-    roundToMagnitude(minMaxFrac, roundingMode, status);
+    roundToMagnitude(-minMaxFrac, roundingMode, status);
 }
 
 void DecimalQuantity::multiplyBy(int32_t multiplicand) {
index 322480869efbd0e3c8ff9480175f324cb3c04943..b135a255804c7d049938238b02c04670dbeb36fb 100644 (file)
@@ -33,9 +33,9 @@ void DecimalQuantityTest::assertDoubleEquals(const char *message, double a, doub
 }
 
 void DecimalQuantityTest::assertHealth(const DecimalQuantity &fq) {
-    UnicodeString health = fq.checkHealth();
-    if (!health.isBogus()) {
-        errln(UnicodeString("HEALTH FAILURE: ") + fq.toString());
+    const char16_t* health = fq.checkHealth();
+    if (health != nullptr) {
+        errln(UnicodeString(u"HEALTH FAILURE: ") + UnicodeString(health) + u": " + fq.toString());
     }
 }