-
Notifications
You must be signed in to change notification settings - Fork 455
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
Compiled js min/max value with bigint #7062
Comments
Thanks for the report! Who's best to look at this, @mununki perhaps? |
You can't use Math.min/max for "bigint" in JS, that operations are for "number" types |
We could add min/max as compiler primitives (and handle it in #7057 too), but that would add some runtime codes anyway. To make it "simple enough" |
I'm thinking that adding primitives to have the compiler throw errors when using max or min with bigint might be a good idea. What do you think? |
Actually the compiler's
What the @remitbri reported is more like not a runtime error, but a Gentype-related one. |
Also note the bigint folding will be a bit improved in v12 by #7029 |
As far as I know, JavaScript does not support Math.max and Math.min for BigInt. Does this mean you are suggesting adding runtime support for max and min in ReScript? How do you plan to implement the runtime? |
When I was saying "We can't use Math.min/max for bigint values." in the issue description, it was about Javascript support, that's why I wasn't keen on having a compiler primitive. That being said, we could have a |
That's what exactly we have already. Just need to expose it to the API surface |
I guess there is an issue with latest master branch: let max0 = max(1n, 2n)
let min0 = min(1n, 2n)
let c0 = 1n > 2n
let a = 5n
let b = 7n
let c = max(a, b) compiled to
|
Since the PR #7088, it is compiled to: open! Js.BigInt
let e = x => x + 5n
let f = x => x + 7n
let g = max(e(4n), f(9n)) function e(x) {
return x + 5n;
}
function f(x) {
return x + 7n;
}
let g = Primitive_bigint.max(4n + 5n, 9n + 7n); |
// Primitive_bigint.js
function max(x, y) {
if (x > y) {
return x;
} else {
return y;
}
} |
We can't use Math.min/max for bigint values.
If the rescript code is simple enough,
the compiled js is simple too:
But if it's trickier,
the compiled js is
Problem:
The text was updated successfully, but these errors were encountered: