The following code is part of an easing equation. I’m just interested in the syntax.
sqrtf(1 - (t = t / d - 1) * t);
I haven’t seen the ‘=’ operator used like this before. What does it do in this context?
Edit: the code is from a well-known Robert Penner easing function, written in ActionScript:
static function easeOut (t:Number, b:Number, c:Number, d:Number):Number {
return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
}
The
=operator here does what it always does. In this case it modifiest(setting it tot / d - 1). The value returned from that part of the equation will be the new value oft.This becomes confusing because
tis used later in the equation, and I wouldn’t be sure that every compiler would treat it the same. ie is the thirdtgoing to use the old value or the new value?I would avoid writing equations in this way. It’s lazy and I don’t see any good reason to do it.