]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/math/tools/big_constant.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / 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_constructible.hpp>
15 #include <boost/type_traits/is_convertible.hpp>
16 #include <boost/type_traits/is_floating_point.hpp>
17
18 namespace boost{ namespace math{
19
20 namespace tools{
21
22 template <class T>
23 struct numeric_traits : public std::numeric_limits< T > {};
24
25 #ifdef BOOST_MATH_USE_FLOAT128
26 typedef __float128 largest_float;
27 #define BOOST_MATH_LARGEST_FLOAT_C(x) x##Q
28 template <>
29 struct numeric_traits<__float128>
30 {
31 static const int digits = 113;
32 static const int digits10 = 33;
33 static const int max_exponent = 16384;
34 static const bool is_specialized = true;
35 };
36 #elif LDBL_DIG > DBL_DIG
37 typedef long double largest_float;
38 #define BOOST_MATH_LARGEST_FLOAT_C(x) x##L
39 #else
40 typedef double largest_float;
41 #define BOOST_MATH_LARGEST_FLOAT_C(x) x
42 #endif
43
44 template <class T>
45 inline BOOST_CONSTEXPR_OR_CONST T make_big_value(largest_float v, const char*, boost::true_type const&, boost::false_type const&) BOOST_MATH_NOEXCEPT(T)
46 {
47 return static_cast<T>(v);
48 }
49 template <class T>
50 inline BOOST_CONSTEXPR_OR_CONST T make_big_value(largest_float v, const char*, boost::true_type const&, boost::true_type const&) BOOST_MATH_NOEXCEPT(T)
51 {
52 return static_cast<T>(v);
53 }
54 #ifndef BOOST_MATH_NO_LEXICAL_CAST
55 template <class T>
56 inline T make_big_value(largest_float, const char* s, boost::false_type const&, boost::false_type const&)
57 {
58 return boost::lexical_cast<T>(s);
59 }
60 #endif
61 template <class T>
62 inline BOOST_MATH_CONSTEXPR T make_big_value(largest_float, const char* s, boost::false_type const&, boost::true_type const&) BOOST_MATH_NOEXCEPT(T)
63 {
64 return T(s);
65 }
66
67 //
68 // For constants which might fit in a long double (if it's big enough):
69 //
70 #define BOOST_MATH_BIG_CONSTANT(T, D, x)\
71 boost::math::tools::make_big_value<T>(\
72 BOOST_MATH_LARGEST_FLOAT_C(x), \
73 BOOST_STRINGIZE(x), \
74 boost::integral_constant<bool, (boost::is_convertible<boost::math::tools::largest_float, T>::value) && \
75 ((D <= boost::math::tools::numeric_traits<boost::math::tools::largest_float>::digits) \
76 || boost::is_floating_point<T>::value \
77 || (boost::math::tools::numeric_traits<T>::is_specialized && \
78 (boost::math::tools::numeric_traits<T>::digits10 <= boost::math::tools::numeric_traits<boost::math::tools::largest_float>::digits10))) >(), \
79 boost::is_constructible<T, const char*>())
80 //
81 // For constants too huge for any conceivable long double (and which generate compiler errors if we try and declare them as such):
82 //
83 #define BOOST_MATH_HUGE_CONSTANT(T, D, x)\
84 boost::math::tools::make_big_value<T>(0.0L, BOOST_STRINGIZE(x), \
85 boost::integral_constant<bool, boost::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)>(), \
86 boost::is_constructible<T, const char*>())
87
88 }}} // namespaces
89
90 #endif
91