Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

easeOutBack math function for 0 is incorrect #151

Open
bcardarella opened this issue Feb 11, 2022 · 5 comments
Open

easeOutBack math function for 0 is incorrect #151

bcardarella opened this issue Feb 11, 2022 · 5 comments

Comments

@bcardarella
Copy link

bcardarella commented Feb 11, 2022

Using the Math function for easeOutBack: https://easings.net/#easeOutBack

function easeOutBack(x: number): number {
  const c1 = 1.70158;
  const c3 = c1 + 1;

  return 1 + c3 * pow(x - 1, 3) + c1 * pow(x - 1, 2);
}

console.log(easeOutBack(0))

results in 2.220446049250313e-16 whereas it should be 0

If the calculation is correct then a simple conditional to return 0 when x === 0 would be necessary.

@clickyclick
Copy link

= 1 + c3 * pow(x - 1, 3) + c1 * pow(x - 1, 2);
= 1 + 2.70158 * pow(0 - 1, 3) + 1.70158 * pow(0 - 1, 2); // x = 0
= 1 + 2.70158 * pow( - 1, 3) + 1.70158 * pow( - 1, 2);
= 1 + 2.70158 * (-1) + 1.70158 * 1; // we know -1^2 is 1 while -1^3 is -1 still
= 1 - 2.70158 + 1.70158 ;
= 0

Here is my work for arriving at 0 as output with a 0 input. Seems correct to me.

@bcardarella
Copy link
Author

See in JavaScript:
Screen Shot 2022-02-16 at 10 07 21 AM

And in Elixir:
Screen Shot 2022-02-16 at 10 08 16 AM

@clickyclick
Copy link

Ah I see, format your output to a certain number of decimal places seems like the proper solution.

https://stackoverflow.com/questions/1458633/how-to-deal-with-floating-point-number-precision-in-javascript

@bcardarella
Copy link
Author

Yes, it is an incredibly small value and I'm sure an argument could be made about managing floating point precision but considering some of the other functions defer to 0 if x === 0 it stands to reason to have something similar here.

@Cleroth
Copy link

Cleroth commented Sep 23, 2023

Changing c1 to 1.701575 works. Effect should be very minor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants