I saw something about LerpStable() in the 4.6 notes and I was wondering what exactly it does. Does it return anything different than what Lerp returns? Is there any advantage to using one over the other?
Hi Jared,
I think from mathematical point of view these functions are equivalent. However, Lerp function can lead to errors on large numbers. For example:
int a = -1000000000, b = -1.2*a;
float alpha = 0.5;
auto r1 = FMath::Lerp(a, b, alpha); // Incorrect result, cause integer overflow
auto r2 = FMath::LerpStable(a, b, alpha); // OK
Best regards,
1 Like
Thank you for that breakdown, . I imagine then that LerpStable must require a bit more memory or work a tick slower than Lerp in exchange for the stability. I appreciate your answer
Exactly. Lerp compiled to i386 assembler without any optimization is just 4 instructions (not counting function parameter handling), while LerpStable translates to 6 instructions (one additional push to the FPU register stack, and one additional multiplication).
1 Like