Skip to content

Commit

Permalink
Pass in a Decimal128 rounding mode when massaging
Browse files Browse the repository at this point in the history
  • Loading branch information
jessealama committed May 30, 2024
1 parent d7bc702 commit 180a895
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions spec.emu
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ location: https://github.com/tc39/proposal-decimal/
<h1>
EnsureDecimal128Value (
_coefficient_ : a mathematical value,
_intendedExponent_ : a mathematical value
_intendedExponent_ : a mathematical value,
_roundingMode_: a Decimal128 rounding mode
): either a normal completion containing a Decimal128 value or a throw completion
</h1>
<dl class="header">
Expand All @@ -271,8 +272,8 @@ location: https://github.com/tc39/proposal-decimal/
1. If -6111 ≤ _intendedExponent_ ≤ 6176, then
1. If _coefficient_ × 10<sup>_intendedExponent_</sup> is an integer _n_ such that 0 < abs(_n_) < 10<sup>34</sup>, return « _coefficient, _intendedExponent_ ».
1. Throw a *RangeError* exception.
1. If _intendedExponent_ < 0, return ? EnsureDecimal128Value(_coefficient_ / 10, _intendedExponent_ + 1).
1. Return ? EnsureDecimal128Value(_coefficient_ × 10, _intendedExponent_ + 1).
1. If _intendedExponent_ < 0, return ? EnsureDecimal128Value(_coefficient_ / 10, _intendedExponent_ + 1, _roundingMode_).
1. Return ? EnsureDecimal128Value(_coefficient_ × 10, _intendedExponent_ + 1, _roundingMode_).
</emu-alg>
</emu-clause>
</emu-clause>
Expand Down Expand Up @@ -372,7 +373,7 @@ location: https://github.com/tc39/proposal-decimal/
1. If _d2_ is *+∞*<sub>𝔻</sub>, return Decimal128ValueToObject(*NaN*<sub>𝔻</sub>).
1. If _d2_ is *-∞*<sub>𝔻</sub>, return Decimal128ValueToObject(*-∞*<sub>𝔻</sub>).
1. Return Decimal128ValueToObject(*-∞*<sub>𝔻</sub>).
1. Return Decimal128ValueToObject(? EnsureDecimal128Value(_d1_[0] + _d2_[0], min(_d1_[1], _d2_[1]))).
1. Return Decimal128ValueToObject(? EnsureDecimal128Value(_d1_[0] + _d2_[0], min(_d1_[1], _d2_[1]), *"halfEven"*)).
</emu-alg>
</emu-clause>

Expand All @@ -394,7 +395,7 @@ location: https://github.com/tc39/proposal-decimal/
1. If _d2_ is *+∞*<sub>𝔻</sub>, return Decimal128ValueToObject(*-∞*<sub>𝔻</sub>).
1. If _d2_ is *-∞*<sub>𝔻</sub>, return Decimal128ValueToObject(*NaN*<sub>𝔻</sub>).
1. Return Decimal128ValueToObject(*-∞*<sub>𝔻</sub>).
1. Return Decimal128ValueToObject(? EnsureDecimal128Value(d1[0] - d2[0], min(d1[1], d2[1]))).
1. Return Decimal128ValueToObject(? EnsureDecimal128Value(d1[0] - d2[0], min(d1[1], d2[1]), *"halfEven"*)).
</emu-alg>
</emu-clause>

Expand All @@ -419,7 +420,7 @@ location: https://github.com/tc39/proposal-decimal/
1. If _d2_ is a zero Decimal128 value, return Decimal128ValueToObject(*NaN*<sub>𝔻</sub>).
1. If _d2_[0] < 0, return Decimal128ValueToObject(*+∞*<sub>𝔻</sub>).
1. Return Decimal128ValueToObject(*-∞*<sub>𝔻</sub>).
1. Return Decimal128ValueToObject(? EnsureDecimal128Value (_d1_[0] × _d2_[0], _d1_[1] + _d2_[1])).
1. Return Decimal128ValueToObject(? EnsureDecimal128Value (_d1_[0] × _d2_[0], _d1_[1] + _d2_[1], *"halfEven"*)).
</emu-alg>
</emu-clause>

