mirror of
https://github.com/BlackMATov/vmath.hpp.git
synced 2025-12-15 04:35:25 +07:00
add sincos
This commit is contained in:
@@ -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<T, Size> acosh(const vec<T, Size>& xs);
|
||||
|
||||
template < typename T, size_t Size >
|
||||
vec<T, Size> atanh(const vec<T, Size>& xs);
|
||||
|
||||
template < typename T, size_t Size >
|
||||
void sincos(const vec<T, Size>& xs, vec<T, Size>* ss, vec<T, Size>* cs);
|
||||
```
|
||||
|
||||
### Exponential Functions
|
||||
|
||||
@@ -103,6 +103,19 @@ namespace vmath_hpp
|
||||
atanh(T x) noexcept {
|
||||
return std::atanh(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, std::pair<T, T>>
|
||||
sincos(T x) noexcept {
|
||||
return {sin(x), cos(x)};
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, void>
|
||||
sincos(T x, T* s, T* c) noexcept {
|
||||
*s = sin(x);
|
||||
*c = cos(x);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -400,6 +400,12 @@ namespace vmath_hpp
|
||||
[[nodiscard]] vec<T, Size> atanh(const vec<T, Size>& xs) {
|
||||
return map_join([](T x) { return atanh(x); }, xs);
|
||||
}
|
||||
|
||||
template < typename T, size_t Size >
|
||||
void sincos(const vec<T, Size>& xs, vec<T, Size>* ss, vec<T, Size>* cs) {
|
||||
*ss = map_join([](T x){ return sin(x); }, xs);
|
||||
*cs = map_join([](T x){ return cos(x); }, xs);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -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") {
|
||||
|
||||
@@ -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") {
|
||||
|
||||
Reference in New Issue
Block a user