When I use several operators in one calculation string, the whole calculation becomes incorrect.
Here's the example project and the result in terminal:
Looks like a compiler bug/feature to me. The sum you are doing is being truncated to 16-bit.
127 * 8 * 512 = 520192
520192 MOD 65536 = 61440 which corresponds to signed value -4096.
In C I would add a typecast to the sum to force it to 32-bit but there is currently no provision to do this in Flowcode so breaking up the sum into smaller chunks is likely the best option.
It’s not a bug, it’s just the way C integer promotions work and the size of an integer on the 16 bit target platform.
Unfortunately this means that the results will be different on target than on Windows simulation, which is going to be confusing.
As Ben says, adding explicit casts would be one way to fix it in C code.
But this would be difficult to do in Flowcode as we would not want to force all calculations to 32 bit with the resulting bloat of program code.
The safest solution is to ensure that numbers are stored in long integer variables before attempting long integer maths on them, as in your third example.