Expand All @@ -435,7 +436,7 @@ location: https://github.com/tc39/proposal-decimal/
1. If _d1_ or _d2_ is *NaN*<sub>𝔻</sub>, return Decimal128ValueToObject(*NaN*<sub>𝔻</sub>).
1. If _d1_ is *+∞*<sub>𝔻</sub> or *-∞*<sub>𝔻</sub>, return Decimal128ValueToObject(*NaN*<sub>𝔻</sub>).
1. If _d2_ is *-∞*<sub>𝔻</sub> or *-∞*<sub>𝔻</sub>, return Decimal128ValueToObject(*NaN*<sub>𝔻</sub>).
1. Return Decimal128ValueToObject(? EnsureDecimal128Value(_d1_[0] / _d2_[0], _d1_[1] + _d2_[1])).
1. Return Decimal128ValueToObject(? EnsureDecimal128Value(_d1_[0] / _d2_[0], _d1_[1] + _d2_[1], *"halfEven"*)).
</emu-alg>
</emu-clause>

Expand All @@ -451,7 +452,7 @@ location: https://github.com/tc39/proposal-decimal/
1. If _d1_ or _d2_ is *NaN*<sub>𝔻</sub>, return Decimal128ValueToObject(*NaN*<sub>𝔻</sub>).
1. If _d1_ is *+∞*<sub>𝔻</sub> or *-∞*<sub>𝔻</sub>, return Decimal128ValueToObject(*NaN*<sub>𝔻</sub>).
1. If _d1_ is *-∞*<sub>𝔻</sub> or *-∞*<sub>𝔻</sub>, return Decimal128ValueToObject(*NaN*<sub>𝔻</sub>).
1. Return Decimal128ValueToObject(? EnsureDecimal128Value(_d1_[0] % _d2_[0], _d1_[1] + _d2_[1])).
1. Return Decimal128ValueToObject(? EnsureDecimal128Value(_d1_[0] % _d2_[0], _d1_[1] + _d2_[1], *"halfEven"*)).
</emu-alg>
<emu-note>
<p>The remainder operation specified here deviates from the IEEE 754 remainder operation. We follow the <emu-xref href="#sec-numeric-types-number-remainder">the remainder operation for Number</emu-xref> rather than IEEE 754, which specifies that, for example, the remainder 46 and 10 is -4 rather than 6.</p>
Expand Down Expand Up @@ -558,7 +559,7 @@ location: https://github.com/tc39/proposal-decimal/
1. If _v_ is *-0*<sub>𝔻</sub>, return _O_.
1. Let _n_ be the integer such that v × 10<sup>-_q_</sup> = _n_ and 0 < abs(_n_) < 10<sup>34</sup>.
1. Let _N_ be ? OrdinaryCreateFromConstructor(%Decimal128%, *"%Decimal128.prototype%"*, « [[Decimal128Data]] »).
1. Set _N_.[[Decimal128Data]] to ? EnsureDecimal128Value(v × 10<sup>-_numFractionalDigits_</sup>, _q_ + _numFractionalDigits_).
1. Set _N_.[[Decimal128Data]] to ? EnsureDecimal128Value(v × 10<sup>-_numFractionalDigits_</sup>, _q_ + _numFractionalDigits_, _roundingMode_).
1. Return _N_.
</emu-alg>
<emu-note>
Expand Down Expand Up @@ -636,7 +637,7 @@ location: https://github.com/tc39/proposal-decimal/
1. Let _n_ be the integer such that v × 10<sup>-_q_</sup> = _n_ and 0 < abs(_n_) < 10<sup>34</sup>.
1. Let _n1_ be the largest multiple of 10 such that _n_ - _n1_ is less than 10<sup>_precision_</sup>.
1. Let _v1_ be _v_ - (_n1_ / 10<sup>_precision_</sup>).
1. Let _N_ be ? EnsureDecimal128Value(_v1_, _precision_).
1. Let _N_ be ? EnsureDecimal128Value(_v1_, _precision_, *"halfEven"*).
1. Return Decimal128ToDecimalString(_N_).
</emu-alg>
</emu-clause>
Expand Down

0 comments on commit 180a895

Please sign in to comment.