Skip to content

Commit

Permalink
runtime: fix useNumberNamespace
Browse files Browse the repository at this point in the history
Signed-off-by: Sora Morimoto <[email protected]>
  • Loading branch information
smorimoto authored and hhugo committed Sep 24, 2024
1 parent fd80886 commit 59d865a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
1 change: 0 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"noVar": "off",
"useExponentiationOperator": "off",
"useNodejsImportProtocol": "off",
"useNumberNamespace": "off",
"useSingleVarDeclarator": "off",
"useTemplate": "off",
"useWhile": "off"
Expand Down
2 changes: 1 addition & 1 deletion runtime/bigarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ Ml_Bigarray.prototype.compare = function (b, total) {
if (x < y) return -1;
if (x > y) return 1;
if (x != y) {
if (!total) return NaN;
if (!total) return Number.NaN;
if (x == x) return 1;
if (y == y) return -1;
}
Expand Down
6 changes: 3 additions & 3 deletions runtime/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function caml_compare_val(a, b, total) {
if (a < b) return -1;
if (a > b) return 1;
if (a != b) {
if (!total) return NaN;
if (!total) return Number.NaN;
if (a == a) return 1;
if (b == b) return -1;
}
Expand All @@ -209,14 +209,14 @@ function caml_compare_val(a, b, total) {
if (a < b) return -1;
if (a > b) return 1;
if (a != b) {
if (!total) return NaN;
if (!total) return Number.NaN;
if (a == a) return 1;
if (b == b) return -1;
}
break;
case 1251: // JavaScript Symbol, no ordering.
if (a !== b) {
if (!total) return NaN;
if (!total) return Number.NaN;
return 1;
}
break;
Expand Down
4 changes: 2 additions & 2 deletions runtime/graphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ function caml_gr_open_graph(info) {
if (!status) specs.push("status=1");

var w = get("width");
w = w ? parseInt(w) : 200;
w = w ? Number.parseInt(w) : 200;
specs.push("width=" + w);

var h = get("height");
h = h ? parseInt(h) : 200;
h = h ? Number.parseInt(h) : 200;
specs.push("height=" + h);

var win = globalThis.open("about:blank", target, specs.join(","));
Expand Down
26 changes: 14 additions & 12 deletions runtime/ieee_754.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var log2_ok = Math.log2 && Math.log2(1.1235582092889474e307) == 1020;
function jsoo_floor_log2(x) {
if (log2_ok) return Math.floor(Math.log2(x));
var i = 0;
if (x == 0) return -Infinity;
if (x == 0) return Number.NEGATIVE_INFINITY;
if (x >= 1) {
while (x >= 2) {
x /= 2;
Expand All @@ -45,7 +45,8 @@ function caml_int64_bits_of_float(x) {
if (x > 0) return caml_int64_create_lo_mi_hi(0, 0, 0x7ff0);
else return caml_int64_create_lo_mi_hi(0, 0, 0xfff0);
}
var sign = x == 0 && 1 / x == -Infinity ? 0x8000 : x >= 0 ? 0 : 0x8000;
var sign =
x == 0 && 1 / x == Number.NEGATIVE_INFINITY ? 0x8000 : x >= 0 ? 0 : 0x8000;
if (sign) x = -x;
// Int64.bits_of_float 1.1235582092889474E+307 = 0x7fb0000000000000L
// using Math.LOG2E*Math.log(x) in place of Math.log2 result in precision lost
Expand Down Expand Up @@ -92,7 +93,7 @@ function caml_hexstring_of_float(x, prec, style) {
if (Number.isNaN(x)) return caml_string_of_jsstring("nan");
return caml_string_of_jsstring(x > 0 ? "infinity" : "-infinity");
}
var sign = x == 0 && 1 / x == -Infinity ? 1 : x >= 0 ? 0 : 1;
var sign = x == 0 && 1 / x == Number.NEGATIVE_INFINITY ? 1 : x >= 0 ? 0 : 1;
if (sign) x = -x;
var exp = 0;
if (x == 0) {
Expand Down Expand Up @@ -151,8 +152,9 @@ function caml_int64_float_of_bits(x) {
var hi = x.hi;
var exp = (hi & 0x7fff) >> 4;
if (exp == 2047) {
if ((lo | mi | (hi & 0xf)) == 0) return hi & 0x8000 ? -Infinity : Infinity;
else return NaN;
if ((lo | mi | (hi & 0xf)) == 0)
return hi & 0x8000 ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY;
else return Number.NaN;
}
var k = Math.pow(2, -24);
var res = (lo * k + mi) * k + (hi & 0xf);
Expand All @@ -167,7 +169,7 @@ function caml_int64_float_of_bits(x) {
//Provides: caml_nextafter_float const
//Requires: caml_int64_float_of_bits, caml_int64_bits_of_float, caml_int64_add, caml_int64_sub,caml_int64_of_int32
function caml_nextafter_float(x, y) {
if (Number.isNaN(x) || Number.isNaN(y)) return NaN;
if (Number.isNaN(x) || Number.isNaN(y)) return Number.NaN;
if (x == y) return y;
if (x == 0) {
if (y < 0) return -Math.pow(2, -1074);
Expand Down Expand Up @@ -215,7 +217,7 @@ function caml_modf_float(x) {
}
return [0, f, i];
}
if (Number.isNaN(x)) return [0, NaN, NaN];
if (Number.isNaN(x)) return [0, Number.NaN, Number.NaN];
return [0, 1 / x, x];
}
//Provides: caml_ldexp_float const
Expand Down Expand Up @@ -490,7 +492,7 @@ function caml_format_float(fmt, x) {
if (Math.abs(x) < 1.0) {
return x.toFixed(dp);
} else {
var e = parseInt(x.toString().split("+")[1]);
var e = Number.parseInt(x.toString().split("+")[1]);
if (e > 20) {
e -= 20;
x /= Math.pow(10, e);
Expand All @@ -505,7 +507,7 @@ function caml_format_float(fmt, x) {
var s,
f = caml_parse_format(fmt);
var prec = f.prec < 0 ? 6 : f.prec;
if (x < 0 || (x == 0 && 1 / x == -Infinity)) {
if (x < 0 || (x == 0 && 1 / x == Number.NEGATIVE_INFINITY)) {
f.sign = -1;
x = -x;
}
Expand Down Expand Up @@ -575,12 +577,12 @@ function caml_float_of_string(s) {
// 1 2 3 5
if (m) {
var m3 = m[3].replace(/0+$/, "");
var mantissa = parseInt(m[1] + m[2] + m3, 16);
var mantissa = Number.parseInt(m[1] + m[2] + m3, 16);
var exponent = (m[5] | 0) - 4 * m3.length;
res = mantissa * Math.pow(2, exponent);
return res;
}
if (/^\+?inf(inity)?$/i.test(s)) return Infinity;
if (/^-inf(inity)?$/i.test(s)) return -Infinity;
if (/^\+?inf(inity)?$/i.test(s)) return Number.POSITIVE_INFINITY;
if (/^-inf(inity)?$/i.test(s)) return Number.NEGATIVE_INFINITY;
caml_failwith("float_of_string");
}

0 comments on commit 59d865a

Please sign in to comment.