I’m trying to convert some algorithms to another language and am stuck on a few lines of code. The language I’m converting from is actionscript and converting it to lua.
I came across this line
return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b
is this the same as
s = s*1.525
return c/2*(t*t*((s+1)*t - s)) + b
or is it the same as
newS = s*1.525
return c/2*(t*t*((newS+1)*t - s)) + b
so once the *= is called, is s changed throughout the function, so every instance of s is the new value or is it only calculated once and s retains it’s value from before?
Any help would be appreciated. Thanks!
The assignment operators are evaluated from right to left on the same level of nesting. As your original statement has
s*=1.25enclosed into parentheses the*=assignment is executed in advance of addition of1, multiplication byt, e.t.c., So, your first variant is the correct one.