From 180a895ee05b7042cc647ef8b43c93df9f19f132 Mon Sep 17 00:00:00 2001 From: Jesse Alama Date: Thu, 30 May 2024 15:29:21 +0200 Subject: [PATCH] Pass in a Decimal128 rounding mode when massaging --- spec.emu | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/spec.emu b/spec.emu index 6394bf2b..c350eb7d 100644 --- a/spec.emu +++ b/spec.emu @@ -260,7 +260,8 @@ location: https://github.com/tc39/proposal-decimal/

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

@@ -271,8 +272,8 @@ location: https://github.com/tc39/proposal-decimal/ 1. If -6111 ≤ _intendedExponent_ ≤ 6176, then 1. If _coefficient_ × 10_intendedExponent_ is an integer _n_ such that 0 < abs(_n_) < 1034, 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_). @@ -372,7 +373,7 @@ location: https://github.com/tc39/proposal-decimal/ 1. If _d2_ is *+∞*𝔻, return Decimal128ValueToObject(*NaN*𝔻). 1. If _d2_ is *-∞*𝔻, return Decimal128ValueToObject(*-∞*𝔻). 1. Return Decimal128ValueToObject(*-∞*𝔻). - 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"*)). @@ -394,7 +395,7 @@ location: https://github.com/tc39/proposal-decimal/ 1. If _d2_ is *+∞*𝔻, return Decimal128ValueToObject(*-∞*𝔻). 1. If _d2_ is *-∞*𝔻, return Decimal128ValueToObject(*NaN*𝔻). 1. Return Decimal128ValueToObject(*-∞*𝔻). - 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"*)). @@ -419,7 +420,7 @@ location: https://github.com/tc39/proposal-decimal/ 1. If _d2_ is a zero Decimal128 value, return Decimal128ValueToObject(*NaN*𝔻). 1. If _d2_[0] < 0, return Decimal128ValueToObject(*+∞*𝔻). 1. Return Decimal128ValueToObject(*-∞*𝔻). - 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"*)). @@ -435,7 +436,7 @@ location: https://github.com/tc39/proposal-decimal/ 1. If _d1_ or _d2_ is *NaN*𝔻, return Decimal128ValueToObject(*NaN*𝔻). 1. If _d1_ is *+∞*𝔻 or *-∞*𝔻, return Decimal128ValueToObject(*NaN*𝔻). 1. If _d2_ is *-∞*𝔻 or *-∞*𝔻, return Decimal128ValueToObject(*NaN*𝔻). - 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"*)). @@ -451,7 +452,7 @@ location: https://github.com/tc39/proposal-decimal/ 1. If _d1_ or _d2_ is *NaN*𝔻, return Decimal128ValueToObject(*NaN*𝔻). 1. If _d1_ is *+∞*𝔻 or *-∞*𝔻, return Decimal128ValueToObject(*NaN*𝔻). 1. If _d1_ is *-∞*𝔻 or *-∞*𝔻, return Decimal128ValueToObject(*NaN*𝔻). - 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"*)).

The remainder operation specified here deviates from the IEEE 754 remainder operation. We follow the the remainder operation for Number rather than IEEE 754, which specifies that, for example, the remainder 46 and 10 is -4 rather than 6.

@@ -558,7 +559,7 @@ location: https://github.com/tc39/proposal-decimal/ 1. If _v_ is *-0*𝔻, return _O_. 1. Let _n_ be the integer such that v × 10-_q_ = _n_ and 0 < abs(_n_) < 1034. 1. Let _N_ be ? OrdinaryCreateFromConstructor(%Decimal128%, *"%Decimal128.prototype%"*, « [[Decimal128Data]] »). - 1. Set _N_.[[Decimal128Data]] to ? EnsureDecimal128Value(v × 10-_numFractionalDigits_, _q_ + _numFractionalDigits_). + 1. Set _N_.[[Decimal128Data]] to ? EnsureDecimal128Value(v × 10-_numFractionalDigits_, _q_ + _numFractionalDigits_, _roundingMode_). 1. Return _N_. @@ -636,7 +637,7 @@ location: https://github.com/tc39/proposal-decimal/ 1. Let _n_ be the integer such that v × 10-_q_ = _n_ and 0 < abs(_n_) < 1034. 1. Let _n1_ be the largest multiple of 10 such that _n_ - _n1_ is less than 10_precision_. 1. Let _v1_ be _v_ - (_n1_ / 10_precision_). - 1. Let _N_ be ? EnsureDecimal128Value(_v1_, _precision_). + 1. Let _N_ be ? EnsureDecimal128Value(_v1_, _precision_, *"halfEven"*). 1. Return Decimal128ToDecimalString(_N_).