Skip to content

Commit 85c1d7c

Browse files
committed
constructor: Don't round unless we have to
Unless `significantDigits` or `fractionDigits` is set, we don't need to round. Let's just keep the unrounded mathematical value, and round only if necessary.
1 parent f8133ce commit 85c1d7c

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

spec.emu

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,7 @@ location: https://github.com/tc39/proposal-measure/
160160
1. If _roundingMode_ is *"ceil"*, set _reverseRoundingMode_ to *"floor"*.
161161
1. Let _d_ be RoundToAmountDomain(–_v_, _reverseRoundingMode_).
162162
1. Return –_d_.
163-
1. Let _e_ be the unique integer such that 10<sup>_e_</sup> ≤ _v_ < 10<sup>_e_+1</sup>.
164-
1. Let _m_ be _v_ × 10<sup>–_e_</sup>.
165-
1. Let _rounded_ be ApplyRoundingModeToPositive(_m_, _roundingMode_).
166-
1. Return _rounded_ × 10<sup>_e_</sup>.
163+
1. Return ApplyRoundingModeToPositive(_m_, _roundingMode_).
167164
</emu-alg>
168165
</emu-clause>
169166

@@ -260,6 +257,7 @@ location: https://github.com/tc39/proposal-measure/
260257
1. Otherwise, if _x_ is a String, set _toParse_ to _x_.
261258
1. If _toParse_ is not a String, throw a *TypeError* exception.
262259
1. If _toParse_ is in « *"NaN"*, *"Infinity"*, *"-Infinity"* », throw a *RangeError* exception.
260+
1. Set _opts_ to GetOptionsObject(_opts_).
263261
1. Let _roundingMode_ be ? GetOption(_opts_, *"roundingMode"*, ~string~, « *"ceil"*, *"floor"*, *"expand"*, *"trunc"*, *"halfCeil"*, *"halfFloor"*, *"halfExpand"*, *"halfTrunc"*, *"halfEven"* », *"halfEven"*).
264262
1. Let _unit_ be ? GetOption(_opts_, *"unit"*, ~string~, ~empty~, *undefined*).
265263
1. Let _currency_ be ? GetOption(_opts_, *"currency"*, ~string~, ~empty~, *undefined*).
@@ -279,19 +277,19 @@ location: https://github.com/tc39/proposal-measure/
279277
1. Let _parseResult_ be ParseText(_toParse_, |StrDecimalLiteral|).
280278
1. If _parseResult_ is a List of errors, throw a *SyntaxError* exception.
281279
1. Let _amountValue_ be ? StringDecimalValue of _parseResult_.
282-
1. Let _roundedAmountValue_ be RoundToAmountDomain(_amountValue_, _roundingMode_).
280+
1. Let _roundedValue_ be _amountValue_.
283281
1. If both _significantDigits_ and _fractionDigits_ are *undefined*, then
284282
1. Set _significantDigits_ to CountSignificantDigits(_toParse_).
285283
1. Set _fractionDigits_ to CountFractionDigits(_toParse_).
286284
1. Else if _significantDigits_ is *undefined*, then
287-
1. Set _roundedAmountValue_ be RoundToFractionalDigits(_amountValue_, _fractionDigits_, _roundingMode_).
288-
1. Let _digitStr_ be the unique decimal string representation of _roundedAmountValue_ without leading zeroes.
285+
1. Set _roundedValue_ be RoundToFractionalDigits(_amountValue_, _fractionDigits_, _roundingMode_).
286+
1. Let _digitStr_ be the unique decimal string representation of _roundedValue_ without leading zeroes.
289287
1. Set _significantDigits_ to CountSignificantDigits(_digitStr_).
290288
1. Otherwise:
291-
1. Set _roundedAmountValue_ be RoundToSignificantDigits(_amountValue_, _significantDigits_, _roundingMode_).
292-
1. Let _digitStr_ be the unique decimal string representation of _roundedAmountValue_ without leading zeroes.
289+
1. Set _roundedValue_ be RoundToSignificantDigits(_amountValue_, _significantDigits_, _roundingMode_).
290+
1. Let _digitStr_ be the unique decimal string representation of _roundedValue_ without leading zeroes.
293291
1. Set _fractionDigits_ to CountFractionDigits(_digitStr_).
294-
1. Set _O_.[[Value]] to _roundedAmountValue_.
292+
1. Set _O_.[[Value]] to _roundedValue_.
295293
1. Set _O_.[[SignificantDigits]] to _significantDigits_.
296294
1. Set _O_.[[FractionDigits]] to _fractionDigits_.
297295
1. If _unit_ is a String, set _O_.[[Unit]] to toLowercase(StringToCodePoints(_unit_)).

0 commit comments

Comments
 (0)