mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-08-03 12:49:50 +00:00
add finite check: is_integer, is_odd, is_even
This commit is contained in:
parent
9ff74b52eb
commit
3f434dd7e1
6 changed files with 34 additions and 8 deletions
|
@ -4,18 +4,27 @@
|
|||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
#include <sprout/math/isfinite.hpp>
|
||||
#include <sprout/math/fmod.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace math {
|
||||
namespace detail {
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
is_even_unchecked(T x) {
|
||||
return sprout::math::fmod(x, T(2)) == T(0);
|
||||
}
|
||||
|
||||
template<
|
||||
typename FloatType,
|
||||
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
is_even(FloatType x) {
|
||||
return sprout::math::fmod(x, FloatType(2)) == FloatType(0);
|
||||
return sprout::math::isfinite(x)
|
||||
&& sprout::math::detail::is_even_unchecked(x)
|
||||
;
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue