From da7c6b93b57171c37646c51569eaac94562b8a1f Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Thu, 11 Sep 2025 08:22:58 +0200 Subject: [PATCH 1/2] Float.isNaN: use Number.isNaN instead of isNaN --- packages/@rescript/runtime/Stdlib_Float.res | 2 +- packages/@rescript/runtime/Stdlib_Float.resi | 4 ++-- packages/@rescript/runtime/lib/es6/Stdlib_Float.js | 2 +- packages/@rescript/runtime/lib/es6/Stdlib_Int.js | 2 +- packages/@rescript/runtime/lib/js/Stdlib_Float.js | 2 +- packages/@rescript/runtime/lib/js/Stdlib_Int.js | 2 +- tests/tests/src/core/Core_FloatTests.mjs | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/@rescript/runtime/Stdlib_Float.res b/packages/@rescript/runtime/Stdlib_Float.res index e41be0b356..3e66e97caf 100644 --- a/packages/@rescript/runtime/Stdlib_Float.res +++ b/packages/@rescript/runtime/Stdlib_Float.res @@ -13,7 +13,7 @@ external equal: (float, float) => bool = "%equal" external compare: (float, float) => Stdlib_Ordering.t = "%compare" -@val external isNaN: float => bool = "isNaN" +@val @scope("Number") external isNaN: float => bool = "isNaN" @val external isFinite: float => bool = "isFinite" @val external parseFloat: 'a => float = "parseFloat" // parseInt's return type is a float because it can be NaN diff --git a/packages/@rescript/runtime/Stdlib_Float.resi b/packages/@rescript/runtime/Stdlib_Float.resi index ef67cfda09..f0f2b78a5b 100644 --- a/packages/@rescript/runtime/Stdlib_Float.resi +++ b/packages/@rescript/runtime/Stdlib_Float.resi @@ -139,7 +139,7 @@ external compare: (float, float) => Stdlib_Ordering.t = "%compare" /** `isNaN(v)` tests if the given `v` is `NaN`. -See [`NaN`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN) on MDN. +See [`isNaN`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN) on MDN. ## Examples @@ -148,7 +148,7 @@ Float.isNaN(3.0) // false Float.isNaN(Float.Constants.nan) // true ``` */ -@val +@val @scope("Number") external isNaN: float => bool = "isNaN" /** diff --git a/packages/@rescript/runtime/lib/es6/Stdlib_Float.js b/packages/@rescript/runtime/lib/es6/Stdlib_Float.js index d0955e3ce0..7cb1e62d88 100644 --- a/packages/@rescript/runtime/lib/es6/Stdlib_Float.js +++ b/packages/@rescript/runtime/lib/es6/Stdlib_Float.js @@ -5,7 +5,7 @@ let Constants = {}; function fromString(i) { let i$1 = parseFloat(i); - if (isNaN(i$1)) { + if (Number.isNaN(i$1)) { return; } else { return i$1; diff --git a/packages/@rescript/runtime/lib/es6/Stdlib_Int.js b/packages/@rescript/runtime/lib/es6/Stdlib_Int.js index 4993a6297c..9f2ba3a6d1 100644 --- a/packages/@rescript/runtime/lib/es6/Stdlib_Int.js +++ b/packages/@rescript/runtime/lib/es6/Stdlib_Int.js @@ -4,7 +4,7 @@ import * as Stdlib_Array from "./Stdlib_Array.js"; function fromString(x, radix) { let maybeInt = radix !== undefined ? parseInt(x, radix) : parseInt(x); - if (isNaN(maybeInt) || maybeInt > 2147483647 || maybeInt < -2147483648) { + if (Number.isNaN(maybeInt) || maybeInt > 2147483647 || maybeInt < -2147483648) { return; } else { return maybeInt | 0; diff --git a/packages/@rescript/runtime/lib/js/Stdlib_Float.js b/packages/@rescript/runtime/lib/js/Stdlib_Float.js index ecb91a0c04..c34f9395a3 100644 --- a/packages/@rescript/runtime/lib/js/Stdlib_Float.js +++ b/packages/@rescript/runtime/lib/js/Stdlib_Float.js @@ -5,7 +5,7 @@ let Constants = {}; function fromString(i) { let i$1 = parseFloat(i); - if (isNaN(i$1)) { + if (Number.isNaN(i$1)) { return; } else { return i$1; diff --git a/packages/@rescript/runtime/lib/js/Stdlib_Int.js b/packages/@rescript/runtime/lib/js/Stdlib_Int.js index 5e6dbb7ced..dbd70277e6 100644 --- a/packages/@rescript/runtime/lib/js/Stdlib_Int.js +++ b/packages/@rescript/runtime/lib/js/Stdlib_Int.js @@ -4,7 +4,7 @@ let Stdlib_Array = require("./Stdlib_Array.js"); function fromString(x, radix) { let maybeInt = radix !== undefined ? parseInt(x, radix) : parseInt(x); - if (isNaN(maybeInt) || maybeInt > 2147483647 || maybeInt < -2147483648) { + if (Number.isNaN(maybeInt) || maybeInt > 2147483647 || maybeInt < -2147483648) { return; } else { return maybeInt | 0; diff --git a/tests/tests/src/core/Core_FloatTests.mjs b/tests/tests/src/core/Core_FloatTests.mjs index 865bbe9cba..2a08805ebb 100644 --- a/tests/tests/src/core/Core_FloatTests.mjs +++ b/tests/tests/src/core/Core_FloatTests.mjs @@ -105,7 +105,7 @@ Test.run([ 33 ], "clamp - nan" -], isNaN(Stdlib_Float.clamp(4.1, 4.3, Number.NaN)), eq, true); +], Number.isNaN(Stdlib_Float.clamp(4.1, 4.3, Number.NaN)), eq, true); Test.run([ [ From fa87b4b09dff74701a0bdd160a3e7325c40f4a63 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Thu, 11 Sep 2025 14:28:01 +0200 Subject: [PATCH 2/2] CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a69f1052b..031cc623b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ #### :nail_care: Polish - Reactivate optimization for length of array literals. https://github.com/rescript-lang/rescript/pull/7872 +- `Float.isNaN`: use `Number.isNaN` instead of global `isNaN`. https://github.com/rescript-lang/rescript/pull/7874 #### :house: Internal