easing-functions icon indicating copy to clipboard operation
easing-functions copied to clipboard

easeInOutCubic is wrong

Open Denis535 opened this issue 6 years ago • 2 comments

I'm trying your easeInOutCubic:

double easeInOutCubic( double t ) {
   return t < 0.5 ? 4 * t * t * t : 1 + (--t) * (2 * (--t)) * (2 * t);
}

But it returns wrong result for case t >= 0.5. unity 2017 1 0f1 personal 64bit - untitled - tween - pc mac linux standalone dx11 2017-07-08 17 28 14

Denis535 avatar Jul 08 '17 14:07 Denis535

I guess the correct implementation is

return t < 0.5 ? 4 * t * t * t : (t-1)*(2*t-2)*(2*t-2)+1

(from https://gist.github.com/gre/1650294)

--t is useful but sometimes get tricky to debug. In this case the second and third parentheses should be 2*t - 2 but in the repo it's 2*(t-2) which of course gives wrong results

micuat avatar Mar 23 '19 15:03 micuat

Using --t and t several times in an expression like this is unfortunately not useful at all, it's Undefined Behaviour. You can't rely on the order of evaluation without sequence points.

Olof-IL avatar Nov 03 '20 09:11 Olof-IL