Skip to content

Instantly share code, notes, and snippets.

@murilopolese
Created March 29, 2017 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save murilopolese/b3c0e697c740084b8c0e4d2d460e8b80 to your computer and use it in GitHub Desktop.
Save murilopolese/b3c0e697c740084b8c0e4d2d460e8b80 to your computer and use it in GitHub Desktop.
Lerp
// Imprecise method, which does not guarantee v = v1 when t = 1, due to floating-point arithmetic error.
// This form may be used when the hardware has a native fused multiply-add instruction.
float lerp(float v0, float v1, float t) {
return v0 + t * (v1 - v0);
}
// Precise method, which guarantees v = v1 when t = 1.
float lerp(float v0, float v1, float t) {
return (1 - t) * v0 + t * v1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment