]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/multiprecision/include/boost/multiprecision/concepts/mp_number_archetypes.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / multiprecision / include / boost / multiprecision / concepts / mp_number_archetypes.hpp
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 http://www.boost.org/LICENSE_1_
5
6 #ifndef BOOST_MATH_CONCEPTS_ER_HPP
7 #define BOOST_MATH_CONCEPTS_ER_HPP
8
9 #include <iostream>
10 #include <sstream>
11 #include <iomanip>
12 #include <cmath>
13 #include <boost/cstdint.hpp>
14 #include <boost/multiprecision/number.hpp>
15 #include <boost/math/special_functions/fpclassify.hpp>
16 #include <boost/mpl/list.hpp>
17
18 namespace boost{
19 namespace multiprecision{
20 namespace concepts{
21
22 #ifdef BOOST_MSVC
23 #pragma warning(push)
24 #pragma warning(disable:4244)
25 #endif
26
27 struct number_backend_float_architype
28 {
29 typedef mpl::list<boost::long_long_type> signed_types;
30 typedef mpl::list<boost::ulong_long_type> unsigned_types;
31 typedef mpl::list<long double> float_types;
32 typedef int exponent_type;
33
34 number_backend_float_architype()
35 {
36 m_value = 0;
37 std::cout << "Default construct" << std::endl;
38 }
39 number_backend_float_architype(const number_backend_float_architype& o)
40 {
41 std::cout << "Copy construct" << std::endl;
42 m_value = o.m_value;
43 }
44 number_backend_float_architype& operator = (const number_backend_float_architype& o)
45 {
46 m_value = o.m_value;
47 std::cout << "Assignment (" << m_value << ")" << std::endl;
48 return *this;
49 }
50 number_backend_float_architype& operator = (boost::ulong_long_type i)
51 {
52 m_value = i;
53 std::cout << "UInt Assignment (" << i << ")" << std::endl;
54 return *this;
55 }
56 number_backend_float_architype& operator = (boost::long_long_type i)
57 {
58 m_value = i;
59 std::cout << "Int Assignment (" << i << ")" << std::endl;
60 return *this;
61 }
62 number_backend_float_architype& operator = (long double d)
63 {
64 m_value = d;
65 std::cout << "long double Assignment (" << d << ")" << std::endl;
66 return *this;
67 }
68 number_backend_float_architype& operator = (const char* s)
69 {
70 #ifndef BOOST_NO_EXCEPTIONS
71 try
72 {
73 #endif
74 m_value = boost::lexical_cast<long double>(s);
75 #ifndef BOOST_NO_EXCEPTIONS
76 }
77 catch(const std::exception&)
78 {
79 BOOST_THROW_EXCEPTION(std::runtime_error(std::string("Unable to parse input string: \"") + s + std::string("\" as a valid floating point number.")));
80 }
81 #endif
82 std::cout << "const char* Assignment (" << s << ")" << std::endl;
83 return *this;
84 }
85 void swap(number_backend_float_architype& o)
86 {
87 std::cout << "Swapping (" << m_value << " with " << o.m_value << ")" << std::endl;
88 std::swap(m_value, o.m_value);
89 }
90 std::string str(std::streamsize digits, std::ios_base::fmtflags f)const
91 {
92 std::stringstream ss;
93 ss.flags(f);
94 if(digits)
95 ss.precision(digits);
96 else
97 ss.precision(std::numeric_limits<long double>::digits10 + 3);
98 boost::intmax_t i = m_value;
99 boost::uintmax_t u = m_value;
100 if(!(f & std::ios_base::scientific) && m_value == i)
101 ss << i;
102 else if(!(f & std::ios_base::scientific) && m_value == u)
103 ss << u;
104 else
105 ss << m_value;
106 std::string s = ss.str();
107 std::cout << "Converting to string (" << s << ")" << std::endl;
108 return s;
109 }
110 void negate()
111 {
112 std::cout << "Negating (" << m_value << ")" << std::endl;
113 m_value = -m_value;
114 }
115 int compare(const number_backend_float_architype& o)const
116 {
117 std::cout << "Comparison" << std::endl;
118 return m_value > o.m_value ? 1 : (m_value < o.m_value ? -1 : 0);
119 }
120 int compare(boost::long_long_type i)const
121 {
122 std::cout << "Comparison with int" << std::endl;
123 return m_value > i ? 1 : (m_value < i ? -1 : 0);
124 }
125 int compare(boost::ulong_long_type i)const
126 {
127 std::cout << "Comparison with unsigned" << std::endl;
128 return m_value > i ? 1 : (m_value < i ? -1 : 0);
129 }
130 int compare(long double d)const
131 {
132 std::cout << "Comparison with long double" << std::endl;
133 return m_value > d ? 1 : (m_value < d ? -1 : 0);
134 }
135 long double m_value;
136 };
137
138 inline void eval_add(number_backend_float_architype& result, const number_backend_float_architype& o)
139 {
140 std::cout << "Addition (" << result.m_value << " += " << o.m_value << ")" << std::endl;
141 result.m_value += o.m_value;
142 }
143 inline void eval_subtract(number_backend_float_architype& result, const number_backend_float_architype& o)
144 {
145 std::cout << "Subtraction (" << result.m_value << " -= " << o.m_value << ")" << std::endl;
146 result.m_value -= o.m_value;
147 }
148 inline void eval_multiply(number_backend_float_architype& result, const number_backend_float_architype& o)
149 {
150 std::cout << "Multiplication (" << result.m_value << " *= " << o.m_value << ")" << std::endl;
151 result.m_value *= o.m_value;
152 }
153 inline void eval_divide(number_backend_float_architype& result, const number_backend_float_architype& o)
154 {
155 std::cout << "Division (" << result.m_value << " /= " << o.m_value << ")" << std::endl;
156 result.m_value /= o.m_value;
157 }
158
159 inline void eval_convert_to(boost::ulong_long_type* result, const number_backend_float_architype& val)
160 {
161 *result = static_cast<boost::ulong_long_type>(val.m_value);
162 }
163 inline void eval_convert_to(boost::long_long_type* result, const number_backend_float_architype& val)
164 {
165 *result = static_cast<boost::long_long_type>(val.m_value);
166 }
167 inline void eval_convert_to(long double* result, number_backend_float_architype& val)
168 {
169 *result = val.m_value;
170 }
171
172 inline void eval_frexp(number_backend_float_architype& result, const number_backend_float_architype& arg, int* exp)
173 {
174 result = std::frexp(arg.m_value, exp);
175 }
176
177 inline void eval_ldexp(number_backend_float_architype& result, const number_backend_float_architype& arg, int exp)
178 {
179 result = std::ldexp(arg.m_value, exp);
180 }
181
182 inline void eval_floor(number_backend_float_architype& result, const number_backend_float_architype& arg)
183 {
184 result = std::floor(arg.m_value);
185 }
186
187 inline void eval_ceil(number_backend_float_architype& result, const number_backend_float_architype& arg)
188 {
189 result = std::ceil(arg.m_value);
190 }
191
192 inline void eval_sqrt(number_backend_float_architype& result, const number_backend_float_architype& arg)
193 {
194 result = std::sqrt(arg.m_value);
195 }
196
197 inline int eval_fpclassify(const number_backend_float_architype& arg)
198 {
199 return (boost::math::fpclassify)(arg.m_value);
200 }
201
202 typedef boost::multiprecision::number<number_backend_float_architype> mp_number_float_architype;
203
204 } // namespace
205
206 template<>
207 struct number_category<concepts::number_backend_float_architype> : public mpl::int_<number_kind_floating_point>{};
208
209 }} // namespaces
210
211 namespace std{
212
213 template <boost::multiprecision::expression_template_option ExpressionTemplates>
214 class numeric_limits<boost::multiprecision::number<boost::multiprecision::concepts::number_backend_float_architype, ExpressionTemplates> > : public std::numeric_limits<long double>
215 {
216 typedef std::numeric_limits<long double> base_type;
217 typedef boost::multiprecision::number<boost::multiprecision::concepts::number_backend_float_architype, ExpressionTemplates> number_type;
218 public:
219 static number_type (min)() BOOST_NOEXCEPT { return (base_type::min)(); }
220 static number_type (max)() BOOST_NOEXCEPT { return (base_type::max)(); }
221 static number_type lowest() BOOST_NOEXCEPT { return -(max)(); }
222 static number_type epsilon() BOOST_NOEXCEPT { return base_type::epsilon(); }
223 static number_type round_error() BOOST_NOEXCEPT { return base_type::round_error(); }
224 static number_type infinity() BOOST_NOEXCEPT { return base_type::infinity(); }
225 static number_type quiet_NaN() BOOST_NOEXCEPT { return base_type::quiet_NaN(); }
226 static number_type signaling_NaN() BOOST_NOEXCEPT { return base_type::signaling_NaN(); }
227 static number_type denorm_min() BOOST_NOEXCEPT { return base_type::denorm_min(); }
228 };
229
230 }
231
232 #ifdef BOOST_MSVC
233 #pragma warning(pop)
234 #endif
235
236 #endif