How would I convert this code?

I was looking at some easing functions that are in … probably C++?
Anyway, I noticed an odd way of calculating happening in the formula.

In this particular line…

return n1 * (x -= 1.5 / d1) * x + 0.75;

it has x -= 1.5
lau will not allow this type of assignment in a calculation apprently as I keep getting an error.
I understand that it is takeing what is in x and subtracting 1.5/d1 from x, but what is the significance of assigning the value back to the variable x?
would it not be the same as just having

return n1 * (x  - 1.5 / d1) * x + 0.75;

or is the re-assignment important considering there is a second x in the formula outside of the parenthesis?
If that is the case, could I do something like…

local x2 = x-1.5/d1
return n1 * (x -= 1.5 / d1) * x2 + 0.75;

or simply

return n1 * (x - 1.5 / d1) * (x - 1.5 / d1)  + 0.75;

Thanks for any input on this.

1 Like