diff --git a/biome.json b/biome.json index 6bcb2055d9..34cc4503d2 100644 --- a/biome.json +++ b/biome.json @@ -41,8 +41,7 @@ "noAssignInExpressions": "off", "noDoubleEquals": "off", "noFallthroughSwitchClause": "off", - "noRedeclare": "off", - "noSelfCompare": "off" + "noRedeclare": "off" } } }, diff --git a/runtime/bigarray.js b/runtime/bigarray.js index c0d35f9c6f..ab767805b0 100644 --- a/runtime/bigarray.js +++ b/runtime/bigarray.js @@ -243,8 +243,8 @@ Ml_Bigarray.prototype.compare = function (b, total) { if (x > y) return 1; if (x != y) { if (!total) return Number.NaN; - if (x == x) return 1; - if (y == y) return -1; + if (!Number.isNaN(x)) return 1; + if (!Number.isNaN(y)) return -1; } } break; diff --git a/runtime/compare.js b/runtime/compare.js index b81b00639c..9805e36db3 100644 --- a/runtime/compare.js +++ b/runtime/compare.js @@ -60,8 +60,8 @@ function caml_compare_val_number_custom(num, custom, swap, total) { var comp = caml_compare_val_get_custom(custom); if (comp) { var x = swap > 0 ? comp(custom, num, total) : comp(num, custom, total); - if (total && x != x) return swap; // total && nan - if (+x != +x) return +x; // nan + if (total && Number.isNaN(x)) return swap; // total && nan + if (Number.isNan(+x)) return +x; // nan if ((x | 0) != 0) return x | 0; // !nan } return swap; @@ -159,7 +159,7 @@ function caml_compare_val(a, b, total) { } if (!comp) caml_invalid_argument("compare: abstract value"); var x = comp(a, b, total); - if (x != x) { + if (Number.isNaN(x)) { // Protect against invalid UNORDERED return total ? -1 : x; } @@ -171,7 +171,7 @@ function caml_compare_val(a, b, total) { break; case 1256: // compare function var x = a.compare(b, total); - if (x != x) { + if (Number.isNaN(x)) { // Protect against invalid UNORDERED return total ? -1 : x; } @@ -188,8 +188,8 @@ function caml_compare_val(a, b, total) { if (a > b) return 1; if (a != b) { if (!total) return Number.NaN; - if (a == a) return 1; - if (b == b) return -1; + if (!Number.isNaN(a)) return 1; + if (!Number.isNaN(b)) return -1; } break; case 1001: // The rest @@ -210,8 +210,8 @@ function caml_compare_val(a, b, total) { if (a > b) return 1; if (a != b) { if (!total) return Number.NaN; - if (a == a) return 1; - if (b == b) return -1; + if (!Number.isNaN(a)) return 1; + if (!Number.isNaN(b)) return -1; } break; case 1251: // JavaScript Symbol, no ordering. diff --git a/runtime/ieee_754.js b/runtime/ieee_754.js index d890101b19..9d16cbefe6 100644 --- a/runtime/ieee_754.js +++ b/runtime/ieee_754.js @@ -264,8 +264,8 @@ function caml_float_compare(x, y) { if (x === y) return 0; if (x < y) return -1; if (x > y) return 1; - if (x === x) return 1; - if (y === y) return -1; + if (!Number.isNaN(x)) return 1; + if (!Number.isNaN(y)) return -1; return 0; } @@ -412,22 +412,13 @@ function caml_fma_float(x, y, z) { : x; } - if ( - x === 0 || - x !== x || - x === +1 / 0 || - x === -1 / 0 || - y === 0 || - y !== y || - y === +1 / 0 || - y === -1 / 0 - ) { + if (x === 0 || y === 0 || !Number.isFinite(x) || !Number.isFinite(y)) { return x * y + z; } if (z === 0) { return x * y; } - if (z !== z || z === +1 / 0 || z === -1 / 0) { + if (!Number.isFinite(z)) { return z; } @@ -569,10 +560,11 @@ function caml_float_of_string(s) { var res; s = caml_jsbytes_of_string(s); res = +s; - if (s.length > 0 && res === res) return res; + //Fast path + if (s.length > 0 && !Number.isNaN(res)) return res; s = s.replace(/_/g, ""); res = +s; - if ((s.length > 0 && res === res) || /^[+-]?nan$/i.test(s)) return res; + if (s.length > 0 && (!Number.isNaN(res) || /^[+-]?nan$/i.test(s))) return res; var m = /^ *([+-]?)0x([0-9a-f]+)\.?([0-9a-f]*)(p([+-]?[0-9]+))?/i.exec(s); // 1 2 3 5 if (m) {