diff --git a/README.md b/README.md index a87b95c..cbb55a8 100644 --- a/README.md +++ b/README.md @@ -617,6 +617,9 @@ T acosh(T x) noexcept; template < floating_point T > T atanh(T x) noexcept; +template < floating_point T > +std::pair sincos(T x) noexcept; + template < floating_point T > void sincos(T x, T* s, T* c) noexcept; @@ -759,9 +762,15 @@ T modf(T x, T* y) noexcept; template < arithmetic T > constexpr T min(T x, T y) noexcept; +template < arithmetic T, arithmetic... Ts > +constexpr std::common_type_t min(T x, T y, Ts... ts) noexcept; + template < arithmetic T > constexpr T max(T x, T y) noexcept; +template < arithmetic T, arithmetic... Ts > +constexpr std::common_type_t max(T x, T y, Ts... ts) noexcept; + template < arithmetic T > constexpr T clamp(T x, T min_x, T max_x) noexcept; diff --git a/headers/vmath.hpp/vmath_fun.hpp b/headers/vmath.hpp/vmath_fun.hpp index 7a201a1..e2d0bc1 100644 --- a/headers/vmath.hpp/vmath_fun.hpp +++ b/headers/vmath.hpp/vmath_fun.hpp @@ -86,12 +86,28 @@ namespace vmath_hpp return x < y ? x : y; } + template < typename T, typename... Ts > + [[nodiscard]] std::enable_if_t< + std::is_arithmetic_v, + std::common_type_t> + constexpr min(T x, T y, Ts... ts) noexcept { + return min(min(x, y), ts...); + } + template < typename T > [[nodiscard]] std::enable_if_t, T> constexpr max(T x, T y) noexcept { return x < y ? y : x; } + template < typename T, typename... Ts > + [[nodiscard]] std::enable_if_t< + std::is_arithmetic_v, + std::common_type_t> + constexpr max(T x, T y, Ts... ts) noexcept { + return max(max(x, y), ts...); + } + template < typename T > [[nodiscard]] std::enable_if_t, T> constexpr clamp(T x, T min_x, T max_x) noexcept { diff --git a/untests/vmath_fun_tests.cpp b/untests/vmath_fun_tests.cpp index be74efd..2cfcb89 100644 --- a/untests/vmath_fun_tests.cpp +++ b/untests/vmath_fun_tests.cpp @@ -85,8 +85,13 @@ TEST_CASE("vmath/fun") { REQUIRE(out_i == approx(1.f)); } - STATIC_REQUIRE(min(1.f, 2.f) == approx(1.f)); - STATIC_REQUIRE(max(1.f, 2.f) == approx(2.f)); + STATIC_REQUIRE(min(0.f, 1.f) == approx(0.f)); + STATIC_REQUIRE(min(3.f, 2.f, 1.f) == approx(1.f)); + STATIC_REQUIRE(min(4.f, 3.f, 2.f, 1.f) == approx(1.f)); + + STATIC_REQUIRE(max(0.f, 1.f) == approx(1.f)); + STATIC_REQUIRE(max(3.f, 2.f, 1.f) == approx(3.f)); + STATIC_REQUIRE(max(4.f, 3.f, 2.f, 1.f) == approx(4.f)); STATIC_REQUIRE(clamp(1.0f, 2.f, 3.f) == approx(2.0f)); STATIC_REQUIRE(clamp(2.5f, 2.f, 3.f) == approx(2.5f));