| 1 | // { dg-do compile { target c++20 } } |
| 2 | |
| 3 | #include <cmath> |
| 4 | |
| 5 | // Fails template argument deduction unless both arguments are the same type. |
| 6 | template<typename T> |
| 7 | constexpr bool |
| 8 | eq(T result, T expected) { return result == expected; } |
| 9 | |
| 10 | static_assert( eq( std::lerp(-10.0, 10.0, 0.25), -5.0 ) ); |
| 11 | static_assert( eq( std::lerp(2.0f, 2.0f, 200.0f), 2.0f ) ); |
| 12 | static_assert( eq( std::lerp(2.0L, 4.0L, 200.0L), 402.0L ) ); |
| 13 | // at least one type is long double, so result is long double |
| 14 | static_assert( eq( std::lerp(2.0L, 4.0f, -20.0), -38.0L ) ); |
| 15 | // at least one type is double, so result is double: |
| 16 | static_assert( eq( std::lerp(-8.0f, 10.0, 0.5f), 1.0 ) ); |
| 17 | // int promotes to double, so result is double |
| 18 | static_assert( eq( std::lerp(0, 1, 0), 0.0 ) ); |
| 19 | // int promotes to double, so result is double |
| 20 | static_assert( eq( std::lerp(2.0f, -10.0f, 1), -10.0 ) ); |