diff --git a/spec.html b/spec.html index 045a409208..e43701684e 100644 --- a/spec.html +++ b/spec.html @@ -5316,6 +5316,30 @@

+ +

+ ToFixedSizeInteger ( + _int_: an integer, +∞, or -∞, + _signed_: ~unsigned~ or ~signed~, + _bitWidth_: a positive integer, + ): an integer +

+
+
description
+
It maps _int_ to one of 2_bitWidth_ integers in the inclusive interval from 0 to 2_bitWidth_ - 1 (if _signed_ is ~unsigned~) or -2_bitWidth_ - 1 to 2_bitWidth_ - 1 - 1 (if _signed_ is ~signed~).
+
+ + 1. If _int_ = +∞ or _int_ = -∞, return 0. + 1. Let _fixedInt_ be _int_ modulo 2_bitWidth_. + 1. NOTE: The following step does not change the two's complement representation of _fixedInt_. + 1. If _signed_ is ~signed~ and _fixedInt_ ≥ 2_bitWidth_ - 1, set _fixedInt_ to _fixedInt_ - 2_bitWidth_. + 1. Return _fixedInt_. + + +

ToFixedSizeInteger is idempotent: for any ECMAScript language value _x_, ToFixedSizeInteger(ToFixedSizeInteger(_x_, _signed_, _bitWidth_), _signed_, _bitWidth_) is the same as ToFixedSizeInteger(_x_, _signed_, _bitWidth_). In fact, because +∞ and -∞ are mapped to 0, this invariant even survives inversion of _signed_ (e.g., ToFixedSizeInteger(ToFixedSizeInteger(_x_, ~signed~, 32), ~unsigned~, 32) is the same as ToFixedSizeInteger(_x_, ~unsigned~, 32)).

+
+
+

