From c8570c66876d81305e4ca17f05dde9f668de5a80 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Fri, 12 Feb 2021 18:16:54 +0700 Subject: [PATCH] pair sincos for vectors --- headers/vmath.hpp/vmath_vec_fun.hpp | 11 ++++++++--- untests/vmath_vec_fun_tests.cpp | 3 +++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/headers/vmath.hpp/vmath_vec_fun.hpp b/headers/vmath.hpp/vmath_vec_fun.hpp index e8392a4..3ab9274 100644 --- a/headers/vmath.hpp/vmath_vec_fun.hpp +++ b/headers/vmath.hpp/vmath_vec_fun.hpp @@ -576,10 +576,15 @@ namespace vmath_hpp return map_join([](T x) { return atanh(x); }, xs); } - template < typename T, size_t Size > + template < typename T, std::size_t Size > + std::pair, vec> sincos(const vec& xs) { + return { sin(xs), cos(xs) }; + } + + template < typename T, std::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); + *ss = sin(xs); + *cs = cos(xs); } } diff --git a/untests/vmath_vec_fun_tests.cpp b/untests/vmath_vec_fun_tests.cpp index 408ad3f..8f67e1c 100644 --- a/untests/vmath_vec_fun_tests.cpp +++ b/untests/vmath_vec_fun_tests.cpp @@ -155,6 +155,9 @@ TEST_CASE("vmath/vec_fun") { sincos(float2(10.f,15.f), &out_ss, &out_cs); REQUIRE(out_ss == uapprox2(sin(10.f), sin(15.f))); REQUIRE(out_cs == uapprox2(cos(10.f), cos(15.f))); + const auto [out_ss2, out_cs2] = sincos(float2(10.f,15.f)); + REQUIRE(out_ss2 == uapprox2(sin(10.f), sin(15.f))); + REQUIRE(out_cs2 == uapprox2(cos(10.f), cos(15.f))); } }