lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




Le jeu. 14 janv. 2021 à 00:57, bel <bel2125@gmail.com> a écrit :
Left-Associativity is only defined for one operator X:   a X b X c = (a X b) X c. This does not define anything for two different operators (* and /).
The problem does not exist for subtraction

No it exists for substraction, exactly like divisions:

a - b - c = (a-b)-c   !=  a-(b-c) = a-b+c =  (a - b) + c

Rewriting the members to use unary negation (or unary inverse) for changing a non-commutative substraction (or division) into a commutative addition (or multiplication) if another thing: you completely change the operation and define another one (negation or inverse).

And if you work with integers or float/doubles in C/C++/Lua/Java/_javascript_, the inverse will generate important rounding differences (or sometimes overflows with unspecified results: commutativity is not true even for the multiplication on integers in C/C++/Lua/Java/_javascript_) on the result, so it's not equivalent at all: in this case the order of operations is important, the type of associatitivity if important, and using reordering/commutativity will bring false results in important cases.

We were ONLY speaking about the use of parentheses to specify the associativity (and order of operations when rounding or overflows can occur due to limited precision).