-
Notifications
You must be signed in to change notification settings - Fork 453
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
Upgrade exponentiation to unified operator #7153
base: master
Are you sure you want to change the base?
Conversation
let int32_pow ?comment (e1 : t) (e2 : t) : J.expression = | ||
match (e1.expression_desc, e2.expression_desc) with | ||
| Number (Int {i = i1}), Number (Int {i = i2}) -> | ||
int ?comment (Ext_int.int32_pow i1 i2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you checked that this is semantically equivalent to js power, or whatever Pow
does below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is different from js pow, especially when overflow. If I leave js pow out, wouldn't it cause undefined behavior in ReScript, like values greater than max_int
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, seems it is already possible by n ** n
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intended question is: does the case with constants behave exactly like when 2 variables with the same constant values are passed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added more tests to verify it
6253a22
to
8af675c
Compare
Also make its output to use ES7 exponentiation (`**`) operator. `**` is more concise, faster than `Math.pow()`, works well with all numeric types include bigint. We were already using it for bigint, now for int and float too.
2ac5b3a
to
73dedfb
Compare
I think The problem is that to match the semantics we need to perform the modulo operation ourselves, which is quite expensive at runtime. |
Well, I guess I'll have to propose new int semantics to fix it, but that would be a pretty breaking change. It seems very weird now that all other operations use int32 coercion, but only multiplication has a different behavior. |
What is the difference, in short? |
Oh you mean |
(discussing in rescript-lang/rfcs#1) |
Also make its output to use ES7 exponentiation (
**
) operator.**
is more concise, faster thanMath.pow()
,works well with all numeric types include bigint.
We were already using it for bigint, now for int and float too.