From 69a21e0c2cab3d7c8f84b040dec9a238f571f6df Mon Sep 17 00:00:00 2001 From: Jono Prest Date: Wed, 12 Mar 2025 10:50:40 +0200 Subject: [PATCH 1/5] Fix floatcomp for %max --- compiler/ml/translcore.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/ml/translcore.ml b/compiler/ml/translcore.ml index 03782b95fa..82fb75a8bd 100644 --- a/compiler/ml/translcore.ml +++ b/compiler/ml/translcore.ml @@ -164,7 +164,7 @@ let comparisons_table = objcomp = Pobjmax; intcomp = Pintmax; boolcomp = Pboolmax; - floatcomp = Pboolmax; + floatcomp = Pfloatmax; stringcomp = Pstringmax; bigintcomp = Pbigintmax; simplify_constant_constructor = false; From 260b462acf3a2917f8a235df8076c229bb87cde2 Mon Sep 17 00:00:00 2001 From: Jono Prest Date: Wed, 12 Mar 2025 11:36:12 +0200 Subject: [PATCH 2/5] Update mario_game generated test code --- tests/tests/src/mario_game.mjs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/tests/src/mario_game.mjs b/tests/tests/src/mario_game.mjs index 6086b07dfe..07016a05be 100644 --- a/tests/tests/src/mario_game.mjs +++ b/tests/tests/src/mario_game.mjs @@ -3,7 +3,6 @@ import * as Belt_List from "rescript/lib/es6/Belt_List.js"; import * as Pervasives from "rescript/lib/es6/Pervasives.js"; import * as Primitive_int from "rescript/lib/es6/Primitive_int.js"; -import * as Primitive_bool from "rescript/lib/es6/Primitive_bool.js"; import * as Primitive_float from "rescript/lib/es6/Primitive_float.js"; import * as Primitive_object from "rescript/lib/es6/Primitive_object.js"; import * as Primitive_option from "rescript/lib/es6/Primitive_option.js"; @@ -979,7 +978,7 @@ function update_player(player, keys, context) { if (!player.jumping && player.grounded) { player.jumping = true; player.grounded = false; - player.vel.y = Primitive_bool.max(player.vel.y - (5.7 + Math.abs(player.vel.x) * 0.25), -6); + player.vel.y = Primitive_float.max(player.vel.y - (5.7 + Math.abs(player.vel.x) * 0.25), -6); return; } else { return; @@ -1531,7 +1530,7 @@ function make$3(param, param$1) { function calc_viewport_point(cc, vc, mc) { let vc_half = vc / 2; - return Primitive_float.min(Primitive_bool.max(cc - vc_half, 0), Primitive_float.min(mc - vc, Math.abs(cc - vc_half))); + return Primitive_float.min(Primitive_float.max(cc - vc_half, 0), Primitive_float.min(mc - vc, Math.abs(cc - vc_half))); } function in_viewport(v, pos) { From f666e6f4969c9126fba383334473648d13cff574 Mon Sep 17 00:00:00 2001 From: Jono Prest Date: Wed, 12 Mar 2025 11:38:27 +0200 Subject: [PATCH 3/5] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e93d38e7e6..73436ed243 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - Add popover attributes to JsxDOM.domProps. https://github.com/rescript-lang/rescript/pull/7317 - Add `inert` attribute to `JsxDOM.domProps`. https://github.com/rescript-lang/rescript/pull/7326 - Make reanalyze exception tracking work with the new stdlib. https://github.com/rescript-lang/rescript/pull/7328 +- Fix Pervasive.max using boolean comparison for floats. https://github.com/rescript-lang/rescript/pull/7333 #### :boom: Breaking Change From ba80b11b25fedfb2bd632effd5875cc9c107862f Mon Sep 17 00:00:00 2001 From: Jono Prest Date: Wed, 12 Mar 2025 11:45:58 +0200 Subject: [PATCH 4/5] Fix second case of floatcomp mapped to Pboolmax --- compiler/ml/translcore.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/ml/translcore.ml b/compiler/ml/translcore.ml index 82fb75a8bd..4c336959f7 100644 --- a/compiler/ml/translcore.ml +++ b/compiler/ml/translcore.ml @@ -215,7 +215,7 @@ let comparisons_table = objcomp = Pobjmax; intcomp = Pintmax; boolcomp = Pboolmax; - floatcomp = Pboolmax; + floatcomp = Pfloatmax; stringcomp = Pstringmax; bigintcomp = Pbigintmax; simplify_constant_constructor = false; From 9694b9037e9b03a80227929f249af8c58e4511fc Mon Sep 17 00:00:00 2001 From: Jono Prest Date: Wed, 12 Mar 2025 12:13:55 +0200 Subject: [PATCH 5/5] Fix %bs_min and %bs_max comparison --- compiler/ml/translcore.ml | 20 ++++++++++---------- lib/es6/Stdlib_List.js | 2 +- lib/js/Stdlib_List.js | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/compiler/ml/translcore.ml b/compiler/ml/translcore.ml index 4c336959f7..db9624b841 100644 --- a/compiler/ml/translcore.ml +++ b/compiler/ml/translcore.ml @@ -211,16 +211,6 @@ let comparisons_table = } ); (* FIXME: Core compatibility *) ( "%bs_min", - { - objcomp = Pobjmax; - intcomp = Pintmax; - boolcomp = Pboolmax; - floatcomp = Pfloatmax; - stringcomp = Pstringmax; - bigintcomp = Pbigintmax; - simplify_constant_constructor = false; - } ); - ( "%bs_max", { objcomp = Pobjmin; intcomp = Pintmin; @@ -230,6 +220,16 @@ let comparisons_table = bigintcomp = Pbigintmin; simplify_constant_constructor = false; } ); + ( "%bs_max", + { + objcomp = Pobjmax; + intcomp = Pintmax; + boolcomp = Pboolmax; + floatcomp = Pfloatmax; + stringcomp = Pstringmax; + bigintcomp = Pbigintmax; + simplify_constant_constructor = false; + } ); |] let primitives_table = diff --git a/lib/es6/Stdlib_List.js b/lib/es6/Stdlib_List.js index 0715a3b68a..0f2e7e7843 100644 --- a/lib/es6/Stdlib_List.js +++ b/lib/es6/Stdlib_List.js @@ -896,7 +896,7 @@ function reduceReverse2(l1, l2, acc, f) { let a = toArray(l1); let b = toArray(l2); let r = acc; - let len$1 = Primitive_int.max(a.length, b.length); + let len$1 = Primitive_int.min(a.length, b.length); for (let i = len$1 - 1 | 0; i >= 0; --i) { r = f(r, a[i], b[i]); } diff --git a/lib/js/Stdlib_List.js b/lib/js/Stdlib_List.js index 2a7fdd73f4..47c32dd1d0 100644 --- a/lib/js/Stdlib_List.js +++ b/lib/js/Stdlib_List.js @@ -896,7 +896,7 @@ function reduceReverse2(l1, l2, acc, f) { let a = toArray(l1); let b = toArray(l2); let r = acc; - let len$1 = Primitive_int.max(a.length, b.length); + let len$1 = Primitive_int.min(a.length, b.length); for (let i = len$1 - 1 | 0; i >= 0; --i) { r = f(r, a[i], b[i]); }