/*============================================================================= Copyright (c) 2011-2014 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_DETAIL_INT_HPP #define SPROUT_DETAIL_INT_HPP #include #include #include #include #include namespace sprout { namespace detail { // // int_pow // template< typename IntType, int Base = 10, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR IntType int_pow(int exponent) { return exponent ? Base * sprout::detail::int_pow(exponent - 1) : 1 ; } // // int_digits // template inline SPROUT_CONSTEXPR int int_digits_impl(IntType val) { return val ? 1 + sprout::detail::int_digits_impl(val / Base) : 0 ; } template< int Base = 10, typename IntType, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR int int_digits(IntType val) { return val ? 1 + sprout::detail::int_digits_impl(val / Base) : 1 ; } // // int_digit_at // template< int Base = 10, typename IntType, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR int int_digit_at(IntType val, int digits) { return val < 0 ? -((val / sprout::detail::int_pow(digits)) % Base) : (val / sprout::detail::int_pow(digits)) % Base ; } template< int Base = 10, typename IntType, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR int int_digit_at(IntType val, int digits) { return (val / sprout::detail::int_pow(digits)) % Base; } } // namespace detail } // namespace sprout #endif // #ifndef SPROUT_DETAIL_INT_HPP