Skip to content

Commit

Permalink
Normative: Fix order of rounding* option reads and resolvedOptions()
Browse files Browse the repository at this point in the history
This PR are mostly Normative but have some editorial parts

1. Editorial: Add text to explain ComputedRoundingPriority in section
"15.4 Properties of Intl.NumberFormat Instances"
https://tc39.es/ecma402/#sec-properties-of-intl-numberformat-instances
and
"16.4 Properties of Intl.PluralRules Instances
https://tc39.es/ecma402/#sec-properties-of-intl-pluralrules-instances

2. Editorial: Add ComputedRoundingPriority to Intl.PluralRules
https://tc39.es/ecma402/#sec-intl.pluralrules
Without this, the spec is not implementable because InitializePluralRules
call "SetNumberFormatDigitOptions(pluralRules, options, +0𝔽, 3𝔽, "standard")."
and SetNumberFormatDigitOptions assume the intlObj has `[[ComputedRoundingPriority]]`

3. Normative: Move the reading of "roundingPriority" from before reading
   "roundingIncrement" to after reading "roundingMode" so these three
   fields are read in alphabetic order.
https://tc39.es/ecma402/#sec-setnfdigitoptions

4. Normative: Move the output order of "roundingIncrement" from after
   output "roundingMode" to before that so these two
   fields are read in alphabetic order in the resolvedOptions of both
   Intl.NumberFormat and Intl.PluralRules.
   https://tc39.es/ecma402/#sec-intl.numberformat.prototype.resolvedoptions
   https://tc39.es/ecma402/#sec-intl.pluralrules.prototype.resolvedoptions

5. Normative: Move the output of "roundingPriority" from after
   "trailingZeroDisplay" before that to sync w/ Intl.NumberFormat after
   PR768.
   https://tc39.es/ecma402/#sec-intl.pluralrules.prototype.resolvedoptions

6. Normative: Move the output of "pluralCategories" from after
   "trailingZeroDisplay" to before "roundingIncrement" so these options
   will be in alphabetic order.
   https://tc39.es/ecma402/#sec-intl.pluralrules.prototype.resolvedoptions
  • Loading branch information
FrankYFTang committed Jul 26, 2023
1 parent 0fbf16c commit 6f0db10
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
15 changes: 8 additions & 7 deletions spec/numberformat.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h1>Intl.NumberFormat ( [ _locales_ [ , _options_ ] ] )</h1>

