You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would expect it prints -4 while it gives 4, 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:
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 ** tighter is a relic of math symbols where the index is written literally on top of the base in smaller type, meaning it is not written as a binary operator at all. That makes the interpretation make sense. However, in programming there is no distinction between an index and its base value. So -2 ** 2 is essentially exp(-2, 2).
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 ?
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: