#ifndef BOOST_NUMERIC_UTILITY_HPP #define BOOST_NUMERIC_UTILITY_HPP // MS compatible compilers support #pragma once #if defined(_MSC_VER) && (_MSC_VER >= 1020) # pragma once #endif // Copyright (c) 2015 Robert Ramey // // 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) #include // intmax_t, uintmax_t #include #include // (u)int_t<>::least, exact namespace boost { namespace numeric { template typename std::enable_if< ! std::is_signed::value, unsigned int >::type constexpr log(T x){ unsigned i = 0; for(; x > 0; ++i) x >>= 1; return i; } template typename std::enable_if< std::is_signed::value, unsigned int >::type constexpr log(T x){ if(x < 0) x = ~x; return log( static_cast::type>(x) ) + 1; } template< std::intmax_t Min, std::intmax_t Max > using signed_stored_type = typename boost::int_t< std::max({log(Min), log(Max)}) >::least ; template< std::uintmax_t Min, std::uintmax_t Max > using unsigned_stored_type = typename boost::uint_t< std::max({log(Min), log(Max)}) >::least ; } // numeric } // boost #endif // BOOST_NUMERIC_UTILITY_HPP