Skip to content

Fix floatcomp for %max #7333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 13, 2025
Merged

Conversation

JonoPrest
Copy link
Contributor

A very quick one 🙏🏼

Closes #7332

Copy link
Collaborator

@cristianoc cristianoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!
Would you update the changelog too?

@zth
Copy link
Collaborator

zth commented Mar 12, 2025

And the test output (CI is red).

@JonoPrest
Copy link
Contributor Author

JonoPrest commented Mar 12, 2025

Thanks guys!

@cristianoc are these supposed to be inverted?

(* 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;
boolcomp = Pboolmin;
floatcomp = Pfloatmin;
stringcomp = Pstringmin;
bigintcomp = Pbigintmin;
simplify_constant_constructor = false;
} );
|]

ie %bs_min maps each comp to max and %bs_max maps to min

@cristianoc
Copy link
Collaborator

Thanks guys!

@cristianoc are these supposed to be inverted?

(* FIXME: Core compatibility *)
( "%bs_min",
{
objcomp = Pobjmax;
intcomp = Pintmax;
boolcomp = Pboolmax;
floatcomp = Pboolmax;
stringcomp = Pstringmax;
bigintcomp = Pbigintmax;
simplify_constant_constructor = false;
} );
( "%bs_max",
{
objcomp = Pobjmin;
intcomp = Pintmin;
boolcomp = Pboolmin;
floatcomp = Pfloatmin;
stringcomp = Pstringmin;
bigintcomp = Pbigintmin;
simplify_constant_constructor = false;
} );
|]

ie %bs_min maps each comp to max and %bs_max maps to min

Likely
To be sure, I would add a test

@JonoPrest
Copy link
Contributor Author

JonoPrest commented Mar 12, 2025

Likely To be sure, I would add a test

@cristianoc I can see for example it's used here and bound to a "min" function.

Inverting them doesn't break any tests currently but it looks like the behaviour of inverting min with max is a mistake. And I think it's safe to assume so given how it's used.

This would go out of bounds if the 2 lists passed in had different lengths.

module A = {
@new external makeUninitializedUnsafe: int => array<'a> = "Array"
external min: ('a, 'a) => 'a = "%bs_min"
let reduceReverseU = (a, x, f) => {
let r = ref(x)
for i in Stdlib_Array.length(a) - 1 downto 0 {
r.contents = f(r.contents, Stdlib_Array.getUnsafe(a, i))
}
r.contents
}
let reduceReverse2U = (a, b, x, f) => {
let r = ref(x)
let len = min(Stdlib_Array.length(a), Stdlib_Array.length(b))
for i in len - 1 downto 0 {
r.contents = f(r.contents, Stdlib_Array.getUnsafe(a, i), Stdlib_Array.getUnsafe(b, i))
}
r.contents
}
}

Would you like me to try and add a test for this reduceReverse2U?

@cometkim
Copy link
Member

Oops..

@cristianoc
Copy link
Collaborator

Likely To be sure, I would add a test

@cristianoc I can see for example it's used here and bound to a "min" function.

Inverting them doesn't break any tests currently but it looks like the behaviour of inverting min with max is a mistake. And I think it's safe to assume so given how it's used.

This would go out of bounds if the 2 lists passed in had different lengths.

module A = {
@new external makeUninitializedUnsafe: int => array<'a> = "Array"
external min: ('a, 'a) => 'a = "%bs_min"
let reduceReverseU = (a, x, f) => {
let r = ref(x)
for i in Stdlib_Array.length(a) - 1 downto 0 {
r.contents = f(r.contents, Stdlib_Array.getUnsafe(a, i))
}
r.contents
}
let reduceReverse2U = (a, b, x, f) => {
let r = ref(x)
let len = min(Stdlib_Array.length(a), Stdlib_Array.length(b))
for i in len - 1 downto 0 {
r.contents = f(r.contents, Stdlib_Array.getUnsafe(a, i), Stdlib_Array.getUnsafe(b, i))
}
r.contents
}
}

Would you like me to try and add a test for this reduceReverse2U?

Given there's already a test whose output changes, I think that' enough.
Good to go.

@cristianoc cristianoc merged commit 600f285 into rescript-lang:master Mar 13, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pervasives.max is broken on float type in v12
4 participants