1
0
Fork 0
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:
bolero-MURAKAMI 2013-05-09 01:15:44 +09:00
parent 9ff74b52eb
commit 3f434dd7e1
6 changed files with 34 additions and 8 deletions

View file

@ -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