Skip to content

Commit

Permalink
Fix incorrect abort in EntryIntl_PluralRulesSelect
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rhuanjl committed Mar 22, 2021
1 parent c091b36 commit 95908ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/Runtime/Library/IntlEngineInterfaceExtensionObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3128,8 +3128,10 @@ DEFINE_ISXLOCALEAVAILABLE(PR, uloc)
}, scriptContext->GetRecycler(), &formattedN, &formattedNLength);

double nWithOptions = unum_parseDouble(*nf, reinterpret_cast<UChar *>(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;
Expand Down
4 changes: 4 additions & 0 deletions test/Intl/PluralRules.js
Original file line number Diff line number Diff line change
@@ -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.
//-------------------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 95908ad

Please # to comment.