Skip to content

Commit e7cb7aa

Browse files
committed
Always use significant digits as implicit understanding of precision
1 parent 631dc37 commit e7cb7aa

File tree

1 file changed

+16
-55
lines changed

1 file changed

+16
-55
lines changed

spec.emu

Lines changed: 16 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -413,62 +413,29 @@ location: https://github.com/tc39/proposal-decimal/
413413
<p>Decimal128.Amount values are intended to contain a Decimal128 value together with a precision, as well as information about how the precision that number should be understood. The two ways precision can be understood are in terms of fractional digits and significant digits.</p>
414414
</emu-intro>
415415

416-
<emu-clause id="sec-decimal128-amount-abstract-ops">
417-
<h1>Abstract Operations</h1>
418-
<emu-clause id="sec-decimal128-amount-aresameprecision" type="abstract operation">
419-
<h1>AreSamePrecision(
420-
_v_: a mathematical value,
421-
_significantDigits_: a non-negative integer,
422-
_fractionalDigits_: a non-negative integer
423-
): a Boolean value
424-
</h1>
425-
<dl class="header">
426-
<dt>description</dt>
427-
<dd>It computes whether the decimal string rendering of the given mathematical value is the same if expressed in terms of the given number of significant digits and the given number of fractional digits. Rounding may be necessary to make this determination; if so, the round-half-to-even method will be applied.</dd>
428-
</dl>
429-
<emu-alg>
430-
1. If _v_ < 0, set _v_ to -_v_.
431-
1. If _v_ = 0, then
432-
1. If _significantDigits_ = _fractionalDigits_, return *true*.
433-
1. Otherwise, return *false*.
434-
1. Let _whole_ be floor(_v_).
435-
1. Let _scaledByFractionalDigits_ be _v_ × 10<sup>_fractionalDigits_</sup>.
436-
1. Let _log10_ be the log-base-10 of _whole_.
437-
1. Let _numWholeDigits_ be floor(_log10_) + 1.
438-
1. If _numWholeDigits_ ≤ _significantDigits_, let _scaledBySignificantDigits_ be _v_ × 10<sup>_significantDigits_</sup>, else let _scaledBySignificantDigits_ be _v_ - _v_ × 10<sup>-_significantDigits_</sup>.
439-
1. Set _scaledBySignificantDigits_ to ApplyRoundingModeToPositive(_scaledBySignificantDigits_, *"halfEven"*).
440-
1. Set _scaledByFractionalDigits_ to ApplyRoundingModeToPositive(_scaledByFractionalDigits_, *"halfEven"*).
441-
1. If _scaledBySignificantDigits_ = _scaledByFractionalDigits_, return *true*.
442-
1. Otherwise, return *false*.
443-
</emu-alg>
444-
</emu-clause>
445-
</emu-clause>
446-
447416
<emu-clause id="sec-the-decimal128-amount-constructor">
448417
<h1>The Decimal128.Amount Constructor</h1>
449418
<p>The Decimal128.Amount constructor:</p>
450419
<ul>
451420
<li>is <dfn>%Decimal128Amount%</dfn>.</li>
452421
<li>is the initial value of the the *"Decimal128Amount"* property of the global object.</li>
453422
<li>creates and initializes a new Decimal128.Amount object when called as a constructor</li>
454-
<li>may be used as the value of an *extends* clause of a class definition. Subclass constructors that intend to inherit the specified Decimal128.Amount behaviour must include a *super* call to the Decimal128.Amount constructor to create and initialize the subclass instance with the [[Decimal128AmountData]], [[Decimal128AmountPrecision]], and [[Decimal128AmountPrecisionMode]] internal slots.</li>
423+
<li>may be used as the value of an *extends* clause of a class definition. Subclass constructors that intend to inherit the specified Decimal128.Amount behaviour must include a *super* call to the Decimal128.Amount constructor to create and initialize the subclass instance with the [[Decimal128AmountData]] and [[Decimal128AmountPrecision]] internal slots.</li>
455424
</ul>
456425
<emu-clause id="sec-the-decimal128-amount-constructor-value">
457-
<h1>Decimal128.Amount ( _s_, _precision_, _mode_ )</h1>
426+
<h1>Decimal128.Amount ( _s_, _precision_ )</h1>
458427
<emu-alg>
459428
1. If NewTarget is *undefined*, throw a *TypeError* exception.
460429
1. If _s_ is not a String, throw a *TypeError* exception.
461430
1. If _precision_ is not a Number, throw a *TypeError* exception.
462431
1. If _precision_ is *NaN*<sub>𝔽</sub>, *+∞*<sub>𝔽</sub> or *+∞*<sub>𝔽</sub>, throw a *RangeError* exception.
463432
1. If ℝ(_precision_) < 0, throw a *RangeError* exception.
464433
1. If ℝ(_precision_) is not an integer, throw a *RangeError* exception.
465-
1. If _mode_ is not a String, throw a *TypeError* exception.
466-
1. If _mode_ is not one of « *"fractionalDigits"*, *"significantDigits"* », throw a *RangeError* exception.
434+
1. If ℝ(_precision_) > 34, throw a *RangeError* exception.
467435
1. Let _decimal_ be ? Construct(%Decimal128%, _s_).
468-
1. Let _O_ be ? OrdinaryCreateFromConstructor(NewTarget, *"%Decimal128Amount.prototype%"*, « [[Decimal128AmountData]], [[Decimal128AmountPrecision]], [[Decimal128AmountPrecisionMode]] »).
436+
1. Let _O_ be ? OrdinaryCreateFromConstructor(NewTarget, *"%Decimal128Amount.prototype%"*, « [[Decimal128AmountData]], [[Decimal128AmountPrecision]] »).
469437
1. Set _O_.[[Decimal128AmountData]] to _decimal_.[[Decimal128Data]].
470438
1. Set _O_.[[Decimal128AmountPrecision]] to _precision_.
471-
1. Set _O_.[[Decimal128AmountPrecisionMode]] to _mode_.
472439
1. Return _O_.
473440
</emu-alg>
474441
</emu-clause>
@@ -1147,9 +1114,17 @@ location: https://github.com/tc39/proposal-decimal/
11471114
<emu-alg>
11481115
1. Let _O_ be the *this* value.
11491116
1. Perform ? RequireInternalSlot(_O_, [[Decimal128Data]]).
1117+
1. If _n_ is not a Number, throw a *TypeError* exception.
1118+
1. If ℝ(_n_) < 0, throw a *RangeError* exception.
1119+
1. If ℝ(_n_) is not an integer, throw a *RangeError* exception.
11501120
1. Let _d_ be _O_.[[Decimal128Data]].
1121+
1. Assert: _d_ is a mathematical value.
1122+
1. If _d_ = 0, return ? Construct(%Decimal128Amount%, « *"0", _n_ * »).
11511123
1. Let _s_ be Decimal128ToDecimalString(_d_).
1152-
1. Return ? Construct(%Decimal128Amount%, « _s_, _n_, *"fractionalDigits"* »).
1124+
1. Let _l_ be log-10 of |_d_|.
1125+
1. Let _numIntegerDigits_ be _l_ + 1.
1126+
1. Let _newPrecision_ be _numIntegerDigits_ - ℝ(_n_).
1127+
1. Return ? Construct(%Decimal128Amount%, « _s_, 𝔽(_newPrecision_) »).
11531128
</emu-alg>
11541129
</emu-clause>
11551130

