From 7d992aaad75d17e1525f59192c86c953386e0086 Mon Sep 17 00:00:00 2001 From: rhuanjl Date: Sun, 21 Mar 2021 00:06:00 +0000 Subject: [PATCH] Fix incorrect abort in EntryIntl_PluralRulesSelect When rounding a number to "x significant figures" Rounding diff can be arbitrarily large There was an abort for rounding diffs > 1 invalid in many cases. --- lib/Runtime/Library/IntlEngineInterfaceExtensionObject.cpp | 6 ++++-- test/Intl/PluralRules.js | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/Runtime/Library/IntlEngineInterfaceExtensionObject.cpp b/lib/Runtime/Library/IntlEngineInterfaceExtensionObject.cpp index 321bd43aa67..d4434b535f1 100644 --- a/lib/Runtime/Library/IntlEngineInterfaceExtensionObject.cpp +++ b/lib/Runtime/Library/IntlEngineInterfaceExtensionObject.cpp @@ -3128,8 +3128,10 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc) }, scriptContext->GetRecycler(), &formattedN, &formattedNLength); double nWithOptions = unum_parseDouble(*nf, reinterpret_cast(formattedN), formattedNLength, nullptr, &status); - double roundtripDiff = n - nWithOptions; - ICU_ASSERT(status, roundtripDiff <= 1.0 && roundtripDiff >= -1.0); + + ICU_ASSERT(status, (n > 0.0 && nWithOptions <= n && nWithOptions >= 0.0) || + (n < 0.0 && nWithOptions >= n && nWithOptions <= 0) || + (n == 0.0 && nWithOptions == 0)); char16 *selected = nullptr; int selectedLength = 0; diff --git a/test/Intl/PluralRules.js b/test/Intl/PluralRules.js index c3262aad8c0..1986740c1a5 100644 --- a/test/Intl/PluralRules.js +++ b/test/Intl/PluralRules.js @@ -159,6 +159,9 @@ testRunner.runTests([ test({ maximumSignificantDigits: 1 }, 1.0, "one"); test({ maximumSignificantDigits: 1 }, 1.1, "one"); test({ maximumSignificantDigits: 1 }, 1.001, "one"); + test({ maximumSignificantDigits: 1 }, 110.001, "many"); + test({ maximumSignificantDigits: 1 }, -110.001, "many"); + test({ maximumSignificantDigits: 1 }, -1, "one"); // significantDigits should override fractionDigits and integerDigits test({ maximumSignificantDigits: 2, maximumFractionDigits: 0 }, 1.1, "other");