Skip to content

Commit

Permalink
Define AO to massage a potential Decimal128 value to an actual one
Browse files Browse the repository at this point in the history
  • Loading branch information
jessealama committed May 30, 2024
1 parent a39e4db commit 18865ce
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions spec.emu
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ location: https://github.com/tc39/proposal-decimal/
<li>a mathematical value</li>
</ul></li>
<li>_q_ is an integer satisfying -6176 ≤ _q_ ≤ 6111,</li>
<li>If _v_ is a mathematical value, then v × 10<sup>-_q_</sup> is an integer _n_ such that 0 < _n_ < 10<sup>34</sup></li>
<li>If _v_ is a mathematical value, then v × 10<sup>-_q_</sup> is an integer _n_ such that 0 < abs(_n_) < 10<sup>34</sup></li>
</ul>
</ul>
<p>The <dfn id="dfn-decimal128-mathematical-value">mathematical value</dfn> of a finite Decimal128 value _x_ = « _v_, _q_ »<sub>𝔻</sub> is defined as follows:</p>
Expand Down Expand Up @@ -247,6 +247,26 @@ location: https://github.com/tc39/proposal-decimal/
1. Return _O_.
</emu-alg>
</emu-clause>

<emu-clause id="sec-decimal128-d" type="abstract operation">
<h1>
EnsureDecimal128Value (
_coefficient_ : a mathematical value,
_intendedExponent_ : a mathematical value
): either a normal completion containing a Decimal128 value or a throw completion
</h1>
<dl class="header">
<dt>description</dt>
<dd>It attempts to convert the pair of arguments, which might be out of range when considered as a Decimal128 value, into a Decimal128 value, throwing an exception if the conversion cannot be done.</dd>
</dl>
<emu-alg>
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).
</emu-alg>
</emu-clause>
</emu-clause>

<emu-clause id="sec-the-decimal-constructor">
Expand Down Expand Up @@ -340,7 +360,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 <mark>Decimal128ValueToObject(« _d1_[0] + _d2_[0], min(_d1_[1], _d2_[1]) »)</mark>.
1. Return Decimal128ValueToObject(? EnsureDecimal128Value(_d1_[0] + _d2_[0], min(_d1_[1], _d2_[1]))).
</emu-alg>
</emu-clause>

Expand All @@ -362,7 +382,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 <mark>Decimal128ValueToObject(« d1[0] - d2[0], min(d1[1], d2[1]) »)</mark>.
1. Return Decimal128ValueToObject(? EnsureDecimal128Value(d1[0] - d2[0], min(d1[1], d2[1]))).
</emu-alg>
</emu-clause>

Expand All @@ -387,7 +407,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 <mark>Decimal128ValueToObject(« _d1_[0] × _d2_[0], min(_d1_[1], _d2_[1]) »)</mark>.
1. Return Decimal128ValueToObject(? EnsureDecimal128Value (_d1_[0] × _d2_[0], _d1_[1] + _d2_[1])).
</emu-alg>
</emu-clause>

Expand All @@ -403,7 +423,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 <mark>Decimal128ValueToObject(« _d1_[0] / _d2_[0], min(_d1_[1], _d2_[1]) »)</mark>.
1. Return Decimal128ValueToObject(? EnsureDecimal128Value(_d1_[0] / _d2_[0], min(_d1_[1], _d2_[1]))).</mark>.
</emu-alg>
</emu-clause>

Expand All @@ -419,7 +439,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 <mark>Decimal128ValueToObject(« _d1_[0] % _d2_[0], min(_d1_[1], _d2_[1]) »)</mark>.
1. Return Decimal128ValueToObject(? EnsureDecimal128Value(_d1_[0] % _d2_[0], _d1_[1] + _d2_[1])).
</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

0 comments on commit 18865ce

Please sign in to comment.