Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-13 09:41:40

0001 // Copyright 2024 Matt Borland
0002 // Distributed under the Boost Software License, Version 1.0.
0003 // https://www.boost.org/LICENSE_1_0.txt
0004 
0005 #ifndef BOOST_CHARCONV_DETAIL_BUFFER_SIZING_HPP
0006 #define BOOST_CHARCONV_DETAIL_BUFFER_SIZING_HPP
0007 
0008 #include <boost/charconv/detail/config.hpp>
0009 #include <boost/charconv/detail/integer_search_trees.hpp>
0010 #include <type_traits>
0011 
0012 namespace boost {
0013 namespace charconv {
0014 namespace detail {
0015 
0016 #ifdef BOOST_MSVC
0017 # pragma warning(push)
0018 # pragma warning(disable: 4127) // Conditional expression for BOOST_IF_CONSTEXPR will be constant in not C++17
0019 #endif
0020 
0021 template <typename Real>
0022 inline int get_real_precision(int precision = -1) noexcept
0023 {
0024     // If the user did not specify a precision than we use the maximum representable amount
0025     // and remove trailing zeros at the end
0026 
0027     int real_precision;
0028     BOOST_IF_CONSTEXPR (!std::is_same<Real, long double>::value
0029                         #ifdef BOOST_CHARCONV_HAS_QUADMATH
0030                         && !std::is_same<Real, __float128>::value
0031                         #endif
0032                         )
0033     {
0034         real_precision = precision == -1 ? std::numeric_limits<Real>::max_digits10 : precision;
0035     }
0036     else
0037     {
0038         #ifdef BOOST_CHARCONV_HAS_QUADMATH
0039         BOOST_CHARCONV_IF_CONSTEXPR (std::is_same<Real, __float128>::value)
0040         {
0041             real_precision = 33;
0042         }
0043         else
0044         #endif
0045         {
0046             #if BOOST_CHARCONV_LDBL_BITS == 128
0047             real_precision = 33;
0048             #else
0049             real_precision = 18;
0050             #endif
0051         }
0052     }
0053 
0054     return real_precision;
0055 }
0056 
0057 template <typename Int>
0058 inline int total_buffer_length(int real_precision, Int exp, bool signed_value)
0059 {
0060     // Sign + integer part + '.' + precision of fraction part + e+/e- or p+/p- + exponent digits
0061     return static_cast<int>(signed_value) + 1 + real_precision + 2 + num_digits(exp);
0062 }
0063 
0064 #ifdef BOOST_MSVC
0065 # pragma warning(pop)
0066 #endif
0067 
0068 } //namespace detail
0069 } //namespace charconv
0070 } //namespace boost
0071 
0072 #endif //BOOST_CHARCONV_DETAIL_BUFFER_SIZING_HPP