1///////////////////////////////////////////////////////////////
2// Copyright 2012 John Maddock. Distributed under the Boost
3// Software License, Version 1.0. (See accompanying file
4// LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
5
6#ifndef BOOST_MP_DETAIL_DIGITS_HPP
7#define BOOST_MP_DETAIL_DIGITS_HPP
8
9namespace boost { namespace multiprecision { namespace detail {
10
11inline constexpr unsigned long digits10_2_2(unsigned long d10)
12{
13 return (d10 * 1000uL) / 301uL + ((d10 * 1000uL) % 301 ? 2u : 1u);
14}
15
16inline constexpr unsigned long digits2_2_10(unsigned long d2)
17{
18 return (d2 * 301uL) / 1000uL;
19}
20
21
22#if ULONG_MAX != SIZE_MAX
23
24inline constexpr std::size_t digits10_2_2(std::size_t d10)
25{
26 return (d10 * 1000uL) / 301uL + ((d10 * 1000uL) % 301 ? 2u : 1u);
27}
28
29inline constexpr std::size_t digits2_2_10(std::size_t d2)
30{
31 return (d2 * 301uL) / 1000uL;
32}
33
34template <class I>
35inline constexpr typename std::enable_if<sizeof(I) <= sizeof(unsigned long), unsigned long>::type digits10_2_2(I d10)
36{
37 return digits10_2_2(static_cast<unsigned long>(d10));
38}
39
40template <class I>
41inline constexpr typename std::enable_if<sizeof(I) <= sizeof(unsigned long), unsigned long>::type digits2_2_10(I d10)
42{
43 return digits2_2_10(static_cast<unsigned long>(d10));
44}
45#endif
46
47}}} // namespace boost::multiprecision::detail
48
49#endif
50

source code of boost/libs/multiprecision/include/boost/multiprecision/detail/digits.hpp