Skip to content

Commit 7344f42

Browse files
authored
Normative: Updated the following Intl.PluralRules AOs to take Intl (#1026)
mathematical values rather than Numbers: * `ResolvePlural` * `ResolvePluralRange` This brings `Intl.PluralRules`'s behaviour into alignment with `Intl.NumberFormat`'s. Making this change has the following benefits: * Allows `Intl.PluralRules` to handle BigInts as well as numbers * Use of `ToIntlMathematicalValue` AO allows exact decimal values to be represented
1 parent f4012d7 commit 7344f42

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

spec/pluralrules.html

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ <h1>Intl.PluralRules.prototype.select ( _value_ )</h1>
219219
<emu-alg>
220220
1. Let _pr_ be the *this* value.
221221
1. Perform ? RequireInternalSlot(_pr_, [[InitializedPluralRules]]).
222-
1. Let _n_ be ? ToNumber(_value_).
222+
1. Let _n_ be ? ToIntlMathematicalValue(_value_).
223223
1. Return ResolvePlural(_pr_, _n_).[[PluralCategory]].
224224
</emu-alg>
225225
</emu-clause>
@@ -233,8 +233,8 @@ <h1>Intl.PluralRules.prototype.selectRange ( _start_, _end_ )</h1>
233233
1. Let _pr_ be the *this* value.
234234
1. Perform ? RequireInternalSlot(_pr_, [[InitializedPluralRules]]).
235235
1. If _start_ is *undefined* or _end_ is *undefined*, throw a *TypeError* exception.
236-
1. Let _x_ be ? ToNumber(_start_).
237-
1. Let _y_ be ? ToNumber(_end_).
236+
1. Let _x_ be ? ToIntlMathematicalValue(_start_).
237+
1. Let _y_ be ? ToIntlMathematicalValue(_end_).
238238
1. Return ? ResolvePluralRange(_pr_, _x_, _y_).
239239
</emu-alg>
240240
</emu-clause>
@@ -295,18 +295,24 @@ <h1>
295295
<h1>
296296
ResolvePlural (
297297
_pluralRules_: an Intl.PluralRules,
298-
_n_: a Number,
298+
_n_: an Intl mathematical value,
299299
): a Record with fields [[PluralCategory]] (*"zero"*, *"one"*, *"two"*, *"few"*, *"many"*, or *"other"*) and [[FormattedString]] (a String)
300300
</h1>
301301
<dl class="header">
302302
<dt>description</dt>
303303
<dd>The returned Record contains two string-valued fields describing _n_ according to the effective locale and the options of _pluralRules_: [[PluralCategory]] characterizing its <emu-xref href="#sec-pluralruleselect">plural category</emu-xref>, and [[FormattedString]] containing its formatted representation.</dd>
304304
</dl>
305305
<emu-alg>
306-
1. If _n_ is not a finite Number, then
307-
1. Let _s_ be ! ToString(_n_).
306+
1. If _n_ is ~not-a-number~, then
307+
1. Let _s_ be an ILD String value indicating the *NaN* value.
308308
1. Return the Record { [[PluralCategory]]: *"other"*, [[FormattedString]]: _s_ }.
309-
1. Let _res_ be FormatNumericToString(_pluralRules_, ℝ(_n_)).
309+
1. If _n_ is ~positive-infinity~, then
310+
1. Let _s_ be an ILD String value indicating positive infinity.
311+
1. Return the Record { [[PluralCategory]]: *"other"*, [[FormattedString]]: _s_ }.
312+
1. If _n_ is ~negative-infinity~, then
313+
1. Let _s_ be an ILD String value indicating negative infinity.
314+
1. Return the Record { [[PluralCategory]]: *"other"*, [[FormattedString]]: _s_ }.
315+
1. Let _res_ be FormatNumericToString(_pluralRules_, _n_).
310316
1. Let _s_ be _res_.[[FormattedString]].
311317
1. Let _locale_ be _pluralRules_.[[Locale]].
312318
1. Let _type_ be _pluralRules_.[[Type]].
@@ -338,16 +344,16 @@ <h1>
338344
<h1>
339345
ResolvePluralRange (
340346
_pluralRules_: an Intl.PluralRules,
341-
_x_: a Number,
342-
_y_: a Number,
347+
_x_: an Intl mathematical value,
348+
_y_: an Intl mathematical value,
343349
): either a normal completion containing either *"zero"*, *"one"*, *"two"*, *"few"*, *"many"*, or *"other"*, or a throw completion
344350
</h1>
345351
<dl class="header">
346352
<dt>description</dt>
347353
<dd>The returned String value represents the plural form of the range starting from _x_ and ending at _y_ according to the effective locale and the options of _pluralRules_.</dd>
348354
</dl>
349355
<emu-alg>
350-
1. If _x_ is *NaN* or _y_ is *NaN*, throw a *RangeError* exception.
356+
1. If _x_ is ~not-a-number~ or _y_ is ~not-a-number~, throw a *RangeError* exception.
351357
1. Let _xp_ be ResolvePlural(_pluralRules_, _x_).
352358
1. Let _yp_ be ResolvePlural(_pluralRules_, _y_).
353359
1. If _xp_.[[FormattedString]] is _yp_.[[FormattedString]], then

0 commit comments

Comments
 (0)