
Re: Robot 2.26 Possible Compiler Error
Yes. I confirmed this is a compiler bug. Looks like it might have been there day one. In some cases the compiler has got to "fancy" in trying to eliminate temporary variables in calculations.
It goes something like this:
<int A> = <factor B> * <factor C>
If either "B" or "C" is a float expression then compiler should do the "times" at float precision using a temporary variable and then convert the temporary variable back to an integer.
In a few weird cases, due to a missing case statement in the bowels of the compiler, compiler incorrectly thinks it can eliminate the temporary variable and instead generate the code for
<int A> = B;
<int A> *= C;
which is incorrect because "B" was a float value that should be preserved.
I have fixed the bug. It should be in version 2.31.
Sorry about that.
Workarounds for this example include:
declaring 'kp' as c'const'.
moving the unary '-' outside the expression -(kp*error)
doing all the calculations at float precsions; eg. "float ans2".