/*============================================================================= Copyright (c) 2011-2019 Bolero MURAKAMI 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) =============================================================================*/ #ifndef SPROUT_MATH_ILOGB2_HPP #define SPROUT_MATH_ILOGB2_HPP #include #include #include #include #include #include #include #if SPROUT_FLT_RADIX_IS_2 # include #else # include # include # include # include #endif namespace sprout { namespace math { #if SPROUT_FLT_RADIX_IS_2 template< typename FloatType, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR int ilogb2(FloatType x) { return sprout::math::ilogb(x); } template< typename IntType, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR int ilogb2(IntType x) { return sprout::math::ilogb(x); } #else template< typename FloatType, typename sprout::enabler_if::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(sprout::math::logb2(x)) ; } template< typename IntType, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR int ilogb2(IntType x) { return sprout::math::ilogb2(static_cast(x)); } #endif } // namespace math using sprout::math::ilogb2; } // namespace sprout #endif // #ifndef SPROUT_MATH_ILOGB2_HPP