ToInt32 ( @@ -5324,29 +5348,12 @@

description
-
It converts _argument_ to one of 232 integral Number values in the inclusive interval from 𝔽(-231) to 𝔽(231 - 1).
+
It converts _argument_ to one of 232 integral Number values in the inclusive interval from 𝔽(-231) to 𝔽(231 - 1), excluding *-0*𝔽.
1. Let _int_ be ? ToIntegerOrInfinity(_argument_). - 1. If _int_ is not finite, return *+0*𝔽. - 1. Let _int32bit_ be _int_ modulo 232. - 1. If _int32bit_ ≥ 231, return 𝔽(_int32bit_ - 232). - 1. Return 𝔽(_int32bit_). + 1. Return 𝔽(ToFixedSizeInteger(_int_, ~signed~, 32)). - -

Given the above definition:

-
    -
  • - It is idempotent: for any ECMAScript language value _x_, ToInt32(ToInt32(_x_)) is the same as ToInt32(_x_). -
  • -
  • - For any ECMAScript language value _x_, ToInt32(ToUint32(_x_)) is the same as ToInt32(_x_). (It is to preserve this property that *+∞*𝔽 and *-∞*𝔽 are mapped to *+0*𝔽.) -
  • -
  • - ToInt32 maps *-0*𝔽 to *+0*𝔽. -
  • -
-
@@ -5361,27 +5368,8 @@

1. Let _int_ be ? ToIntegerOrInfinity(_argument_). - 1. If _int_ is not finite, return *+0*𝔽. - 1. Let _int32bit_ be _int_ modulo 232. - 1. [id="step-touint32-return"] Return 𝔽(_int32bit_). + 1. Return 𝔽(ToFixedSizeInteger(_int_, ~unsigned~, 32)). - -

Given the above definition:

-
    -
  • - Step is the only difference between ToUint32 and ToInt32. -
  • -
  • - It is idempotent: for any ECMAScript language value _x_, ToUint32(ToUint32(_x_)) is the same as ToUint32(_x_). -
  • -
  • - For any ECMAScript language value _x_, ToUint32(ToInt32(_x_)) is the same as ToUint32(_x_). (It is to preserve this property that *+∞*𝔽 and *-∞*𝔽 are mapped to *+0*𝔽.) -
  • -
  • - ToUint32 maps *-0*𝔽 to *+0*𝔽. -
  • -
-
@@ -5392,14 +5380,11 @@

description
-
It converts _argument_ to one of 216 integral Number values in the inclusive interval from 𝔽(-215) to 𝔽(215 - 1).
+
It converts _argument_ to one of 216 integral Number values in the inclusive interval from 𝔽(-215) to 𝔽(215 - 1), excluding *-0*𝔽.
1. Let _int_ be ? ToIntegerOrInfinity(_argument_). - 1. If _int_ is not finite, return *+0*𝔽. - 1. Let _int16bit_ be _int_ modulo 216. - 1. If _int16bit_ ≥ 215, return 𝔽(_int16bit_ - 216). - 1. Return 𝔽(_int16bit_). + 1. Return 𝔽(ToFixedSizeInteger(_int_, ~signed~, 16)).
@@ -5415,21 +5400,8 @@

1. Let _int_ be ? ToIntegerOrInfinity(_argument_). - 1. If _int_ is not finite, return *+0*𝔽. - 1. [id="step-touint16-mod"] Let _int16bit_ be _int_ modulo 216. - 1. Return 𝔽(_int16bit_). + 1. Return 𝔽(ToFixedSizeInteger(_int_, ~unsigned~, 16)). - -

Given the above definition:

-
    -
  • - The substitution of 216 for 232 in step is the only difference between ToUint32 and ToUint16. -
  • -
  • - ToUint16 maps *-0*𝔽 to *+0*𝔽. -
  • -
-
@@ -5440,14 +5412,11 @@

description
-
It converts _argument_ to one of 28 integral Number values in the inclusive interval from *-128*𝔽 to *127*𝔽.
+
It converts _argument_ to one of 28 integral Number values in the inclusive interval from *-128*𝔽 to *127*𝔽, excluding *-0*𝔽.
1. Let _int_ be ? ToIntegerOrInfinity(_argument_). - 1. If _int_ is not finite, return *+0*𝔽. - 1. Let _int8bit_ be _int_ modulo 28. - 1. If _int8bit_ ≥ 27, return 𝔽(_int8bit_ - 28). - 1. Return 𝔽(_int8bit_). + 1. Return 𝔽(ToFixedSizeInteger(_int_, ~signed~, 8)).
@@ -5463,9 +5432,7 @@

1. Let _int_ be ? ToIntegerOrInfinity(_argument_). - 1. If _int_ is not finite, return *+0*𝔽. - 1. Let _int8bit_ be _int_ modulo 28. - 1. Return 𝔽(_int8bit_). + 1. Return 𝔽(ToFixedSizeInteger(_int_, ~unsigned~, 8)). @@ -5640,10 +5607,8 @@

It converts _argument_ to one of 264 BigInt values in the inclusive interval from ℤ(-263) to ℤ(263 - 1).
- 1. Let _n_ be ? ToBigInt(_argument_). - 1. Let _int64bit_ be ℝ(_n_) modulo 264. - 1. If _int64bit_ ≥ 263, return ℤ(_int64bit_ - 264). - 1. Return ℤ(_int64bit_). + 1. Let _int_ be ℝ(? ToBigInt(_argument_)). + 1. Return ℤ(ToFixedSizeInteger(_int_, ~signed~, 64)). @@ -5658,9 +5623,8 @@

It converts _argument_ to one of 264 BigInt values in the inclusive interval from *0* to ℤ(264 - 1).
- 1. Let _n_ be ? ToBigInt(_argument_). - 1. Let _int64bit_ be ℝ(_n_) modulo 264. - 1. Return ℤ(_int64bit_). + 1. Let _int_ be ℝ(? ToBigInt(_argument_)). + 1. Return ℤ(ToFixedSizeInteger(_int_, ~unsigned~, 64)).