<emu-alg>
1. If NewTarget is *undefined*, let _newTarget_ be the active function object, else let _newTarget_ be NewTarget.
1. Let _numberFormat_ be ? OrdinaryCreateFromConstructor(_newTarget_, *"%NumberFormat.prototype%"*, &laquo; [[InitializedNumberFormat]], [[Locale]], [[DataLocale]], [[NumberingSystem]], [[Style]], [[Unit]], [[UnitDisplay]], [[Currency]], [[CurrencyDisplay]], [[CurrencySign]], [[MinimumIntegerDigits]], [[MinimumFractionDigits]], [[MaximumFractionDigits]], [[MinimumSignificantDigits]], [[MaximumSignificantDigits]], [[RoundingType]], [[Notation]], [[CompactDisplay]], [[UseGrouping]], [[SignDisplay]], [[RoundingMode]], [[RoundingIncrement]], [[ComputedRoundingPriority]], [[TrailingZeroDisplay]], [[BoundFormat]] &raquo;).
1. Let _numberFormat_ be ? OrdinaryCreateFromConstructor(_newTarget_, *"%NumberFormat.prototype%"*, &laquo; [[InitializedNumberFormat]], [[Locale]], [[DataLocale]], [[NumberingSystem]], [[Style]], [[Unit]], [[UnitDisplay]], [[Currency]], [[CurrencyDisplay]], [[CurrencySign]], [[MinimumIntegerDigits]], [[MinimumFractionDigits]], [[MaximumFractionDigits]], [[MinimumSignificantDigits]], [[MaximumSignificantDigits]], [[RoundingType]], [[Notation]], [[CompactDisplay]], [[UseGrouping]], [[SignDisplay]], [[RoundingIncrement]], [[RoundingMode]], [[ComputedRoundingPriority]], [[TrailingZeroDisplay]], [[BoundFormat]] &raquo;).
1. Perform ? InitializeNumberFormat(_numberFormat_, _locales_, _options_).
1. If the implementation supports the normative optional constructor mode of <emu-xref href="#legacy-constructor"></emu-xref>, then
1. Let _this_ be the *this* value.
Expand Down Expand Up @@ -113,10 +113,10 @@ <h1>
1. Let _mnsd_ be ? Get(_options_, *"minimumSignificantDigits"*).
1. Let _mxsd_ be ? Get(_options_, *"maximumSignificantDigits"*).
1. Set _intlObj_.[[MinimumIntegerDigits]] to _mnid_.
1. Let _roundingPriority_ be ? GetOption(_options_, *"roundingPriority"*, ~string~, &laquo; *"auto"*, *"morePrecision"*, *"lessPrecision"* &raquo;, *"auto"*).
1. Let _roundingIncrement_ be ? GetNumberOption(_options_, *"roundingIncrement"*, 1, 5000, 1).
1. If _roundingIncrement_ is not in « 1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000, 2500, 5000 », throw a *RangeError* exception.
1. Let _roundingMode_ be ? GetOption(_options_, *"roundingMode"*, ~string~, &laquo; *"ceil"*, *"floor"*, *"expand"*, *"trunc"*, *"halfCeil"*, *"halfFloor"*, *"halfExpand"*, *"halfTrunc"*, *"halfEven"* &raquo;, *"halfExpand"*).
1. Let _roundingPriority_ be ? GetOption(_options_, *"roundingPriority"*, ~string~, &laquo; *"auto"*, *"morePrecision"*, *"lessPrecision"* &raquo;, *"auto"*).
1. Let _trailingZeroDisplay_ be ? GetOption(_options_, *"trailingZeroDisplay"*, ~string~, &laquo; *"auto"*, *"stripIfInteger"* &raquo;, *"auto"*).
1. NOTE: All fields required by SetNumberFormatDigitOptions have now been read from _options_. The remainder of this AO interprets the options and may throw exceptions.
1. If _roundingIncrement_ is not 1, set _mxfdDefault_ to _mnfdDefault_.
Expand Down Expand Up @@ -490,14 +490,14 @@ <h1>Intl.NumberFormat.prototype.resolvedOptions ( )</h1>
<td>[[SignDisplay]]</td>
<td>*"signDisplay"*</td>
</tr>
<tr>
<td>[[RoundingMode]]</td>
<td>*"roundingMode"*</td>
</tr>
<tr>
<td>[[RoundingIncrement]]</td>
<td>*"roundingIncrement"*</td>
</tr>
<tr>
<td>[[RoundingMode]]</td>
<td>*"roundingMode"*</td>
</tr>
<tr>
<td>[[ComputedRoundingPriority]]</td>
<td>*"roundingPriority"*</td>
Expand Down Expand Up @@ -547,8 +547,9 @@ <h1>Properties of Intl.NumberFormat Instances</h1>
[[SignDisplay]] is one of the String values *"auto"*, *"always"*, *"never"*, *"exceptZero"*, or *"negative"*, specifying when to include a sign (with non-*"auto"* options respectively corresponding with inclusion always, never, only for non-zero numbers, or only for non-zero negative numbers).
In scientific notation, this slot affects the sign display of the mantissa but not the exponent.
</li>
<li>[[RoundingMode]] is one of the String values in the Identifier column of <emu-xref href="#table-intl-rounding-modes"></emu-xref>, specifying which rounding mode to use.</li>
<li>[[RoundingIncrement]] is an integer-valued Number that evenly divides 10, 100, 1000, or 10000 into tenths, fifths, quarters, or halves. It indicates the increment at which rounding should take place relative to the calculated rounding magnitude. For example, if [[MaximumFractionDigits]] is 2 and [[RoundingIncrement]] is 5, then the number is rounded to the nearest 0.05 ("nickel rounding").</li>
<li>[[RoundingMode]] is one of the String values in the Identifier column of <emu-xref href="#table-intl-rounding-modes"></emu-xref>, specifying which rounding mode to use.</li>
<li>[[ComputedRoundingPriority]] is one of the String values *"auto"*, *"lessPrecision"*, or *"morePrecision"*, specifying the strategy to resolve mixed fraction digits and significant digits settings.</li>
<li>[[TrailingZeroDisplay]] is one of the String values *"auto"* or *"stripIfInteger"*, indicating whether to strip trailing zeros if the formatted number is an integer (i.e., has no non-zero fraction digit).</li>
</ul>

