From b2aaa9ba3c9540709da358e33b433bf4527d21a9 Mon Sep 17 00:00:00 2001 From: Jesse Alama Date: Tue, 23 Sep 2025 10:29:19 +0200 Subject: [PATCH 01/12] toString: Fix bug in emitting exponential notation --- spec.emu | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/spec.emu b/spec.emu index 4906980..df2503b 100644 --- a/spec.emu +++ b/spec.emu @@ -318,25 +318,21 @@ location: https://github.com/tc39/proposal-amount/ 1. Set _v_ to -_v_. 1. Set _roundingMode_ to ReverseRoundingMode(_roundingMode_). 1. Let _rounded_ be ApplyRoundingModeToPositive(_v_ × 10_numDigits_, _roundingMode_). - 1. Let _e_ be the smallest non-negative integer such that _rounded_ × 10-_numDigits_ is an integer. + 1. Let _e_ be the smallest non-negative integer such that _rounded_ × 10-_e_ is an integer. 1. Let _s_ be the unique decimal string representation of _rounded_ without duplicate leading zeroes. - 1. If _numDigits_ > _e_, then + 1. If _e_ < numDigits_, then 1. If _v_ is an integer, return the string-concatenation of _prefix, _s_, *"."*, and *"0"* repeated _numDigits_ times. 1. Otherwise, return the string-concatenation of _prefix_, _s_ and *"0"* repeated _numDigits_ - _e_ times. - 1. If 0 < _numDigits_, then + 1. Else if 0 < _numDigits_, then 1. Return the string-concatenation of _prefix, _s_ and *"0"* repeated _e_ - _numDigits_ times. 1. Otherwise: - 1. Assert: _rounded_ is an integer. 1. Let _firstDigit_ be the substring of _s_ from 0 to 1. 1. Let _p_ be the unique integer such that 1 ≤ _rounded_ × 10_p_ < 10. 1. Let _n_ be _p_ + _numDigits_. - 1. Assert: _n_ ≥ 0. - 1. Let _exp_ be the unique string representation of _n_ in base-10 without duplicate leading zeros. - 1. If _n_ = 0, then - 1. Return the string-concatenation of _s_, *"e"*, and _exp_. - 1. Otherwise: - 1. Let _remainingDigits_ be the substring of _s_ from 1 to _n_. - 1. Return the string-concatenation of _firstDigit_, *"."*, _remainingDigits_, *"e"*, and _exp_. + 1. Assert: _n_ < 0. + 1. Let _exp_ be the unique string representation of -_n_ in base-10 without duplicate leading zeros. + 1. Let _remainingDigits_ be the substring of _s_ from 1 to _n_. + 1. Return the string-concatenation of _firstDigit_, *"."*, _remainingDigits_, *"e"*, and _exp_. From 82c23da5da057be67ed71971819d4c4a4b4634d4 Mon Sep 17 00:00:00 2001 From: Jesse Alama Date: Tue, 23 Sep 2025 20:59:32 +0200 Subject: [PATCH 02/12] Fix mising `_` --- spec.emu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec.emu b/spec.emu index df2503b..19ba3de 100644 --- a/spec.emu +++ b/spec.emu @@ -320,7 +320,7 @@ location: https://github.com/tc39/proposal-amount/ 1. Let _rounded_ be ApplyRoundingModeToPositive(_v_ × 10_numDigits_, _roundingMode_). 1. Let _e_ be the smallest non-negative integer such that _rounded_ × 10-_e_ is an integer. 1. Let _s_ be the unique decimal string representation of _rounded_ without duplicate leading zeroes. - 1. If _e_ < numDigits_, then + 1. If _e_ < _numDigits_, then 1. If _v_ is an integer, return the string-concatenation of _prefix, _s_, *"."*, and *"0"* repeated _numDigits_ times. 1. Otherwise, return the string-concatenation of _prefix_, _s_ and *"0"* repeated _numDigits_ - _e_ times. 1. Else if 0 < _numDigits_, then From ef944f319deab79591653f2312d3b5508bb1ceaf Mon Sep 17 00:00:00 2001 From: Jesse Alama Date: Tue, 23 Sep 2025 21:20:29 +0200 Subject: [PATCH 03/12] Handle _numDigits_ being 0 (render no fraction digits) --- spec.emu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec.emu b/spec.emu index 19ba3de..0b822f5 100644 --- a/spec.emu +++ b/spec.emu @@ -323,7 +323,7 @@ location: https://github.com/tc39/proposal-amount/ 1. If _e_ < _numDigits_, then 1. If _v_ is an integer, return the string-concatenation of _prefix, _s_, *"."*, and *"0"* repeated _numDigits_ times. 1. Otherwise, return the string-concatenation of _prefix_, _s_ and *"0"* repeated _numDigits_ - _e_ times. - 1. Else if 0 < _numDigits_, then + 1. Else if 0 ≤ _numDigits_, then 1. Return the string-concatenation of _prefix, _s_ and *"0"* repeated _e_ - _numDigits_ times. 1. Otherwise: 1. Let _firstDigit_ be the substring of _s_ from 0 to 1. From 6de39bf20970938f2f0d2c45ae4df29fa4f2a035 Mon Sep 17 00:00:00 2001 From: Jesse Alama Date: Tue, 23 Sep 2025 21:22:06 +0200 Subject: [PATCH 04/12] Add clarifying assertion --- spec.emu | 1 + 1 file changed, 1 insertion(+) diff --git a/spec.emu b/spec.emu index 0b822f5..0321f12 100644 --- a/spec.emu +++ b/spec.emu @@ -328,6 +328,7 @@ location: https://github.com/tc39/proposal-amount/ 1. Otherwise: 1. Let _firstDigit_ be the substring of _s_ from 0 to 1. 1. Let _p_ be the unique integer such that 1 ≤ _rounded_ × 10_p_ < 10. + 1. Assert: _numDigits_ < 0. 1. Let _n_ be _p_ + _numDigits_. 1. Assert: _n_ < 0. 1. Let _exp_ be the unique string representation of -_n_ in base-10 without duplicate leading zeros. From 54d9e773d36488f1688620b7c6d1f1320afde06f Mon Sep 17 00:00:00 2001 From: Jesse Alama Date: Tue, 23 Sep 2025 21:32:15 +0200 Subject: [PATCH 05/12] RenderAmountValueWithFractionDigits: Remove rounding --- spec.emu | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/spec.emu b/spec.emu index 0321f12..949bf6e 100644 --- a/spec.emu +++ b/spec.emu @@ -291,13 +291,12 @@ location: https://github.com/tc39/proposal-amount/

