1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +00:00
Sprout/sprout/math/ilogb.hpp

48 lines
1.2 KiB
C++
Raw Normal View History

2013-02-07 09:14:50 +00:00
#ifndef SPROUT_MATH_ILOGB_HPP
#define SPROUT_MATH_ILOGB_HPP
#include <climits>
#include <cfloat>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/math/detail/config.hpp>
#include <sprout/math/logb.hpp>
#include <sprout/math/isnan.hpp>
#include <sprout/math/isinf.hpp>
#include <sprout/math/iszero.hpp>
#include <sprout/type_traits/enabler_if.hpp>
namespace sprout {
namespace math {
namespace detail {
template<
typename FloatType,
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR int
ilogb(FloatType x) {
2013-04-23 10:03:03 +00:00
return sprout::iszero(x) ? FP_ILOGB0
: sprout::isinf(x) ? INT_MAX
: sprout::isnan(x) ? FP_ILOGBNAN
: static_cast<int>(sprout::logb(x))
2013-02-07 09:14:50 +00:00
;
}
template<
typename IntType,
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR int
ilogb(IntType x) {
return sprout::math::detail::ilogb(static_cast<double>(x));
}
} // namespace detail
using NS_SPROUT_MATH_DETAIL::ilogb;
} // namespace math
using sprout::math::ilogb;
} // namespace sprout
#endif // #ifndef SPROUT_MATH_ILOGB_HPP