From 95908ad92038341e3b6d3ba8dc7752141cbbd9f6 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 | 4 ++++ 2 files changed, 8 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..298cbbe8e4a 100644 --- a/test/Intl/PluralRules.js +++ b/test/Intl/PluralRules.js @@ -1,5 +1,6 @@ //------------------------------------------------------------------------------------------------------- // Copyright (C) Microsoft. All rights reserved. +// Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. //------------------------------------------------------------------------------------------------------- @@ -159,6 +160,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, "other"); + test({ maximumSignificantDigits: 1 }, -110.001, "other"); + test({ maximumSignificantDigits: 1 }, -1, "one"); // significantDigits should override fractionDigits and integerDigits test({ maximumSignificantDigits: 2, maximumFractionDigits: 0 }, 1.1, "other");