Expand Down
26 changes: 13 additions & 13 deletions spec/pluralrules.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h1>Intl.PluralRules ( [ _locales_ [ , _options_ ] ] )</h1>

<emu-alg>
1. If NewTarget is *undefined*, throw a *TypeError* exception.
1. Let _pluralRules_ be ? OrdinaryCreateFromConstructor(NewTarget, *"%PluralRules.prototype%"*, &laquo; [[InitializedPluralRules]], [[Locale]], [[Type]], [[MinimumIntegerDigits]], [[MinimumFractionDigits]], [[MaximumFractionDigits]], [[MinimumSignificantDigits]], [[MaximumSignificantDigits]], [[RoundingType]], [[RoundingMode]], [[RoundingIncrement]], [[TrailingZeroDisplay]] &raquo;).
1. Let _pluralRules_ be ? OrdinaryCreateFromConstructor(NewTarget, *"%PluralRules.prototype%"*, &laquo; [[InitializedPluralRules]], [[Locale]], [[Type]], [[MinimumIntegerDigits]], [[MinimumFractionDigits]], [[MaximumFractionDigits]], [[MinimumSignificantDigits]], [[MaximumSignificantDigits]], [[RoundingType]], [[RoundingIncrement]], [[RoundingMode]], [[ComputedRoundingPriority]], [[TrailingZeroDisplay]] &raquo;).
1. Return ? InitializePluralRules(_pluralRules_, _locales_, _options_).
</emu-alg>
</emu-clause>
Expand Down Expand Up @@ -172,19 +172,14 @@ <h1>Intl.PluralRules.prototype.resolvedOptions ( )</h1>
1. Let _pr_ be the *this* value.
1. Perform ? RequireInternalSlot(_pr_, [[InitializedPluralRules]]).
1. Let _options_ be OrdinaryObjectCreate(%Object.prototype%).
1. Let _pluralCategories_ be a List of Strings containing all possible results of <emu-xref href="#sec-pluralruleselect">PluralRuleSelect</emu-xref> for the selected locale _pr_.[[Locale]].
1. For each row of <emu-xref href="#table-pluralrules-resolvedoptions-properties"></emu-xref>, except the header row, in table order, do
1. Let _p_ be the Property value of the current row.
1. Let _v_ be the value of _pr_'s internal slot whose name is the Internal Slot value of the current row.
1. If _p_ is *"roundingIncrement"*, then
1. Perform ! CreateDataProperty(_options_, *"pluralCategories"*, CreateArrayFromList(_pluralCategories_)).
1. If _v_ is not *undefined*, then
1. Perform ! CreateDataPropertyOrThrow(_options_, _p_, _v_).
1. Let _pluralCategories_ be a List of Strings containing all possible results of <emu-xref href="#sec-pluralruleselect">PluralRuleSelect</emu-xref> for the selected locale _pr_.[[Locale]].
1. Perform ! CreateDataProperty(_options_, *"pluralCategories"*, CreateArrayFromList(_pluralCategories_)).
1. If _pr_.[[RoundingType]] is ~morePrecision~, then
1. Perform ! CreateDataPropertyOrThrow(_options_, *"roundingPriority"*, *"morePrecision"*).
1. Else if _pr_.[[RoundingType]] is ~lessPrecision~, then
1. Perform ! CreateDataPropertyOrThrow(_options_, *"roundingPriority"*, *"lessPrecision"*).
1. Else,
1. Perform ! CreateDataPropertyOrThrow(_options_, *"roundingPriority"*, *"auto"*).
1. Return _options_.
</emu-alg>

