-
Notifications
You must be signed in to change notification settings - Fork 188
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
Precedence of power operator #935
Comments
Yeah, that is because in Rhai uniary operators (such as negation and negative) bind tighter than binary operators... It would be confusing otherwise: -2 ** 2 = -4;
-2 * 2 = ? // does - bind tighter than * but no as tight as **? Binding |
Okay, would it possible to add a special hint to the document (Rhai book) to clarify this feature, in case someone else would come across this behaviour in the future ? |
It's documented pretty well. I can confirm it differs from popular scripting languages, but Rust doesn't have the operator so it doesn't differ from Rust. |
IMO it would be better to have an operator precedence table in the Scripting Language section as well, without the numbers and maybe without the directions. They could link to each other. Otherwise the Scripting Language section is a bit incomplete as a language reference. |
True. It is certainly missing a section on operators... |
Well, I know that Rust doesn't have it but many other languages have the power operator, and most of them follows the precedence of it in mathematics (for example, in Julia |
I think it's worth making this change, because it's a better design. I just noticed that Rhai has modulus, which is more convenient, and differs from Rust and JavaScript, in a pleasant way. You can page through things by doing With the power operator, giving |
The current difficulty is thar Rhai's code structure binds unary operators tighter than binary ones... |
Hi, consider the short code
I would expect it prints
-4
while it gives4
, meaning that-2**2
equals(-2) ** 2
, which is contradict to the common precedence of negate and power (for example, Python and Fortran would print-4
).Is it an expected behaviour?
The text was updated successfully, but these errors were encountered: