]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/include/boost/math/concepts/std_real_concept.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / math / include / 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 } // namespace std
231
232 #include <boost/math/special_functions/round.hpp>
233 #include <boost/math/special_functions/trunc.hpp>
234 #include <boost/math/special_functions/modf.hpp>
235 #include <boost/math/tools/precision.hpp>
236
237 namespace boost{ namespace math{ namespace concepts{
238
239 //
240 // Conversion and truncation routines:
241 //
242 template <class Policy>
243 inline int iround(const concepts::std_real_concept& v, const Policy& pol)
244 {
245 return boost::math::iround(v.value(), pol);
246 }
247 inline int iround(const concepts::std_real_concept& v)
248 {
249 return boost::math::iround(v.value(), policies::policy<>());
250 }
251
252 template <class Policy>
253 inline long lround(const concepts::std_real_concept& v, const Policy& pol)
254 {
255 return boost::math::lround(v.value(), pol);
256 }
257 inline long lround(const concepts::std_real_concept& v)
258 {
259 return boost::math::lround(v.value(), policies::policy<>());
260 }
261
262 #ifdef BOOST_HAS_LONG_LONG
263
264 template <class Policy>
265 inline boost::long_long_type llround(const concepts::std_real_concept& v, const Policy& pol)
266 {
267 return boost::math::llround(v.value(), pol);
268 }
269 inline boost::long_long_type llround(const concepts::std_real_concept& v)
270 {
271 return boost::math::llround(v.value(), policies::policy<>());
272 }
273
274 #endif
275
276 template <class Policy>
277 inline int itrunc(const concepts::std_real_concept& v, const Policy& pol)
278 {
279 return boost::math::itrunc(v.value(), pol);
280 }
281 inline int itrunc(const concepts::std_real_concept& v)
282 {
283 return boost::math::itrunc(v.value(), policies::policy<>());
284 }
285
286 template <class Policy>
287 inline long ltrunc(const concepts::std_real_concept& v, const Policy& pol)
288 {
289 return boost::math::ltrunc(v.value(), pol);
290 }
291 inline long ltrunc(const concepts::std_real_concept& v)
292 {
293 return boost::math::ltrunc(v.value(), policies::policy<>());
294 }
295
296 #ifdef BOOST_HAS_LONG_LONG
297
298 template <class Policy>
299 inline boost::long_long_type lltrunc(const concepts::std_real_concept& v, const Policy& pol)
300 {
301 return boost::math::lltrunc(v.value(), pol);
302 }
303 inline boost::long_long_type lltrunc(const concepts::std_real_concept& v)
304 {
305 return boost::math::lltrunc(v.value(), policies::policy<>());
306 }
307
308 #endif
309
310 // Streaming:
311 template <class charT, class traits>
312 inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os, const std_real_concept& a)
313 {
314 return os << a.value();
315 }
316 template <class charT, class traits>
317 inline std::basic_istream<charT, traits>& operator>>(std::basic_istream<charT, traits>& is, std_real_concept& a)
318 {
319 #if defined(__SGI_STL_PORT) || defined(_RWSTD_VER) || defined(__LIBCOMO__) || defined(_LIBCPP_VERSION)
320 std::string s;
321 std_real_concept_base_type d;
322 is >> s;
323 std::sscanf(s.c_str(), "%Lf", &d);
324 a = d;
325 return is;
326 #else
327 std_real_concept_base_type v;
328 is >> v;
329 a = v;
330 return is;
331 #endif
332 }
333
334 } // namespace concepts
335 }}
336
337 #include <boost/math/tools/precision.hpp>
338 #include <boost/math/tools/big_constant.hpp>
339
340 namespace boost{ namespace math{
341 namespace tools
342 {
343
344 template <>
345 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&)
346 {
347 return val; // Can't use lexical_cast here, sometimes it fails....
348 }
349
350 template <>
351 inline concepts::std_real_concept max_value<concepts::std_real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept))
352 {
353 return max_value<concepts::std_real_concept_base_type>();
354 }
355
356 template <>
357 inline concepts::std_real_concept min_value<concepts::std_real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept))
358 {
359 return min_value<concepts::std_real_concept_base_type>();
360 }
361
362 template <>
363 inline concepts::std_real_concept log_max_value<concepts::std_real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept))
364 {
365 return log_max_value<concepts::std_real_concept_base_type>();
366 }
367
368 template <>
369 inline concepts::std_real_concept log_min_value<concepts::std_real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept))
370 {
371 return log_min_value<concepts::std_real_concept_base_type>();
372 }
373
374 template <>
375 inline concepts::std_real_concept epsilon(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept))
376 {
377 return tools::epsilon<concepts::std_real_concept_base_type>();
378 }
379
380 template <>
381 inline BOOST_MATH_CONSTEXPR int digits<concepts::std_real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept)) BOOST_NOEXCEPT
382 { // Assume number of significand bits is same as std_real_concept_base_type,
383 // unless std::numeric_limits<T>::is_specialized to provide digits.
384 return digits<concepts::std_real_concept_base_type>();
385 }
386
387 } // namespace tools
388
389 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1310)
390 using concepts::itrunc;
391 using concepts::ltrunc;
392 using concepts::lltrunc;
393 using concepts::iround;
394 using concepts::lround;
395 using concepts::llround;
396 #endif
397
398 } // namespace math
399 } // namespace boost
400
401 #endif // BOOST_MATH_STD_REAL_CONCEPT_HPP
402
403
404
405