[libcxx-commits] [PATCH] D60371: Add lerp function to cmath (P0811R3)
Marshall Clow via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Apr 15 04:37:00 PDT 2019
mclow.lists added a comment.
The paper suggests an implementation like this:
constexpr Float lerp(Float a, Float b, Float t) {
// Exact, monotonic, bounded, determinate, and (for a=b=0) consistent:
if(a<=0 && b>=0 || a>=0 && b<=0) return t*b + (1-t)*a;
if(t==1) return b; // exact
// Exact at t=0, monotonic except near t=1,
// bounded, determinate, and consistent:
const Float x = a + t*(b-a);
return t>1 == b>a ? max(b,x) : min(b,x); // monotonic near t=1
}
I've tested this, and it works "pretty well", but not (I think) well enough.
Repository:
rCXX libc++
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D60371/new/
https://reviews.llvm.org/D60371
More information about the libcxx-commits
mailing list