]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/math/concepts/std_real_concept.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / math / concepts / std_real_concept.hpp
1 // Copyright John Maddock 2006.
2 // Use, modification and distribution are subject to the
3 // Boost Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 // std_real_concept is an archetype for built-in Real types.
7
8 // The main purpose in providing this type is to verify
9 // that std lib functions are found via a using declaration
10 // bringing those functions into the current scope, and not
11 // just because they happen to be in global scope.
12 //
13 // If ::pow is found rather than std::pow say, then the code
14 // will silently compile, but truncation of long doubles to
15 // double will cause a significant loss of precision.
16 // A template instantiated with std_real_concept will *only*
17 // compile if it std::whatever is in scope.
18
19 #include <boost/config.hpp>
20 #include <boost/limits.hpp>
21 #include <boost/math/policies/policy.hpp>
22 #include <boost/math/special_functions/math_fwd.hpp>
23
24 #include <ostream>
25 #include <istream>
26 #include <boost/config/no_tr1/cmath.hpp>
27 #include <math.h> // fmodl
28
29 #ifndef BOOST_MATH_STD_REAL_CONCEPT_HPP
30 #define BOOST_MATH_STD_REAL_CONCEPT_HPP
31
32 namespace boost{ namespace math{
33
34 namespace concepts
35 {
36
37 #ifdef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
38 typedef double std_real_concept_base_type;
39 #else
40 typedef long double std_real_concept_base_type;
41 #endif
42
43 class std_real_concept
44 {
45 public:
46 // Constructors:
47 std_real_concept() : m_value(0){}
48 std_real_concept(char c) : m_value(c){}
49 #ifndef BOOST_NO_INTRINSIC_WCHAR_T
50 std_real_concept(wchar_t c) : m_value(c){}
51 #endif
52 std_real_concept(unsigned char c) : m_value(c){}
53 std_real_concept(signed char c) : m_value(c){}
54 std_real_concept(unsigned short c) : m_value(c){}
55 std_real_concept(short c) : m_value(c){}
56 std_real_concept(unsigned int c) : m_value(c){}
57 std_real_concept(int c) : m_value(c){}
58 std_real_concept(unsigned long c) : m_value(c){}
59 std_real_concept(long c) : m_value(c){}
60 #if defined(__DECCXX) || defined(__SUNPRO_CC)
61 std_real_concept(unsigned long long c) : m_value(static_cast<std_real_concept_base_type>(c)){}
62 std_real_concept(long long c) : m_value(static_cast<std_real_concept_base_type>(c)){}
63 #elif defined(BOOST_HAS_LONG_LONG)
64 std_real_concept(boost::ulong_long_type c) : m_value(static_cast<std_real_concept_base_type>(c)){}
65 std_real_concept(boost::long_long_type c) : m_value(static_cast<std_real_concept_base_type>(c)){}
66 #endif
67 std_real_concept(float c) : m_value(c){}
68 std_real_concept(double c) : m_value(c){}
69 std_real_concept(long double c) : m_value(c){}
70 #ifdef BOOST_MATH_USE_FLOAT128
71 std_real_concept(BOOST_MATH_FLOAT128_TYPE c) : m_value(c){}
72 #endif
73
74 // Assignment:
75 std_real_concept& operator=(char c) { m_value = c; return *this; }
76 std_real_concept& operator=(unsigned char c) { m_value = c; return *this; }
77 std_real_concept& operator=(signed char c) { m_value = c; return *this; }
78 #ifndef BOOST_NO_INTRINSIC_WCHAR_T
79 std_real_concept& operator=(wchar_t c) { m_value = c; return *this; }
80 #endif
81 std_real_concept& operator=(short c) { m_value = c; return *this; }
82 std_real_concept& operator=(unsigned short c) { m_value = c; return *this; }
83 std_real_concept& operator=(int c) { m_value = c; return *this; }
84 std_real_concept& operator=(unsigned int c) { m_value = c; return *this; }
85 std_real_concept& operator=(long c) { m_value = c; return *this; }
86 std_real_concept& operator=(unsigned long c) { m_value = c; return *this; }
87 #if defined(__DECCXX) || defined(__SUNPRO_CC)
88 std_real_concept& operator=(unsigned long long c) { m_value = static_cast<std_real_concept_base_type>(c); return *this; }
89 std_real_concept& operator=(long long c) { m_value = static_cast<std_real_concept_base_type>(c); return *this; }
90 #elif defined(BOOST_HAS_LONG_LONG)
91 std_real_concept& operator=(boost::long_long_type c) { m_value = static_cast<std_real_concept_base_type>(c); return *this; }
92 std_real_concept& operator=(boost::ulong_long_type c) { m_value = static_cast<std_real_concept_base_type>(c); return *this; }
93 #endif
94 std_real_concept& operator=(float c) { m_value = c; return *this; }
95 std_real_concept& operator=(double c) { m_value = c; return *this; }
96 std_real_concept& operator=(long double c) { m_value = c; return *this; }
97
98 // Access:
99 std_real_concept_base_type value()const{ return m_value; }
100
101 // Member arithmetic:
102 std_real_concept& operator+=(const std_real_concept& other)
103 { m_value += other.value(); return *this; }
104 std_real_concept& operator-=(const std_real_concept& other)
105 { m_value -= other.value(); return *this; }
106 std_real_concept& operator*=(const std_real_concept& other)
107 { m_value *= other.value(); return *this; }
108 std_real_concept& operator/=(const std_real_concept& other)
109 { m_value /= other.value(); return *this; }
110 std_real_concept operator-()const
111 { return -m_value; }
112 std_real_concept const& operator+()const
113 { return *this; }
114
115 private:
116 std_real_concept_base_type m_value;
117 };
118
119 // Non-member arithmetic:
120 inline std_real_concept operator+(const std_real_concept& a, const std_real_concept& b)
121 {
122 std_real_concept result(a);
123 result += b;
124 return result;
125 }
126 inline std_real_concept operator-(const std_real_concept& a, const std_real_concept& b)
127 {
128 std_real_concept result(a);
129 result -= b;
130 return result;
131 }
132 inline std_real_concept operator*(const std_real_concept& a, const std_real_concept& b)
133 {
134 std_real_concept result(a);
135 result *= b;
136 return result;
137 }
138 inline std_real_concept operator/(const std_real_concept& a, const std_real_concept& b)
139 {
140 std_real_concept result(a);
141 result /= b;
142 return result;
143 }
144
145 // Comparison:
146 inline bool operator == (const std_real_concept& a, const std_real_concept& b)
147 { return a.value() == b.value(); }
148 inline bool operator != (const std_real_concept& a, const std_real_concept& b)
149 { return a.value() != b.value();}
150 inline bool operator < (const std_real_concept& a, const std_real_concept& b)
151 { return a.value() < b.value(); }
152 inline bool operator <= (const std_real_concept& a, const std_real_concept& b)
153 { return a.value() <= b.value(); }
154 inline bool operator > (const std_real_concept& a, const std_real_concept& b)
155 { return a.value() > b.value(); }
156 inline bool operator >= (const std_real_concept& a, const std_real_concept& b)
157 { return a.value() >= b.value(); }
158
159 } // namespace concepts
160 } // namespace math
161 } // namespace boost
162
163 namespace std{
164
165 // Non-member functions:
166 inline boost::math::concepts::std_real_concept acos(boost::math::concepts::std_real_concept a)
167 { return std::acos(a.value()); }
168 inline boost::math::concepts::std_real_concept cos(boost::math::concepts::std_real_concept a)
169 { return std::cos(a.value()); }
170 inline boost::math::concepts::std_real_concept asin(boost::math::concepts::std_real_concept a)
171 { return std::asin(a.value()); }
172 inline boost::math::concepts::std_real_concept atan(boost::math::concepts::std_real_concept a)
173 { return std::atan(a.value()); }
174 inline boost::math::concepts::std_real_concept atan2(boost::math::concepts::std_real_concept a, boost::math::concepts::std_real_concept b)
175 { return std::atan2(a.value(), b.value()); }
176 inline boost::math::concepts::std_real_concept ceil(boost::math::concepts::std_real_concept a)
177 { return std::ceil(a.value()); }
178 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
179 inline boost::math::concepts::std_real_concept fmod(boost::math::concepts::std_real_concept a, boost::math::concepts::std_real_concept b)
180 { return fmodl(a.value(), b.value()); }
181 #else
182 inline boost::math::concepts::std_real_concept fmod(boost::math::concepts::std_real_concept a, boost::math::concepts::std_real_concept b)
183 { return std::fmod(a.value(), b.value()); }
184 #endif
185 inline boost::math::concepts::std_real_concept cosh(boost::math::concepts::std_real_concept a)
186 { return std::cosh(a.value()); }
187 inline boost::math::concepts::std_real_concept exp(boost::math::concepts::std_real_concept a)
188 { return std::exp(a.value()); }
189 inline boost::math::concepts::std_real_concept fabs(boost::math::concepts::std_real_concept a)
190 { return std::fabs(a.value()); }
191 inline boost::math::concepts::std_real_concept abs(boost::math::concepts::std_real_concept a)
192 { return std::abs(a.value()); }
193 inline boost::math::concepts::std_real_concept floor(boost::math::concepts::std_real_concept a)
194 { return std::floor(a.value()); }
195 inline boost::math::concepts::std_real_concept modf(boost::math::concepts::std_real_concept a, boost::math::concepts::std_real_concept* ipart)
196 {
197 boost::math::concepts::std_real_concept_base_type ip;
198 boost::math::concepts::std_real_concept_base_type result = std::modf(a.value(), &ip);
199 *ipart = ip;
200 return result;
201 }
202 inline boost::math::concepts::std_real_concept frexp(boost::math::concepts::std_real_concept a, int* expon)
203 { return std::frexp(a.value(), expon); }
204 inline boost::math::concepts::std_real_concept ldexp(boost::math::concepts::std_real_concept a, int expon)
205 { return std::ldexp(a.value(), expon); }
206 inline boost::math::concepts::std_real_concept log(boost::math::concepts::std_real_concept a)
207 { return std::log(a.value()); }
208 inline boost::math::concepts::std_real_concept log10(boost::math::concepts::std_real_concept a)
209 { return std::log10(a.value()); }
210 inline boost::math::concepts::std_real_concept tan(boost::math::concepts::std_real_concept a)
211 { return std::tan(a.value()); }
212 inline boost::math::concepts::std_real_concept pow(boost::math::concepts::std_real_concept a, boost::math::concepts::std_real_concept b)
213 { return std::pow(a.value(), b.value()); }
214 #if !defined(__SUNPRO_CC)
215 inline boost::math::concepts::std_real_concept pow(boost::math::concepts::std_real_concept a, int b)
216 { return std::pow(a.value(), b); }
217 #else
218 inline boost::math::concepts::std_real_concept pow(boost::math::concepts::std_real_concept a, int b)
219 { return std::pow(a.value(), static_cast<long double>(b)); }
220 #endif
221 inline boost::math::concepts::std_real_concept sin(boost::math::concepts::std_real_concept a)
222 { return std::sin(a.value()); }
223 inline boost::math::concepts::std_real_concept sinh(boost::math::concepts::std_real_concept a)
224 { return std::sinh(a.value()); }
225 inline boost::math::concepts::std_real_concept sqrt(boost::math::concepts::std_real_concept a)
226 { return std::sqrt(a.value()); }
227 inline boost::math::concepts::std_real_concept tanh(boost::math::concepts::std_real_concept a)
228 { return std::tanh(a.value()); }
229 //
230 // C++11 ism's
231 // Note that these must not actually call the std:: versions as that precludes using this
232 // header to test in C++03 mode, call the Boost versions instead:
233 //
234 inline boost::math::concepts::std_real_concept asinh(boost::math::concepts::std_real_concept a)
235 { return boost::math::asinh(a.value(), boost::math::policies::make_policy(boost::math::policies::overflow_error<boost::math::policies::ignore_error>())); }
236 inline boost::math::concepts::std_real_concept acosh(boost::math::concepts::std_real_concept a)
237 { return boost::math::acosh(a.value(), boost::math::policies::make_policy(boost::math::policies::overflow_error<boost::math::policies::ignore_error>())); }
238 inline boost::math::concepts::std_real_concept atanh(boost::math::concepts::std_real_concept a)
239 { return boost::math::atanh(a.value(), boost::math::policies::make_policy(boost::math::policies::overflow_error<boost::math::policies::ignore_error>())); }
240
241
242 } // namespace std
243
244 #include <boost/math/special_functions/round.hpp>
245 #include <boost/math/special_functions/trunc.hpp>
246 #include <boost/math/special_functions/modf.hpp>
247 #include <boost/math/tools/precision.hpp>
248
249 namespace boost{ namespace math{ namespace concepts{
250
251 //
252 // Conversion and truncation routines:
253 //
254 template <class Policy>
255 inline int iround(const concepts::std_real_concept& v, const Policy& pol)
256 {
257 return boost::math::iround(v.value(), pol);
258 }
259 inline int iround(const concepts::std_real_concept& v)
260 {
261 return boost::math::iround(v.value(), policies::policy<>());
262 }
263
264 template <class Policy>
265 inline long lround(const concepts::std_real_concept& v, const Policy& pol)
266 {
267 return boost::math::lround(v.value(), pol);
268 }
269 inline long lround(const concepts::std_real_concept& v)
270 {
271 return boost::math::lround(v.value(), policies::policy<>());
272 }
273
274 #ifdef BOOST_HAS_LONG_LONG
275
276 template <class Policy>
277 inline boost::long_long_type llround(const concepts::std_real_concept& v, const Policy& pol)
278 {
279 return boost::math::llround(v.value(), pol);
280 }
281 inline boost::long_long_type llround(const concepts::std_real_concept& v)
282 {
283 return boost::math::llround(v.value(), policies::policy<>());
284 }
285
286 #endif
287
288 template <class Policy>
289 inline int itrunc(const concepts::std_real_concept& v, const Policy& pol)
290 {
291 return boost::math::itrunc(v.value(), pol);
292 }
293 inline int itrunc(const concepts::std_real_concept& v)
294 {
295 return boost::math::itrunc(v.value(), policies::policy<>());
296 }
297
298 template <class Policy>
299 inline long ltrunc(const concepts::std_real_concept& v, const Policy& pol)
300 {
301 return boost::math::ltrunc(v.value(), pol);
302 }
303 inline long ltrunc(const concepts::std_real_concept& v)
304 {
305 return boost::math::ltrunc(v.value(), policies::policy<>());
306 }
307
308 #ifdef BOOST_HAS_LONG_LONG
309
310 template <class Policy>
311 inline boost::long_long_type lltrunc(const concepts::std_real_concept& v, const Policy& pol)
312 {
313 return boost::math::lltrunc(v.value(), pol);
314 }
315 inline boost::long_long_type lltrunc(const concepts::std_real_concept& v)
316 {
317 return boost::math::lltrunc(v.value(), policies::policy<>());
318 }
319
320 #endif
321
322 // Streaming:
323 template <class charT, class traits>
324 inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os, const std_real_concept& a)
325 {
326 return os << a.value();
327 }
328 template <class charT, class traits>
329 inline std::basic_istream<charT, traits>& operator>>(std::basic_istream<charT, traits>& is, std_real_concept& a)
330 {
331 #if defined(__SGI_STL_PORT) || defined(_RWSTD_VER) || defined(__LIBCOMO__) || defined(_LIBCPP_VERSION)
332 std::string s;
333 std_real_concept_base_type d;
334 is >> s;
335 std::sscanf(s.c_str(), "%Lf", &d);
336 a = d;
337 return is;
338 #else
339 std_real_concept_base_type v;
340 is >> v;
341 a = v;
342 return is;
343 #endif
344 }
345
346 } // namespace concepts
347 }}
348
349 #include <boost/math/tools/precision.hpp>
350 #include <boost/math/tools/big_constant.hpp>
351
352 namespace boost{ namespace math{
353 namespace tools
354 {
355
356 template <>
357 inline concepts::std_real_concept make_big_value<concepts::std_real_concept>(boost::math::tools::largest_float val, const char*, mpl::false_ const&, mpl::false_ const&)
358 {
359 return val; // Can't use lexical_cast here, sometimes it fails....
360 }
361
362 template <>
363 inline concepts::std_real_concept max_value<concepts::std_real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept))
364 {
365 return max_value<concepts::std_real_concept_base_type>();
366 }
367
368 template <>
369 inline concepts::std_real_concept min_value<concepts::std_real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept))
370 {
371 return min_value<concepts::std_real_concept_base_type>();
372 }
373
374 template <>
375 inline concepts::std_real_concept log_max_value<concepts::std_real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept))
376 {
377 return log_max_value<concepts::std_real_concept_base_type>();
378 }
379
380 template <>
381 inline concepts::std_real_concept log_min_value<concepts::std_real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept))
382 {
383 return log_min_value<concepts::std_real_concept_base_type>();
384 }
385
386 template <>
387 inline concepts::std_real_concept epsilon(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept))
388 {
389 return tools::epsilon<concepts::std_real_concept_base_type>();
390 }
391
392 template <>
393 inline BOOST_MATH_CONSTEXPR int digits<concepts::std_real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept)) BOOST_NOEXCEPT
394 { // Assume number of significand bits is same as std_real_concept_base_type,
395 // unless std::numeric_limits<T>::is_specialized to provide digits.
396 return digits<concepts::std_real_concept_base_type>();
397 }
398
399 } // namespace tools
400
401 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1310)
402 using concepts::itrunc;
403 using concepts::ltrunc;
404 using concepts::lltrunc;
405 using concepts::iround;
406 using concepts::lround;
407 using concepts::llround;
408 #endif
409
410 } // namespace math
411 } // namespace boost
412
413 //
414 // These must go at the end, as they include stuff that won't compile until
415 // after std_real_concept has been defined:
416 //
417 #include <boost/math/special_functions/acosh.hpp>
418 #include <boost/math/special_functions/asinh.hpp>
419 #include <boost/math/special_functions/atanh.hpp>
420
421 #endif // BOOST_MATH_STD_REAL_CONCEPT_HPP