Expand Down Expand Up @@ -225,13 +220,17 @@ <h1>Intl.PluralRules.prototype.resolvedOptions ( )</h1>
<td>[[MaximumSignificantDigits]]</td>
<td>*"maximumSignificantDigits"*</td>
</tr>
<tr>
<td>[[RoundingIncrement]]</td>
<td>*"roundingIncrement"*</td>
</tr>
<tr>
<td>[[RoundingMode]]</td>
<td>*"roundingMode"*</td>
</tr>
<tr>
<td>[[RoundingIncrement]]</td>
<td>*"roundingIncrement"*</td>
<td>[[ComputedRoundingPriority]]</td>
<td>*"roundingPriority"*</td>
</tr>
<tr>
<td>[[TrailingZeroDisplay]]</td>
Expand Down Expand Up @@ -263,9 +262,10 @@ <h1>Properties of Intl.PluralRules Instances</h1>
<li>[[MinimumIntegerDigits]] is a non-negative integer Number value indicating the minimum integer digits to be used.</li>
<li>[[MinimumFractionDigits]] and [[MaximumFractionDigits]] are non-negative integer Number values indicating the minimum and maximum fraction digits to be used. Numbers will be rounded or padded with trailing zeroes if necessary.</li>
<li>[[MinimumSignificantDigits]] and [[MaximumSignificantDigits]] are positive integer Number values indicating the minimum and maximum fraction digits to be used. Either none or both of these properties are present; if they are, they override minimum and maximum integer and fraction digits.</li>
<li>[[RoundingType]] is one of the values ~fractionDigits~, ~significantDigits~, ~morePrecision~, or ~lessPrecision~, indicating which rounding strategy to use, as discussed in <emu-xref href="#sec-properties-of-intl-numberformat-instances"></emu-xref>.</li>
<li>[[RoundingMode]] is one of the String values in the Identifier column of <emu-xref href="#table-intl-rounding-modes"></emu-xref>, specifying which rounding mode to use.</li>
<li>[[RoundingIncrement]] is an integer-valued Number that evenly divides 10, 100, 1000, or 10000 into tenths, fifths, quarters, or halves. It indicates the increment at which rounding should take place relative to the calculated rounding magnitude. For example, if [[MaximumFractionDigits]] is 2 and [[RoundingIncrement]] is 5, then the number is rounded to the nearest 0.05 ("nickel rounding").</li>
<li>[[RoundingMode]] is one of the String values in the Identifier column of <emu-xref href="#table-intl-rounding-modes"></emu-xref>, specifying which rounding mode to use.</li>
<li>[[ComputedRoundingPriority]] is one of the String values *"auto"*, *"lessPrecision"*, or *"morePrecision"*, specifying the strategy to resolve mixed fraction digits and significant digits settings.</li>
<li>[[RoundingType]] is one of the values ~fractionDigits~, ~significantDigits~, ~morePrecision~, or ~lessPrecision~, indicating which rounding strategy to use, as discussed in <emu-xref href="#sec-properties-of-intl-numberformat-instances"></emu-xref>.</li>
<li>[[TrailingZeroDisplay]] is one of the String values *"auto"* or *"stripIfInteger"*, indicating whether to strip trailing zeros if the formatted number is an integer (i.e., has no non-zero fraction digit).</li>
</ul>
</emu-clause>
Expand Down

0 comments on commit 6f0db10

Please sign in to comment.