diff --git a/README.md b/README.md index e795a55..a87b95c 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 > +void sincos(T x, T* s, T* c) noexcept; + // Vector template < typename T, size_t Size > @@ -663,6 +666,9 @@ vec acosh(const vec& xs); template < typename T, size_t Size > vec atanh(const vec& xs); + +template < typename T, size_t Size > +void sincos(const vec& xs, vec* ss, vec* cs); ``` ### Exponential Functions diff --git a/headers/vmath.hpp/vmath_fun.hpp b/headers/vmath.hpp/vmath_fun.hpp index c753df6..ab0caea 100644 --- a/headers/vmath.hpp/vmath_fun.hpp +++ b/headers/vmath.hpp/vmath_fun.hpp @@ -103,6 +103,19 @@ namespace vmath_hpp atanh(T x) noexcept { return std::atanh(x); } + + template < typename T > + [[nodiscard]] std::enable_if_t, std::pair> + sincos(T x) noexcept { + return {sin(x), cos(x)}; + } + + template < typename T > + [[nodiscard]] std::enable_if_t, void> + sincos(T x, T* s, T* c) noexcept { + *s = sin(x); + *c = cos(x); + } } // diff --git a/headers/vmath.hpp/vmath_vec_fun.hpp b/headers/vmath.hpp/vmath_vec_fun.hpp index ffbff21..ce780dc 100644 --- a/headers/vmath.hpp/vmath_vec_fun.hpp +++ b/headers/vmath.hpp/vmath_vec_fun.hpp @@ -400,6 +400,12 @@ namespace vmath_hpp [[nodiscard]] vec atanh(const vec& xs) { return map_join([](T x) { return atanh(x); }, xs); } + + template < typename T, size_t Size > + void sincos(const vec& xs, vec* ss, vec* cs) { + *ss = map_join([](T x){ return sin(x); }, xs); + *cs = map_join([](T x){ return cos(x); }, xs); + } } // diff --git a/untests/vmath_fun_tests.cpp b/untests/vmath_fun_tests.cpp index 11eb4af..be74efd 100644 --- a/untests/vmath_fun_tests.cpp +++ b/untests/vmath_fun_tests.cpp @@ -34,6 +34,13 @@ TEST_CASE("vmath/fun") { (void)asinh(0.f); (void)acosh(0.f); (void)atanh(0.f); + + { + float out_s{}, out_c{}; + sincos(15.f, &out_s, &out_c); + REQUIRE(out_s == approx(sin(15.f))); + REQUIRE(out_c == approx(cos(15.f))); + } } SUBCASE("Exponential Functions") { diff --git a/untests/vmath_vec_fun_tests.cpp b/untests/vmath_vec_fun_tests.cpp index 67faff9..f5f256a 100644 --- a/untests/vmath_vec_fun_tests.cpp +++ b/untests/vmath_vec_fun_tests.cpp @@ -108,6 +108,13 @@ TEST_CASE("vmath/vec_fun") { (void)asinh(float2(1.f)); (void)acosh(float2(1.f)); (void)atanh(float2(1.f)); + + { + float2 out_ss{}, out_cs{}; + sincos(float2(10.f,15.f), &out_ss, &out_cs); + REQUIRE(out_ss == approx2(sin(10.f), sin(15.f))); + REQUIRE(out_cs == approx2(cos(10.f), cos(15.f))); + } } SUBCASE("Exponential Functions") {