#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 sprout::math::isnan(x) ? x : x == 0 ? -sprout::numeric_limits::infinity() : x == sprout::numeric_limits::infinity() ? sprout::numeric_limits::infinity() : x < 0 ? sprout::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 using sprout::math::detail::log2; } // namespace math using sprout::math::log2; } // namespace sprout #endif // #ifndef SPROUT_MATH_LOG2_HPP