RenderAmountValueWithFractionDigits ( _v_: an Intl mathematical value, - _numDigits_: an integer, - optional _roundingMode_: a rounding mode + _numDigits_: an integer ): a String

description
-
It renders the given Intl mathematical value with a given number of fractional digits, rounding, if necessary, using the given rounding mode, which, if missing, is *"halfEven"*.
+
It renders the given Intl mathematical value with a given number of fractional digits
1. If _v_ is ~not-a-number~, return *"NaN"*. @@ -312,14 +311,10 @@ location: https://github.com/tc39/proposal-amount/ 1. Let _z_ be *"-0"*. 1. If _numDigits_ = 0, return _z_. 1. Otherwise, return the string-concatenation of _z_, *"."* and _trailingZeroes_. - 1. If _roundingMode_ is *undefined*, set _roundingMode_ to *"halfEven"*. 1. If _v_ < 0, let _prefix_ be *"-"*, else let _prefix_ be "". - 1. If _v_ < 0, then - 1. Set _v_ to -_v_. - 1. Set _roundingMode_ to ReverseRoundingMode(_roundingMode_). - 1. Let _rounded_ be ApplyRoundingModeToPositive(_v_ × 10_numDigits_, _roundingMode_). - 1. Let _e_ be the smallest non-negative integer such that _rounded_ × 10-_e_ is an integer. - 1. Let _s_ be the unique decimal string representation of _rounded_ without duplicate leading zeroes. + 1. If _v_ < 0, set _v_ to -_v_. + 1. Let _e_ be the smallest non-negative integer such that _v_ × 10-_e_ is an integer. + 1. Let _s_ be the unique decimal string representation of _v_ without duplicate leading zeroes. 1. If _e_ < _numDigits_, then 1. If _v_ is an integer, return the string-concatenation of _prefix, _s_, *"."*, and *"0"* repeated _numDigits_ times. 1. Otherwise, return the string-concatenation of _prefix_, _s_ and *"0"* repeated _numDigits_ - _e_ times. @@ -327,7 +322,7 @@ location: https://github.com/tc39/proposal-amount/ 1. Return the string-concatenation of _prefix, _s_ and *"0"* repeated _e_ - _numDigits_ times. 1. Otherwise: 1. Let _firstDigit_ be the substring of _s_ from 0 to 1. - 1. Let _p_ be the unique integer such that 1 ≤ _rounded_ × 10_p_ < 10. + 1. Let _p_ be the unique integer such that 1 ≤ _v_ × 10_p_ < 10. 1. Assert: _numDigits_ < 0. 1. Let _n_ be _p_ + _numDigits_. 1. Assert: _n_ < 0. From 52c8ddf192c7c0b5eb306819ff6e93d382fdf692 Mon Sep 17 00:00:00 2001 From: Jesse Alama Date: Tue, 23 Sep 2025 21:33:48 +0200 Subject: [PATCH 06/12] Rename formal parameter name --- spec.emu | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/spec.emu b/spec.emu index 949bf6e..694ae8a 100644 --- a/spec.emu +++ b/spec.emu @@ -291,7 +291,7 @@ location: https://github.com/tc39/proposal-amount/

