You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: text/0001-int.md
+45-7Lines changed: 45 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,14 +43,13 @@ Let `min_value` be $-2^{31}$ and `max_value` be $2^{31}-1$
43
43
44
44
### `fromNumber: (x: number) => int`
45
45
46
-
1. If `x` is JavaScript's `Infinity`, return `max_value`.
47
-
2. If `x` is JavaScript's `-Infinity`, return `min_value`.
48
-
3. Let `int32` be [`ToInt32`]`(x)`, return `int32`.
49
-
50
-
Actions 1 and 2 are intended to relax confusion when converting from infinite value directly. (e.g. https://github.com/rescript-lang/rescript/issues/6737) However, it can be omitted if the input is obviously not `Infinity` or `-Infinity`.
46
+
1. Let `int32` be [`ToInt32`]`(x)`, return `int32`.
51
47
52
48
The [`ToInt32`] behavior follows the definition in ECMA-262 as is. ReScript compiler uses `bitwiseOR(number, 0)` in action. This is what appears in the output as `number | 0`, which truncates all special numbers defined in IEEE-754.
53
49
50
+
The `fromNumber` shouldn't be directly exposed to the users. Applying the [`ToInt32`] operation to special numeric values, such as `Infinity`, can lead to subtle bugs (see example: [issue #6737](https://github.com/rescript-lang/rescript/issues/6737)).
51
+
Instead, Public APIs should wrap it and perform bounds-checking, if necessary, either emit errors (explained further in the "API Consideration" section below) or notify the user via compiler warning.
52
+
54
53
`int` never contains the following values:
55
54
56
55
-`-0`
@@ -61,6 +60,11 @@ The [`ToInt32`] behavior follows the definition in ECMA-262 as is. ReScript comp
61
60
62
61
`fromNumber(x)` must be idempotent.
63
62
63
+
### `minus: (x: int) => int`
64
+
65
+
1. Let `number` be mathematically $-x$.
66
+
2. Let `int32` be `fromNumber(number)`, return `int32`.
0 commit comments