BruceSherwood/glowscript

Violation of order of operations when using modulo

Closed this issue · 2 comments

wigie commented

In GlowScript 2.0 VPython:

print(14 % 5 + 3)
=> 6
print(3 + 14 % 5)
=> 7
print((14 % 5) + 3)
=> 6
print(3 + (14 % 5))
=> 7

In standard Python, these examples all return 7, as they should since % binds more tightly than +.
The last two examples in GlowScript are particularly bizarre.

Oy. It isn't just order of operations, since as you show, (14%5)+3 also gives 6. This is a bug in the RapydScript Python-to-JavaScript transpiler, which I'll report, but I'll also try to fix it myself. Thanks much for the clear report.

It wasn't a problem with the RapydScript compiler but a mistake in handling operator overloading; the % operator was handled properly. Will be fixed in GlowScript 2.1.