#ifndef SPROUT_MATH_LOG2_HPP #define SPROUT_MATH_LOG2_HPP #include #include #include #include #include #include #include #include #include namespace sprout { namespace math { namespace detail { template inline SPROUT_CONSTEXPR T log2_impl(T x) { return sprout::math::log(x) / sprout::math::ln_two(); } template< typename FloatType, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR FloatType log2(FloatType x) { return x == 0 ? -std::numeric_limits::infinity() : x == std::numeric_limits::infinity() ? std::numeric_limits::infinity() : x < 0 ? std::numeric_limits::quiet_NaN() #if SPROUT_USE_BUILTIN_CMATH_FUNCTION : std::log2(x) #else : x == 1 ? FloatType(0) : static_cast(sprout::math::detail::log2_impl(static_cast::type>(x))) #endif ; } template< typename IntType, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR double log2(IntType x) { return sprout::math::detail::log2(static_cast(x)); } } // namespace detail // // log2 // template< typename ArithmeticType, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR typename sprout::float_promote::type log2(ArithmeticType x) { return sprout::math::detail::log2(x); } } // namespace math using sprout::math::log2; } // namespace sprout #endif // #ifndef SPROUT_MATH_LOG2_HPP