RenderAmountValueWithFractionDigits ( _v_: an Intl mathematical value, - _numDigits_: an integer + _fractionDigits_: an integer ): a String

@@ -303,28 +303,28 @@ location: https://github.com/tc39/proposal-amount/ 1. If _v_ is ~negative-infinity~, return *"-Infinity"*. 1. If _v_ is ~positive-infinity~, return *"Infinity"*. 1. If _v_ is ~minus-zero~, then - 1. If _numDigits_ < 0, then - 1. Let _exp_ be the unique string representation of -_numDigits_ in base 10 without duplicate leading zeros. + 1. If _fractionDigits_ < 0, then + 1. Let _exp_ be the unique string representation of -_fractionDigits_ in base 10 without duplicate leading zeros. 1. Return the string-concatenation of *"0"*, *"e"*, and _exp_. 1. Otherwise: - 1. Let _trailingZeroes_ be *"0"* repeated _numDigits_ times. + 1. Let _trailingZeroes_ be *"0"* repeated _fractionDigits_ times. 1. Let _z_ be *"-0"*. - 1. If _numDigits_ = 0, return _z_. + 1. If _fractionDigits_ = 0, return _z_. 1. Otherwise, return the string-concatenation of _z_, *"."* and _trailingZeroes_. 1. If _v_ < 0, let _prefix_ be *"-"*, else let _prefix_ be "". 1. If _v_ < 0, set _v_ to -_v_. 1. Let _e_ be the smallest non-negative integer such that _v_ × 10-_e_ is an integer. 1. Let _s_ be the unique decimal string representation of _v_ without duplicate leading zeroes. - 1. If _e_ < _numDigits_, then - 1. If _v_ is an integer, return the string-concatenation of _prefix, _s_, *"."*, and *"0"* repeated _numDigits_ times. - 1. Otherwise, return the string-concatenation of _prefix_, _s_ and *"0"* repeated _numDigits_ - _e_ times. - 1. Else if 0 ≤ _numDigits_, then - 1. Return the string-concatenation of _prefix, _s_ and *"0"* repeated _e_ - _numDigits_ times. + 1. If _e_ < _fractionDigits_, then + 1. If _v_ is an integer, return the string-concatenation of _prefix, _s_, *"."*, and *"0"* repeated _fractionDigits_ times. + 1. Otherwise, return the string-concatenation of _prefix_, _s_ and *"0"* repeated _fractionDigits_ - _e_ times. + 1. Else if 0 ≤ _fractionDigits_, then + 1. Return the string-concatenation of _prefix, _s_ and *"0"* repeated _e_ - _fractionDigits_ times. 1. Otherwise: 1. Let _firstDigit_ be the substring of _s_ from 0 to 1. 1. Let _p_ be the unique integer such that 1 ≤ _v_ × 10_p_ < 10. - 1. Assert: _numDigits_ < 0. - 1. Let _n_ be _p_ + _numDigits_. + 1. Assert: _fractionDigits_ < 0. + 1. Let _n_ be _p_ + _fractionDigits_. 1. Assert: _n_ < 0. 1. Let _exp_ be the unique string representation of -_n_ in base-10 without duplicate leading zeros. 1. Let _remainingDigits_ be the substring of _s_ from 1 to _n_. From cb2fb5ef1ead1b9867d0a1826d86e60c85435d3f Mon Sep 17 00:00:00 2001 From: Jesse Alama Date: Tue, 23 Sep 2025 21:34:56 +0200 Subject: [PATCH 07/12] Fix -0 --- spec.emu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec.emu b/spec.emu index 694ae8a..8ace02e 100644 --- a/spec.emu +++ b/spec.emu @@ -305,7 +305,7 @@ location: https://github.com/tc39/proposal-amount/ 1. If _v_ is ~minus-zero~, then 1. If _fractionDigits_ < 0, then 1. Let _exp_ be the unique string representation of -_fractionDigits_ in base 10 without duplicate leading zeros. - 1. Return the string-concatenation of *"0"*, *"e"*, and _exp_. + 1. Return the string-concatenation of *"-0"*, *"e"*, and _exp_. 1. Otherwise: 1. Let _trailingZeroes_ be *"0"* repeated _fractionDigits_ times. 1. Let _z_ be *"-0"*. From 38173e39ef1cabf1778eeb3419756a05181eee0b Mon Sep 17 00:00:00 2001 From: Jesse Alama Date: Tue, 23 Sep 2025 21:35:56 +0200 Subject: [PATCH 08/12] Reorder steps, avoid computation --- spec.emu | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/spec.emu b/spec.emu index 8ace02e..d097fdd 100644 --- a/spec.emu +++ b/spec.emu @@ -307,10 +307,9 @@ location: https://github.com/tc39/proposal-amount/ 1. Let _exp_ be the unique string representation of -_fractionDigits_ in base 10 without duplicate leading zeros. 1. Return the string-concatenation of *"-0"*, *"e"*, and _exp_. 1. Otherwise: + 1. If _fractionDigits_ = 0, return *"-0"*. 1. Let _trailingZeroes_ be *"0"* repeated _fractionDigits_ times. - 1. Let _z_ be *"-0"*. - 1. If _fractionDigits_ = 0, return _z_. - 1. Otherwise, return the string-concatenation of _z_, *"."* and _trailingZeroes_. + 1. Otherwise, return the string-concatenation of *"-0"*, *"."* and _trailingZeroes_. 1. If _v_ < 0, let _prefix_ be *"-"*, else let _prefix_ be "". 1. If _v_ < 0, set _v_ to -_v_. 1. Let _e_ be the smallest non-negative integer such that _v_ × 10-_e_ is an integer. From e79f85ae6b58396c0b456ef6ce09f41158a6ef46 Mon Sep 17 00:00:00 2001 From: Jesse Alama Date: Tue, 23 Sep 2025 21:52:18 +0200 Subject: [PATCH 09/12] Handle -0 recursively --- spec.emu | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/spec.emu b/spec.emu index d097fdd..d4956e2 100644 --- a/spec.emu +++ b/spec.emu @@ -303,13 +303,8 @@ location: https://github.com/tc39/proposal-amount/ 1. If _v_ is ~negative-infinity~, return *"-Infinity"*. 1. If _v_ is ~positive-infinity~, return *"Infinity"*. 1. If _v_ is ~minus-zero~, then - 1. If _fractionDigits_ < 0, then - 1. Let _exp_ be the unique string representation of -_fractionDigits_ in base 10 without duplicate leading zeros. - 1. Return the string-concatenation of *"-0"*, *"e"*, and _exp_. - 1. Otherwise: - 1. If _fractionDigits_ = 0, return *"-0"*. - 1. Let _trailingZeroes_ be *"0"* repeated _fractionDigits_ times. - 1. Otherwise, return the string-concatenation of *"-0"*, *"."* and _trailingZeroes_. + 1. Let _s_ be RenderAmountValueWithFractionDigits(0, _fractionDigits_:). + 1. Return the string-concatenation of *"-"* and _s_. 1. If _v_ < 0, let _prefix_ be *"-"*, else let _prefix_ be "". 1. If _v_ < 0, set _v_ to -_v_. 1. Let _e_ be the smallest non-negative integer such that _v_ × 10-_e_ is an integer. From eaded13fa286766981cd86854b370c17497a6795 Mon Sep 17 00:00:00 2001 From: Jesse Alama Date: Tue, 23 Sep 2025 22:06:58 +0200 Subject: [PATCH 10/12] Add missing `_` --- spec.emu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec.emu b/spec.emu index d4956e2..7a50bc6 100644 --- a/spec.emu +++ b/spec.emu @@ -310,7 +310,7 @@ location: https://github.com/tc39/proposal-amount/ 1. Let _e_ be the smallest non-negative integer such that _v_ × 10-_e_ is an integer. 1. Let _s_ be the unique decimal string representation of _v_ without duplicate leading zeroes. 1. If _e_ < _fractionDigits_, then - 1. If _v_ is an integer, return the string-concatenation of _prefix, _s_, *"."*, and *"0"* repeated _fractionDigits_ times. + 1. If _v_ is an integer, return the string-concatenation of _prefix_, _s_, *"."*, and *"0"* repeated _fractionDigits_ times. 1. Otherwise, return the string-concatenation of _prefix_, _s_ and *"0"* repeated _fractionDigits_ - _e_ times. 1. Else if 0 ≤ _fractionDigits_, then 1. Return the string-concatenation of _prefix, _s_ and *"0"* repeated _e_ - _fractionDigits_ times. From 941efe35d1f20f6ea39388a58613036fcf0567d0 Mon Sep 17 00:00:00 2001 From: Jesse Alama Date: Tue, 23 Sep 2025 22:10:36 +0200 Subject: [PATCH 11/12] Adopt bulky language for expressing decimal notation --- spec.emu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec.emu b/spec.emu index 7a50bc6..55ff244 100644 --- a/spec.emu +++ b/spec.emu @@ -308,7 +308,7 @@ location: https://github.com/tc39/proposal-amount/ 1. If _v_ < 0, let _prefix_ be *"-"*, else let _prefix_ be "". 1. If _v_ < 0, set _v_ to -_v_. 1. Let _e_ be the smallest non-negative integer such that _v_ × 10-_e_ is an integer. - 1. Let _s_ be the unique decimal string representation of _v_ without duplicate leading zeroes. + 1. If _v_ = 0, let _s_ be *"0"*, else let _s_ be the unique decimal string representation of _v_ that either starts with "0." or does not start with "0". 1. If _e_ < _fractionDigits_, then 1. If _v_ is an integer, return the string-concatenation of _prefix_, _s_, *"."*, and *"0"* repeated _fractionDigits_ times. 1. Otherwise, return the string-concatenation of _prefix_, _s_ and *"0"* repeated _fractionDigits_ - _e_ times. From 0a04ef7224c236cdf1dd515b03a1ab83b49a1f95 Mon Sep 17 00:00:00 2001 From: Jesse Alama Date: Tue, 23 Sep 2025 22:15:44 +0200 Subject: [PATCH 12/12] Handle 0 emitted in exponential notation --- spec.emu | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec.emu b/spec.emu index 55ff244..c8eb7e1 100644 --- a/spec.emu +++ b/spec.emu @@ -316,8 +316,7 @@ location: https://github.com/tc39/proposal-amount/ 1. Return the string-concatenation of _prefix, _s_ and *"0"* repeated _e_ - _fractionDigits_ times. 1. Otherwise: 1. Let _firstDigit_ be the substring of _s_ from 0 to 1. - 1. Let _p_ be the unique integer such that 1 ≤ _v_ × 10_p_ < 10. - 1. Assert: _fractionDigits_ < 0. + 1. If _v_ = 0, let _p_ be 0, else let _p_ be the unique integer such that 1 ≤ _v_ × 10_p_ < 10. 1. Let _n_ be _p_ + _fractionDigits_. 1. Assert: _n_ < 0. 1. Let _exp_ be the unique string representation of -_n_ in base-10 without duplicate leading zeros.