From: Shane Carr Date: Wed, 27 Sep 2017 03:21:29 +0000 (+0000) Subject: ICU-13177 Fixing minor NumberTest unit test failures. X-Git-Tag: release-60-rc~98^2~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c55bf3d8bf960de336d69a3538c508de367f9d49;p=icu ICU-13177 Fixing minor NumberTest unit test failures. X-SVN-Rev: 40469 --- diff --git a/icu4c/source/i18n/number_decimalquantity.cpp b/icu4c/source/i18n/number_decimalquantity.cpp index a355f96d3f1..b9ede4117c5 100644 --- a/icu4c/source/i18n/number_decimalquantity.cpp +++ b/icu4c/source/i18n/number_decimalquantity.cpp @@ -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(static_cast(a) - static_cast(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) { diff --git a/icu4c/source/test/intltest/numbertest_decimalquantity.cpp b/icu4c/source/test/intltest/numbertest_decimalquantity.cpp index 322480869ef..b135a255804 100644 --- a/icu4c/source/test/intltest/numbertest_decimalquantity.cpp +++ b/icu4c/source/test/intltest/numbertest_decimalquantity.cpp @@ -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()); } }