Date: Sun, 13 Apr 2025 18:38:26 +0200
Hi,
On 13/04/2025 17:23, Paul Meckel via Std-Proposals wrote:
> for lerp_inv(a, b, x) it should hold true
>
> lerp(a, b, lerp_inv(a, b, x)) == x
>
> The naive implementation is
>
> ```cpp
> template <typename T>
> requires std::is_arithmetic_v<T> // can we also get concept
> std::arithmetic, please?
> constexpr T lerp_inv(const T a, const T b, const T x) noexcept {
> return (x - a) / (b - a);
> }
> ```
Do you have a non-naive implementation available, that also satisfies a
set of useful properties?
std::lerp got added by
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0811r3.html
That paper discusses an interesting set of properties that lerp should
have, and also provided a reference implementation. That reference
implementation is the one actually used by libstdc++ and libc++:
https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/c_global/cmath#L3840
https://github.com/llvm/llvm-project/blob/main/libcxx/include/cmath#L576
You should provide the same (rationale and implementation), and with
that you can turn this idea into a paper.
Thanks,
--
Giuseppe D'Angelo
On 13/04/2025 17:23, Paul Meckel via Std-Proposals wrote:
> for lerp_inv(a, b, x) it should hold true
>
> lerp(a, b, lerp_inv(a, b, x)) == x
>
> The naive implementation is
>
> ```cpp
> template <typename T>
> requires std::is_arithmetic_v<T> // can we also get concept
> std::arithmetic, please?
> constexpr T lerp_inv(const T a, const T b, const T x) noexcept {
> return (x - a) / (b - a);
> }
> ```
Do you have a non-naive implementation available, that also satisfies a
set of useful properties?
std::lerp got added by
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0811r3.html
That paper discusses an interesting set of properties that lerp should
have, and also provided a reference implementation. That reference
implementation is the one actually used by libstdc++ and libc++:
https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/c_global/cmath#L3840
https://github.com/llvm/llvm-project/blob/main/libcxx/include/cmath#L576
You should provide the same (rationale and implementation), and with
that you can turn this idea into a paper.
Thanks,
--
Giuseppe D'Angelo
Received on 2025-04-13 16:38:29