mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-10 07:39:16 +00:00
ICU-13725 Fixing various number test failures in MSVC.
X-SVN-Rev: 41281
This commit is contained in:
parent
acbdeaf98e
commit
e77603e3c3
5 changed files with 38 additions and 18 deletions
|
@ -380,7 +380,7 @@ DecimalQuantity &DecimalQuantity::setToDouble(double n) {
|
|||
setBcdToZero();
|
||||
flags = 0;
|
||||
// signbit() from <math.h> handles +0.0 vs -0.0
|
||||
if (std::signbit(n) != 0) {
|
||||
if (std::signbit(n)) {
|
||||
flags |= NEGATIVE_FLAG;
|
||||
n = -n;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include "numparse_types.h"
|
||||
#include "number_decimalquantity.h"
|
||||
#include "putilimp.h"
|
||||
#include <cmath>
|
||||
|
||||
using namespace icu;
|
||||
|
@ -57,7 +58,9 @@ double ParsedNumber::getDouble() const {
|
|||
|
||||
// Check for NaN, infinity, and -0.0
|
||||
if (sawNaN) {
|
||||
return NAN;
|
||||
// Can't use NAN or std::nan because the byte pattern is platform-dependent;
|
||||
// MSVC sets the sign bit, but Clang and GCC do not
|
||||
return uprv_getNaN();
|
||||
}
|
||||
if (sawInfinity) {
|
||||
if (0 != (flags & FLAG_NEGATIVE)) {
|
||||
|
@ -85,7 +88,9 @@ void ParsedNumber::populateFormattable(Formattable& output, parse_flags_t parseF
|
|||
|
||||
// Check for NaN, infinity, and -0.0
|
||||
if (sawNaN) {
|
||||
output.setDouble(NAN);
|
||||
// Can't use NAN or std::nan because the byte pattern is platform-dependent;
|
||||
// MSVC sets the sign bit, but Clang and GCC do not
|
||||
output.setDouble(uprv_getNaN());
|
||||
return;
|
||||
}
|
||||
if (sawInfinity) {
|
||||
|
|
|
@ -450,7 +450,7 @@ UBool NumberFormatTestDataDriven::isParsePass(
|
|||
}
|
||||
return TRUE;
|
||||
} else if (tuple.output == "-0.0") {
|
||||
if (std::signbit(result.getDouble()) == 0 || result.getDouble() != 0) {
|
||||
if (!std::signbit(result.getDouble()) || result.getDouble() != 0) {
|
||||
appendErrorMessage.append(UnicodeString("Expected -0.0, but got: ") + result.getDouble());
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -660,6 +660,7 @@ void NumberFormatTest::runIndexedTest( int32_t index, UBool exec, const char* &n
|
|||
TESTCASE_AUTO(TestParsePercentRegression);
|
||||
TESTCASE_AUTO(TestMultiplierWithScale);
|
||||
TESTCASE_AUTO(TestFastFormatInt32);
|
||||
TESTCASE_AUTO(TestParseNaN);
|
||||
TESTCASE_AUTO_END;
|
||||
}
|
||||
|
||||
|
@ -8313,7 +8314,7 @@ void NumberFormatTest::TestCurrencyUsage() {
|
|||
|
||||
UnicodeString original;
|
||||
fmt->format(agent,original);
|
||||
assertEquals("Test Currency Usage 1", UnicodeString("PKR\u00A0124"), original);
|
||||
assertEquals("Test Currency Usage 1", u"PKR\u00A0124", original);
|
||||
|
||||
// test the getter here
|
||||
UCurrencyUsage curUsage = fmt->getCurrencyUsage();
|
||||
|
@ -8333,7 +8334,7 @@ void NumberFormatTest::TestCurrencyUsage() {
|
|||
|
||||
UnicodeString cash_currency;
|
||||
fmt->format(agent,cash_currency);
|
||||
assertEquals("Test Currency Usage 2", UnicodeString("PKR\u00A0124"), cash_currency);
|
||||
assertEquals("Test Currency Usage 2", u"PKR\u00A0124", cash_currency);
|
||||
delete fmt;
|
||||
}
|
||||
|
||||
|
@ -8350,7 +8351,7 @@ void NumberFormatTest::TestCurrencyUsage() {
|
|||
|
||||
UnicodeString original_rounding;
|
||||
fmt->format(agent, original_rounding);
|
||||
assertEquals("Test Currency Usage 3", UnicodeString("CA$123.57"), original_rounding);
|
||||
assertEquals("Test Currency Usage 3", u"CA$123.57", original_rounding);
|
||||
fmt->setCurrencyUsage(UCURR_USAGE_CASH, &status);
|
||||
}else{
|
||||
fmt = (DecimalFormat *) NumberFormat::createInstance(enUS_CAD, UNUM_CASH_CURRENCY, status);
|
||||
|
@ -8361,7 +8362,7 @@ void NumberFormatTest::TestCurrencyUsage() {
|
|||
|
||||
UnicodeString cash_rounding_currency;
|
||||
fmt->format(agent, cash_rounding_currency);
|
||||
assertEquals("Test Currency Usage 4", UnicodeString("CA$123.55"), cash_rounding_currency);
|
||||
assertEquals("Test Currency Usage 4", u"CA$123.55", cash_rounding_currency);
|
||||
delete fmt;
|
||||
}
|
||||
|
||||
|
@ -8386,14 +8387,14 @@ void NumberFormatTest::TestCurrencyUsage() {
|
|||
UnicodeString cur_original;
|
||||
fmt->setCurrencyUsage(UCURR_USAGE_STANDARD, &status);
|
||||
fmt->format(agent, cur_original);
|
||||
assertEquals("Test Currency Usage 5", UnicodeString("CA$123.57"), cur_original);
|
||||
assertEquals("Test Currency Usage 5", u"CA$123.57", cur_original);
|
||||
|
||||
fmt->setCurrency(CUR_PKR, status);
|
||||
assertSuccess("Set currency to PKR", status);
|
||||
|
||||
UnicodeString PKR_changed;
|
||||
fmt->format(agent, PKR_changed);
|
||||
assertEquals("Test Currency Usage 6", UnicodeString("PKR\u00A0124"), PKR_changed);
|
||||
assertEquals("Test Currency Usage 6", u"PKR\u00A0124", PKR_changed);
|
||||
delete fmt;
|
||||
}
|
||||
}
|
||||
|
@ -9120,4 +9121,17 @@ void NumberFormatTest::TestFastFormatInt32() {
|
|||
}
|
||||
}
|
||||
|
||||
void NumberFormatTest::TestParseNaN() {
|
||||
IcuTestErrorCode status(*this, "TestParseNaN");
|
||||
|
||||
DecimalFormat df("0", { "en", status }, status);
|
||||
Formattable parseResult;
|
||||
df.parse(u"NaN", parseResult, status);
|
||||
assertEquals("NaN should parse successfully", NAN, parseResult.getDouble());
|
||||
assertFalse("Result NaN should be positive", std::signbit(parseResult.getDouble()));
|
||||
UnicodeString formatResult;
|
||||
df.format(parseResult.getDouble(), formatResult);
|
||||
assertEquals("NaN should round-trip", u"NaN", formatResult);
|
||||
}
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
|
|
@ -225,6 +225,7 @@ class NumberFormatTest: public CalendarTimeZoneTest {
|
|||
void TestParsePercentRegression();
|
||||
void TestMultiplierWithScale();
|
||||
void TestFastFormatInt32();
|
||||
void TestParseNaN();
|
||||
|
||||
private:
|
||||
UBool testFormattableAsUFormattable(const char *file, int line, Formattable &f);
|
||||
|
|
|
@ -201,15 +201,15 @@ void IntlTestDecimalFormatSymbols::testSymbols(/* char *par */)
|
|||
DecimalFormatSymbols sym(Locale::getUS(), status);
|
||||
|
||||
UnicodeString customDecSeperator("S");
|
||||
Verify(34.5, (UnicodeString)"00.00", sym, (UnicodeString)"34.50");
|
||||
Verify(34.5, u"00.00", sym, u"34.50");
|
||||
sym.setSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol, customDecSeperator);
|
||||
Verify(34.5, (UnicodeString)"00.00", sym, (UnicodeString)"34S50");
|
||||
sym.setSymbol(DecimalFormatSymbols::kPercentSymbol, (UnicodeString)"P");
|
||||
Verify(34.5, (UnicodeString)"00 %", sym, (UnicodeString)"3450 P");
|
||||
sym.setSymbol(DecimalFormatSymbols::kCurrencySymbol, (UnicodeString)"D");
|
||||
Verify(34.5, CharsToUnicodeString("\\u00a4##.##"), sym, (UnicodeString)"D 34.50");
|
||||
sym.setSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol, (UnicodeString)"|");
|
||||
Verify(3456.5, (UnicodeString)"0,000.##", sym, (UnicodeString)"3|456S5");
|
||||
Verify(34.5, u"00.00", sym, u"34S50");
|
||||
sym.setSymbol(DecimalFormatSymbols::kPercentSymbol, u"P");
|
||||
Verify(34.5, u"00 %", sym, u"3450 P");
|
||||
sym.setSymbol(DecimalFormatSymbols::kCurrencySymbol, u"D");
|
||||
Verify(34.5, u"\u00a4##.##", sym, u"D\u00a034.50");
|
||||
sym.setSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol, u"|");
|
||||
Verify(3456.5, u"0,000.##", sym, u"3|456S5");
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue