return modf function

This commit is contained in:
BlackMATov
2021-02-23 22:26:40 +07:00
parent 6e3c1ba523
commit e80f49133b
6 changed files with 63 additions and 22 deletions

View File

@@ -78,6 +78,12 @@ namespace vmath_hpp
return std::fmod(x, y);
}
template < typename T >
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
modf(T x, T* y) noexcept {
return std::modf(x, y);
}
template < typename T >
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
copysign(T x, T s) noexcept {

View File

@@ -505,6 +505,20 @@ namespace vmath_hpp
return map_join([](T x, T y) { return fmod(x, y); }, xs, ys);
}
namespace impl
{
template < typename T, std::size_t Size, std::size_t... Is >
VMATH_HPP_FORCE_INLINE
vec<T, Size> modf_impl(const vec<T, Size>& xs, vec<T, Size>* is, std::index_sequence<Is...>) {
return { modf(xs[Is], &(*is)[Is])... };
}
}
template < typename T, std::size_t Size >
vec<T, Size> modf(const vec<T, Size>& xs, vec<T, Size>* is) {
return impl::modf_impl(xs, is, std::make_index_sequence<Size>{});
}
template < typename T, std::size_t Size >
[[nodiscard]] vec<T, Size> copysign(const vec<T, Size>& xs, T s) {
return map_join([s](T x) { return copysign(x, s); }, xs);