@@ -1162,7 +1137,7 @@ location: https://github.com/tc39/proposal-decimal/
11621137
1. Perform ? RequireInternalSlot(_O_, [[Decimal128Data]]).
11631138
1. Let _d_ be _O_.[[Decimal128Data]].
11641139
1. Let _s_ be Decimal128ToDecimalString(_d_).
1165-
1. Return ? Construct(%Decimal128Amount%, « _s_, _n_, *"significantDigits"* »).
1140+
1. Return ? Construct(%Decimal128Amount%, « _s_, _n_ »).
11661141
</emu-alg>
11671142
</emu-clause>
11681143

@@ -1186,35 +1161,21 @@ location: https://github.com/tc39/proposal-decimal/
11861161
1. Let _O_ be the *this* value.
11871162
1. Perform ? RequireInternalSlot(_O_, [[Decimal128AmountData]]).
11881163
1. Perform ? RequireInternalSlot(_O_, [[Decimal128AmountPrecision]]).
1189-
1. Perform ? RequireInternalSlot(_O_, [[Decimal128AmountPrecisionMode]]).
11901164
1. Perform ? RequireInternalSlot(_x_, [[Decimal128AmountData]]).
11911165
1. Perform ? RequireInternalSlot(_x_, [[Decimal128AmountPrecision]]).
1192-
1. Perform ? RequireInternalSlot(_x_, [[Decimal128AmountPrecisionMode]]).
11931166
1. Let _d1_ be _O_.[[Decimal128AmountData]].
11941167
1. Let _d2_ be _x_.[[Decimal128AmountData]].
11951168
1. Assert: _d1_ is a finite Decimal128 value.
11961169
1. Assert: _d2_ is a finite Decimal128 value.
11971170
1. If _d1_ is either *+0*<sub>𝔻</sub> or *-0*<sub>𝔻</sub>, set _d1_ to 0.
11981171
1. If _d2_ is either *+0*<sub>𝔻</sub> or *-0*<sub>𝔻</sub>, set _d2_ to 0.
11991172
1. If _d1_ ≠ _d2_, return *false*.
1200-
1. Let _mode1_ be _O_.[[Decimal128AmountPrecisionMode]].
1201-
1. Let _mode2_ be _x_.[[Decimal128AmountPrecisionMode]].
1202-
1. Assert: _mode1_ is one of « *"fractionalDigits"*, *"significantDigits"* ».
1203-
1. Assert: _mode2_ is one of « *"fractionalDigits"*, *"significantDigits"* ».
12041173
1. Let _precision1_ be _O_.[[Decimal128AmountPrecision]].
12051174
1. Let _precision2_ be _x_.[[Decimal128AmountPrecision]].
12061175
1. Assert: _precision1_ is a non-negative integer.
12071176
1. Assert: _precision2_ is a non-negative integer.
1208-
1. If _mode1_ is *"fractionalDigits"*, then
1209-
1. If _mode2_ is *"fractionalDigits"*, then
1210-
1. If _precision1_ = _precision2_, return *true*.
1211-
1. Otherwise, return *false*.
1212-
1. Otherwise:
1213-
1. Return AreSamePrecision(_d1_, _precision2_, _precision1_).
1214-
1. Otherwise:
1215-
1. If _mode2_ is *"fractionalDigits"*, return AreSamePrecision(_d1_, _precision1_, _precision2_).
1216-
1. Else if _precision1_ = _precision2_, return *true*.
1217-
1. Otherwise, return *false*.
1177+
1. If _precision1_ = _precision2_, return *true*.
1178+
1. Otherwise, return *false*.
12181179
</emu-alg>
12191180
</emu-clause>
12201181
</emu-clause>

0 commit comments

Comments
 (0)