2013-08-08 09:54:33 +00:00
|
|
|
/*=============================================================================
|
2016-02-25 09:48:28 +00:00
|
|
|
Copyright (c) 2011-2016 Bolero MURAKAMI
|
2013-08-08 09:54:33 +00:00
|
|
|
https://github.com/bolero-MURAKAMI/Sprout
|
|
|
|
|
|
|
|
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
=============================================================================*/
|
2013-02-10 02:54:54 +00:00
|
|
|
#ifndef SPROUT_MATH_ILOGB2_HPP
|
|
|
|
#define SPROUT_MATH_ILOGB2_HPP
|
|
|
|
|
|
|
|
#include <climits>
|
|
|
|
#include <cfloat>
|
2014-04-24 04:35:08 +00:00
|
|
|
#include <cmath>
|
2013-02-10 02:54:54 +00:00
|
|
|
#include <type_traits>
|
|
|
|
#include <sprout/config.hpp>
|
|
|
|
#include <sprout/math/detail/config.hpp>
|
|
|
|
#include <sprout/type_traits/enabler_if.hpp>
|
|
|
|
#if SPROUT_FLT_RADIX_IS_2
|
|
|
|
# include <sprout/math/ilogb.hpp>
|
|
|
|
#else
|
|
|
|
# include <sprout/math/logb2.hpp>
|
|
|
|
# include <sprout/math/isnan.hpp>
|
|
|
|
# include <sprout/math/isinf.hpp>
|
|
|
|
# include <sprout/math/iszero.hpp>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
namespace math {
|
|
|
|
#if SPROUT_FLT_RADIX_IS_2
|
2013-10-25 03:29:16 +00:00
|
|
|
template<
|
|
|
|
typename FloatType,
|
|
|
|
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
|
|
|
|
>
|
|
|
|
inline SPROUT_CONSTEXPR int
|
|
|
|
ilogb2(FloatType x) {
|
|
|
|
return sprout::math::ilogb(x);
|
|
|
|
}
|
|
|
|
template<
|
|
|
|
typename IntType,
|
|
|
|
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
|
|
|
|
>
|
|
|
|
inline SPROUT_CONSTEXPR int
|
|
|
|
ilogb2(IntType x) {
|
|
|
|
return sprout::math::ilogb(x);
|
|
|
|
}
|
2013-02-10 02:54:54 +00:00
|
|
|
#else
|
2013-10-25 03:29:16 +00:00
|
|
|
template<
|
|
|
|
typename FloatType,
|
|
|
|
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
|
|
|
|
>
|
|
|
|
inline SPROUT_CONSTEXPR int
|
|
|
|
ilogb2(FloatType x) {
|
|
|
|
return sprout::math::iszero(x) ? FP_ILOGB0
|
|
|
|
: sprout::math::isinf(x) ? INT_MAX
|
|
|
|
: sprout::math::isnan(x) ? FP_ILOGBNAN
|
|
|
|
: static_cast<int>(sprout::math::logb2(x))
|
|
|
|
;
|
|
|
|
}
|
|
|
|
template<
|
|
|
|
typename IntType,
|
|
|
|
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
|
|
|
|
>
|
|
|
|
inline SPROUT_CONSTEXPR int
|
|
|
|
ilogb2(IntType x) {
|
|
|
|
return sprout::math::ilogb2(static_cast<double>(x));
|
|
|
|
}
|
2013-02-10 02:54:54 +00:00
|
|
|
#endif
|
|
|
|
} // namespace math
|
|
|
|
|
|
|
|
using sprout::math::ilogb2;
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_MATH_ILOGB2_HPP
|