]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/include/boost/math/tools/big_constant.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / math / include / boost / math / tools / big_constant.hpp
1
2 // Copyright (c) 2011 John Maddock
3 // Use, modification and distribution are subject to the
4 // Boost Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7 #ifndef BOOST_MATH_TOOLS_BIG_CONSTANT_HPP
8 #define BOOST_MATH_TOOLS_BIG_CONSTANT_HPP
9
10 #include <boost/math/tools/config.hpp>
11 #ifndef BOOST_MATH_NO_LEXICAL_CAST
12 #include <boost/lexical_cast.hpp>
13 #endif
14 #include <boost/type_traits/is_convertible.hpp>
15
16 namespace boost{ namespace math{
17
18 namespace tools{
19
20 template <class T>
21 struct numeric_traits : public std::numeric_limits< T > {};
22
23 #ifdef BOOST_MATH_USE_FLOAT128
24 typedef __float128 largest_float;
25 #define BOOST_MATH_LARGEST_FLOAT_C(x) x##Q
26 template <>
27 struct numeric_traits<__float128>
28 {
29 static const int digits = 113;
30 static const int digits10 = 33;
31 static const int max_exponent = 16384;
32 static const bool is_specialized = true;
33 };
34 #else
35 typedef long double largest_float;
36 #define BOOST_MATH_LARGEST_FLOAT_C(x) x##L
37 #endif
38
39 template <class T>
40 inline BOOST_CONSTEXPR_OR_CONST T make_big_value(largest_float v, const char*, mpl::true_ const&, mpl::false_ const&) BOOST_MATH_NOEXCEPT(T)
41 {
42 return static_cast<T>(v);
43 }
44 template <class T>
45 inline BOOST_CONSTEXPR_OR_CONST T make_big_value(largest_float v, const char*, mpl::true_ const&, mpl::true_ const&) BOOST_MATH_NOEXCEPT(T)
46 {
47 return static_cast<T>(v);
48 }
49 #ifndef BOOST_MATH_NO_LEXICAL_CAST
50 template <class T>
51 inline T make_big_value(largest_float, const char* s, mpl::false_ const&, mpl::false_ const&)
52 {
53 return boost::lexical_cast<T>(s);
54 }
55 #endif
56 template <class T>
57 inline BOOST_MATH_CONSTEXPR const char* make_big_value(largest_float, const char* s, mpl::false_ const&, mpl::true_ const&) BOOST_MATH_NOEXCEPT(T)
58 {
59 return s;
60 }
61
62 //
63 // For constants which might fit in a long double (if it's big enough):
64 //
65 #define BOOST_MATH_BIG_CONSTANT(T, D, x)\
66 boost::math::tools::make_big_value<T>(\
67 BOOST_MATH_LARGEST_FLOAT_C(x), \
68 BOOST_STRINGIZE(x), \
69 mpl::bool_< (is_convertible<boost::math::tools::largest_float, T>::value) && \
70 ((D <= boost::math::tools::numeric_traits<boost::math::tools::largest_float>::digits) \
71 || is_floating_point<T>::value \
72 || (boost::math::tools::numeric_traits<T>::is_specialized && \
73 (boost::math::tools::numeric_traits<T>::digits10 <= boost::math::tools::numeric_traits<boost::math::tools::largest_float>::digits10))) >(), \
74 boost::is_convertible<const char*, T>())
75 //
76 // For constants too huge for any conceivable long double (and which generate compiler errors if we try and declare them as such):
77 //
78 #define BOOST_MATH_HUGE_CONSTANT(T, D, x)\
79 boost::math::tools::make_big_value<T>(0.0L, BOOST_STRINGIZE(x), \
80 mpl::bool_<is_floating_point<T>::value || (boost::math::tools::numeric_traits<T>::is_specialized && boost::math::tools::numeric_traits<T>::max_exponent <= boost::math::tools::numeric_traits<boost::math::tools::largest_float>::max_exponent && boost::math::tools::numeric_traits<T>::digits <= boost::math::tools::numeric_traits<boost::math::tools::largest_float>::digits)>(), \
81 boost::is_convertible<const char*, T>())
82
83 }}} // namespaces
84
85 #endif
86