Chris@16
|
1 // Copyright John Maddock 2006.
|
Chris@16
|
2 // Use, modification and distribution are subject to the
|
Chris@16
|
3 // Boost Software License, Version 1.0. (See accompanying file
|
Chris@16
|
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
5
|
Chris@16
|
6 // Test real concept.
|
Chris@16
|
7
|
Chris@16
|
8 // real_concept is an archetype for User defined Real types.
|
Chris@16
|
9
|
Chris@16
|
10 // This file defines the features, constructors, operators, functions...
|
Chris@16
|
11 // that are essential to use mathematical and statistical functions.
|
Chris@16
|
12 // The template typename "RealType" is used where this type
|
Chris@16
|
13 // (as well as the normal built-in types, float, double & long double)
|
Chris@16
|
14 // can be used.
|
Chris@16
|
15 // That this is the minimum set is confirmed by use as a type
|
Chris@16
|
16 // in tests of all functions & distributions, for example:
|
Chris@16
|
17 // test_spots(0.F); & test_spots(0.); for float and double, but also
|
Chris@16
|
18 // test_spots(boost::math::concepts::real_concept(0.));
|
Chris@16
|
19 // NTL quad_float type is an example of a type meeting the requirements,
|
Chris@16
|
20 // but note minor additions are needed - see ntl.diff and documentation
|
Chris@16
|
21 // "Using With NTL - a High-Precision Floating-Point Library".
|
Chris@16
|
22
|
Chris@16
|
23 #ifndef BOOST_MATH_REAL_CONCEPT_HPP
|
Chris@16
|
24 #define BOOST_MATH_REAL_CONCEPT_HPP
|
Chris@16
|
25
|
Chris@16
|
26 #include <boost/config.hpp>
|
Chris@16
|
27 #include <boost/limits.hpp>
|
Chris@16
|
28 #include <boost/math/special_functions/round.hpp>
|
Chris@16
|
29 #include <boost/math/special_functions/trunc.hpp>
|
Chris@16
|
30 #include <boost/math/special_functions/modf.hpp>
|
Chris@16
|
31 #include <boost/math/tools/big_constant.hpp>
|
Chris@16
|
32 #include <boost/math/tools/precision.hpp>
|
Chris@16
|
33 #include <boost/math/policies/policy.hpp>
|
Chris@16
|
34 #if defined(__SGI_STL_PORT)
|
Chris@16
|
35 # include <boost/math/tools/real_cast.hpp>
|
Chris@16
|
36 #endif
|
Chris@16
|
37 #include <ostream>
|
Chris@16
|
38 #include <istream>
|
Chris@16
|
39 #include <boost/config/no_tr1/cmath.hpp>
|
Chris@16
|
40 #include <math.h> // fmodl
|
Chris@16
|
41
|
Chris@16
|
42 #if defined(__SGI_STL_PORT) || defined(_RWSTD_VER) || defined(__LIBCOMO__)
|
Chris@16
|
43 # include <cstdio>
|
Chris@16
|
44 #endif
|
Chris@16
|
45
|
Chris@16
|
46 namespace boost{ namespace math{
|
Chris@16
|
47
|
Chris@16
|
48 namespace concepts
|
Chris@16
|
49 {
|
Chris@16
|
50
|
Chris@16
|
51 #ifdef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
|
Chris@16
|
52 typedef double real_concept_base_type;
|
Chris@16
|
53 #else
|
Chris@16
|
54 typedef long double real_concept_base_type;
|
Chris@16
|
55 #endif
|
Chris@16
|
56
|
Chris@16
|
57 class real_concept
|
Chris@16
|
58 {
|
Chris@16
|
59 public:
|
Chris@16
|
60 // Constructors:
|
Chris@16
|
61 real_concept() : m_value(0){}
|
Chris@16
|
62 real_concept(char c) : m_value(c){}
|
Chris@16
|
63 #ifndef BOOST_NO_INTRINSIC_WCHAR_T
|
Chris@16
|
64 real_concept(wchar_t c) : m_value(c){}
|
Chris@16
|
65 #endif
|
Chris@16
|
66 real_concept(unsigned char c) : m_value(c){}
|
Chris@16
|
67 real_concept(signed char c) : m_value(c){}
|
Chris@16
|
68 real_concept(unsigned short c) : m_value(c){}
|
Chris@16
|
69 real_concept(short c) : m_value(c){}
|
Chris@16
|
70 real_concept(unsigned int c) : m_value(c){}
|
Chris@16
|
71 real_concept(int c) : m_value(c){}
|
Chris@16
|
72 real_concept(unsigned long c) : m_value(c){}
|
Chris@16
|
73 real_concept(long c) : m_value(c){}
|
Chris@16
|
74 #if defined(__DECCXX) || defined(__SUNPRO_CC)
|
Chris@16
|
75 real_concept(unsigned long long c) : m_value(static_cast<real_concept_base_type>(c)){}
|
Chris@16
|
76 real_concept(long long c) : m_value(static_cast<real_concept_base_type>(c)){}
|
Chris@16
|
77 #elif defined(BOOST_HAS_LONG_LONG)
|
Chris@16
|
78 real_concept(boost::ulong_long_type c) : m_value(static_cast<real_concept_base_type>(c)){}
|
Chris@16
|
79 real_concept(boost::long_long_type c) : m_value(static_cast<real_concept_base_type>(c)){}
|
Chris@16
|
80 #elif defined(BOOST_HAS_MS_INT64)
|
Chris@16
|
81 real_concept(unsigned __int64 c) : m_value(static_cast<real_concept_base_type>(c)){}
|
Chris@16
|
82 real_concept(__int64 c) : m_value(static_cast<real_concept_base_type>(c)){}
|
Chris@16
|
83 #endif
|
Chris@16
|
84 real_concept(float c) : m_value(c){}
|
Chris@16
|
85 real_concept(double c) : m_value(c){}
|
Chris@16
|
86 real_concept(long double c) : m_value(c){}
|
Chris@16
|
87 #ifdef BOOST_MATH_USE_FLOAT128
|
Chris@101
|
88 real_concept(BOOST_MATH_FLOAT128_TYPE c) : m_value(c){}
|
Chris@16
|
89 #endif
|
Chris@16
|
90
|
Chris@16
|
91 // Assignment:
|
Chris@16
|
92 real_concept& operator=(char c) { m_value = c; return *this; }
|
Chris@16
|
93 real_concept& operator=(unsigned char c) { m_value = c; return *this; }
|
Chris@16
|
94 real_concept& operator=(signed char c) { m_value = c; return *this; }
|
Chris@16
|
95 #ifndef BOOST_NO_INTRINSIC_WCHAR_T
|
Chris@16
|
96 real_concept& operator=(wchar_t c) { m_value = c; return *this; }
|
Chris@16
|
97 #endif
|
Chris@16
|
98 real_concept& operator=(short c) { m_value = c; return *this; }
|
Chris@16
|
99 real_concept& operator=(unsigned short c) { m_value = c; return *this; }
|
Chris@16
|
100 real_concept& operator=(int c) { m_value = c; return *this; }
|
Chris@16
|
101 real_concept& operator=(unsigned int c) { m_value = c; return *this; }
|
Chris@16
|
102 real_concept& operator=(long c) { m_value = c; return *this; }
|
Chris@16
|
103 real_concept& operator=(unsigned long c) { m_value = c; return *this; }
|
Chris@16
|
104 #ifdef BOOST_HAS_LONG_LONG
|
Chris@16
|
105 real_concept& operator=(boost::long_long_type c) { m_value = static_cast<real_concept_base_type>(c); return *this; }
|
Chris@16
|
106 real_concept& operator=(boost::ulong_long_type c) { m_value = static_cast<real_concept_base_type>(c); return *this; }
|
Chris@16
|
107 #endif
|
Chris@16
|
108 real_concept& operator=(float c) { m_value = c; return *this; }
|
Chris@16
|
109 real_concept& operator=(double c) { m_value = c; return *this; }
|
Chris@16
|
110 real_concept& operator=(long double c) { m_value = c; return *this; }
|
Chris@16
|
111
|
Chris@16
|
112 // Access:
|
Chris@16
|
113 real_concept_base_type value()const{ return m_value; }
|
Chris@16
|
114
|
Chris@16
|
115 // Member arithmetic:
|
Chris@16
|
116 real_concept& operator+=(const real_concept& other)
|
Chris@16
|
117 { m_value += other.value(); return *this; }
|
Chris@16
|
118 real_concept& operator-=(const real_concept& other)
|
Chris@16
|
119 { m_value -= other.value(); return *this; }
|
Chris@16
|
120 real_concept& operator*=(const real_concept& other)
|
Chris@16
|
121 { m_value *= other.value(); return *this; }
|
Chris@16
|
122 real_concept& operator/=(const real_concept& other)
|
Chris@16
|
123 { m_value /= other.value(); return *this; }
|
Chris@16
|
124 real_concept operator-()const
|
Chris@16
|
125 { return -m_value; }
|
Chris@16
|
126 real_concept const& operator+()const
|
Chris@16
|
127 { return *this; }
|
Chris@16
|
128 real_concept& operator++()
|
Chris@16
|
129 { ++m_value; return *this; }
|
Chris@16
|
130 real_concept& operator--()
|
Chris@16
|
131 { --m_value; return *this; }
|
Chris@16
|
132
|
Chris@16
|
133 private:
|
Chris@16
|
134 real_concept_base_type m_value;
|
Chris@16
|
135 };
|
Chris@16
|
136
|
Chris@16
|
137 // Non-member arithmetic:
|
Chris@16
|
138 inline real_concept operator+(const real_concept& a, const real_concept& b)
|
Chris@16
|
139 {
|
Chris@16
|
140 real_concept result(a);
|
Chris@16
|
141 result += b;
|
Chris@16
|
142 return result;
|
Chris@16
|
143 }
|
Chris@16
|
144 inline real_concept operator-(const real_concept& a, const real_concept& b)
|
Chris@16
|
145 {
|
Chris@16
|
146 real_concept result(a);
|
Chris@16
|
147 result -= b;
|
Chris@16
|
148 return result;
|
Chris@16
|
149 }
|
Chris@16
|
150 inline real_concept operator*(const real_concept& a, const real_concept& b)
|
Chris@16
|
151 {
|
Chris@16
|
152 real_concept result(a);
|
Chris@16
|
153 result *= b;
|
Chris@16
|
154 return result;
|
Chris@16
|
155 }
|
Chris@16
|
156 inline real_concept operator/(const real_concept& a, const real_concept& b)
|
Chris@16
|
157 {
|
Chris@16
|
158 real_concept result(a);
|
Chris@16
|
159 result /= b;
|
Chris@16
|
160 return result;
|
Chris@16
|
161 }
|
Chris@16
|
162
|
Chris@16
|
163 // Comparison:
|
Chris@16
|
164 inline bool operator == (const real_concept& a, const real_concept& b)
|
Chris@16
|
165 { return a.value() == b.value(); }
|
Chris@16
|
166 inline bool operator != (const real_concept& a, const real_concept& b)
|
Chris@16
|
167 { return a.value() != b.value();}
|
Chris@16
|
168 inline bool operator < (const real_concept& a, const real_concept& b)
|
Chris@16
|
169 { return a.value() < b.value(); }
|
Chris@16
|
170 inline bool operator <= (const real_concept& a, const real_concept& b)
|
Chris@16
|
171 { return a.value() <= b.value(); }
|
Chris@16
|
172 inline bool operator > (const real_concept& a, const real_concept& b)
|
Chris@16
|
173 { return a.value() > b.value(); }
|
Chris@16
|
174 inline bool operator >= (const real_concept& a, const real_concept& b)
|
Chris@16
|
175 { return a.value() >= b.value(); }
|
Chris@16
|
176
|
Chris@16
|
177 // Non-member functions:
|
Chris@16
|
178 inline real_concept acos(real_concept a)
|
Chris@16
|
179 { return std::acos(a.value()); }
|
Chris@16
|
180 inline real_concept cos(real_concept a)
|
Chris@16
|
181 { return std::cos(a.value()); }
|
Chris@16
|
182 inline real_concept asin(real_concept a)
|
Chris@16
|
183 { return std::asin(a.value()); }
|
Chris@16
|
184 inline real_concept atan(real_concept a)
|
Chris@16
|
185 { return std::atan(a.value()); }
|
Chris@16
|
186 inline real_concept atan2(real_concept a, real_concept b)
|
Chris@16
|
187 { return std::atan2(a.value(), b.value()); }
|
Chris@16
|
188 inline real_concept ceil(real_concept a)
|
Chris@16
|
189 { return std::ceil(a.value()); }
|
Chris@16
|
190 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
|
Chris@16
|
191 // I've seen std::fmod(long double) crash on some platforms
|
Chris@16
|
192 // so use fmodl instead:
|
Chris@16
|
193 #ifdef _WIN32_WCE
|
Chris@16
|
194 //
|
Chris@16
|
195 // Ugly workaround for macro fmodl:
|
Chris@16
|
196 //
|
Chris@16
|
197 inline long double call_fmodl(long double a, long double b)
|
Chris@16
|
198 { return fmodl(a, b); }
|
Chris@16
|
199 inline real_concept fmod(real_concept a, real_concept b)
|
Chris@16
|
200 { return call_fmodl(a.value(), b.value()); }
|
Chris@16
|
201 #else
|
Chris@16
|
202 inline real_concept fmod(real_concept a, real_concept b)
|
Chris@16
|
203 { return fmodl(a.value(), b.value()); }
|
Chris@16
|
204 #endif
|
Chris@16
|
205 #endif
|
Chris@16
|
206 inline real_concept cosh(real_concept a)
|
Chris@16
|
207 { return std::cosh(a.value()); }
|
Chris@16
|
208 inline real_concept exp(real_concept a)
|
Chris@16
|
209 { return std::exp(a.value()); }
|
Chris@16
|
210 inline real_concept fabs(real_concept a)
|
Chris@16
|
211 { return std::fabs(a.value()); }
|
Chris@16
|
212 inline real_concept abs(real_concept a)
|
Chris@16
|
213 { return std::abs(a.value()); }
|
Chris@16
|
214 inline real_concept floor(real_concept a)
|
Chris@16
|
215 { return std::floor(a.value()); }
|
Chris@16
|
216 inline real_concept modf(real_concept a, real_concept* ipart)
|
Chris@16
|
217 {
|
Chris@16
|
218 real_concept_base_type ip;
|
Chris@16
|
219 real_concept_base_type result = std::modf(a.value(), &ip);
|
Chris@16
|
220 *ipart = ip;
|
Chris@16
|
221 return result;
|
Chris@16
|
222 }
|
Chris@16
|
223 inline real_concept frexp(real_concept a, int* expon)
|
Chris@16
|
224 { return std::frexp(a.value(), expon); }
|
Chris@16
|
225 inline real_concept ldexp(real_concept a, int expon)
|
Chris@16
|
226 { return std::ldexp(a.value(), expon); }
|
Chris@16
|
227 inline real_concept log(real_concept a)
|
Chris@16
|
228 { return std::log(a.value()); }
|
Chris@16
|
229 inline real_concept log10(real_concept a)
|
Chris@16
|
230 { return std::log10(a.value()); }
|
Chris@16
|
231 inline real_concept tan(real_concept a)
|
Chris@16
|
232 { return std::tan(a.value()); }
|
Chris@16
|
233 inline real_concept pow(real_concept a, real_concept b)
|
Chris@16
|
234 { return std::pow(a.value(), b.value()); }
|
Chris@16
|
235 #if !defined(__SUNPRO_CC)
|
Chris@16
|
236 inline real_concept pow(real_concept a, int b)
|
Chris@16
|
237 { return std::pow(a.value(), b); }
|
Chris@16
|
238 #else
|
Chris@16
|
239 inline real_concept pow(real_concept a, int b)
|
Chris@16
|
240 { return std::pow(a.value(), static_cast<real_concept_base_type>(b)); }
|
Chris@16
|
241 #endif
|
Chris@16
|
242 inline real_concept sin(real_concept a)
|
Chris@16
|
243 { return std::sin(a.value()); }
|
Chris@16
|
244 inline real_concept sinh(real_concept a)
|
Chris@16
|
245 { return std::sinh(a.value()); }
|
Chris@16
|
246 inline real_concept sqrt(real_concept a)
|
Chris@16
|
247 { return std::sqrt(a.value()); }
|
Chris@16
|
248 inline real_concept tanh(real_concept a)
|
Chris@16
|
249 { return std::tanh(a.value()); }
|
Chris@16
|
250
|
Chris@16
|
251 //
|
Chris@16
|
252 // Conversion and truncation routines:
|
Chris@16
|
253 //
|
Chris@16
|
254 template <class Policy>
|
Chris@16
|
255 inline int iround(const concepts::real_concept& v, const Policy& pol)
|
Chris@16
|
256 { return boost::math::iround(v.value(), pol); }
|
Chris@16
|
257 inline int iround(const concepts::real_concept& v)
|
Chris@16
|
258 { return boost::math::iround(v.value(), policies::policy<>()); }
|
Chris@16
|
259 template <class Policy>
|
Chris@16
|
260 inline long lround(const concepts::real_concept& v, const Policy& pol)
|
Chris@16
|
261 { return boost::math::lround(v.value(), pol); }
|
Chris@16
|
262 inline long lround(const concepts::real_concept& v)
|
Chris@16
|
263 { return boost::math::lround(v.value(), policies::policy<>()); }
|
Chris@16
|
264
|
Chris@16
|
265 #ifdef BOOST_HAS_LONG_LONG
|
Chris@16
|
266 template <class Policy>
|
Chris@16
|
267 inline boost::long_long_type llround(const concepts::real_concept& v, const Policy& pol)
|
Chris@16
|
268 { return boost::math::llround(v.value(), pol); }
|
Chris@16
|
269 inline boost::long_long_type llround(const concepts::real_concept& v)
|
Chris@16
|
270 { return boost::math::llround(v.value(), policies::policy<>()); }
|
Chris@16
|
271 #endif
|
Chris@16
|
272
|
Chris@16
|
273 template <class Policy>
|
Chris@16
|
274 inline int itrunc(const concepts::real_concept& v, const Policy& pol)
|
Chris@16
|
275 { return boost::math::itrunc(v.value(), pol); }
|
Chris@16
|
276 inline int itrunc(const concepts::real_concept& v)
|
Chris@16
|
277 { return boost::math::itrunc(v.value(), policies::policy<>()); }
|
Chris@16
|
278 template <class Policy>
|
Chris@16
|
279 inline long ltrunc(const concepts::real_concept& v, const Policy& pol)
|
Chris@16
|
280 { return boost::math::ltrunc(v.value(), pol); }
|
Chris@16
|
281 inline long ltrunc(const concepts::real_concept& v)
|
Chris@16
|
282 { return boost::math::ltrunc(v.value(), policies::policy<>()); }
|
Chris@16
|
283
|
Chris@16
|
284 #ifdef BOOST_HAS_LONG_LONG
|
Chris@16
|
285 template <class Policy>
|
Chris@16
|
286 inline boost::long_long_type lltrunc(const concepts::real_concept& v, const Policy& pol)
|
Chris@16
|
287 { return boost::math::lltrunc(v.value(), pol); }
|
Chris@16
|
288 inline boost::long_long_type lltrunc(const concepts::real_concept& v)
|
Chris@16
|
289 { return boost::math::lltrunc(v.value(), policies::policy<>()); }
|
Chris@16
|
290 #endif
|
Chris@16
|
291
|
Chris@16
|
292 // Streaming:
|
Chris@16
|
293 template <class charT, class traits>
|
Chris@16
|
294 inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os, const real_concept& a)
|
Chris@16
|
295 {
|
Chris@16
|
296 return os << a.value();
|
Chris@16
|
297 }
|
Chris@16
|
298 template <class charT, class traits>
|
Chris@16
|
299 inline std::basic_istream<charT, traits>& operator>>(std::basic_istream<charT, traits>& is, real_concept& a)
|
Chris@16
|
300 {
|
Chris@16
|
301 #if defined(BOOST_MSVC) && defined(__SGI_STL_PORT)
|
Chris@16
|
302 //
|
Chris@16
|
303 // STLPort 5.1.4 has a problem reading long doubles from strings,
|
Chris@16
|
304 // see http://sourceforge.net/tracker/index.php?func=detail&aid=1811043&group_id=146814&atid=766244
|
Chris@16
|
305 //
|
Chris@16
|
306 double v;
|
Chris@16
|
307 is >> v;
|
Chris@16
|
308 a = v;
|
Chris@16
|
309 return is;
|
Chris@101
|
310 #elif defined(__SGI_STL_PORT) || defined(_RWSTD_VER) || defined(__LIBCOMO__) || defined(_LIBCPP_VERSION)
|
Chris@16
|
311 std::string s;
|
Chris@16
|
312 real_concept_base_type d;
|
Chris@16
|
313 is >> s;
|
Chris@16
|
314 std::sscanf(s.c_str(), "%Lf", &d);
|
Chris@16
|
315 a = d;
|
Chris@16
|
316 return is;
|
Chris@16
|
317 #else
|
Chris@16
|
318 real_concept_base_type v;
|
Chris@16
|
319 is >> v;
|
Chris@16
|
320 a = v;
|
Chris@16
|
321 return is;
|
Chris@16
|
322 #endif
|
Chris@16
|
323 }
|
Chris@16
|
324
|
Chris@16
|
325 } // namespace concepts
|
Chris@16
|
326
|
Chris@16
|
327 namespace tools
|
Chris@16
|
328 {
|
Chris@16
|
329
|
Chris@16
|
330 template <>
|
Chris@101
|
331 inline concepts::real_concept make_big_value<concepts::real_concept>(boost::math::tools::largest_float val, const char* , mpl::false_ const&, mpl::false_ const&)
|
Chris@16
|
332 {
|
Chris@16
|
333 return val; // Can't use lexical_cast here, sometimes it fails....
|
Chris@16
|
334 }
|
Chris@16
|
335
|
Chris@16
|
336 template <>
|
Chris@16
|
337 inline concepts::real_concept max_value<concepts::real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::real_concept))
|
Chris@16
|
338 {
|
Chris@16
|
339 return max_value<concepts::real_concept_base_type>();
|
Chris@16
|
340 }
|
Chris@16
|
341
|
Chris@16
|
342 template <>
|
Chris@16
|
343 inline concepts::real_concept min_value<concepts::real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::real_concept))
|
Chris@16
|
344 {
|
Chris@16
|
345 return min_value<concepts::real_concept_base_type>();
|
Chris@16
|
346 }
|
Chris@16
|
347
|
Chris@16
|
348 template <>
|
Chris@16
|
349 inline concepts::real_concept log_max_value<concepts::real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::real_concept))
|
Chris@16
|
350 {
|
Chris@16
|
351 return log_max_value<concepts::real_concept_base_type>();
|
Chris@16
|
352 }
|
Chris@16
|
353
|
Chris@16
|
354 template <>
|
Chris@16
|
355 inline concepts::real_concept log_min_value<concepts::real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::real_concept))
|
Chris@16
|
356 {
|
Chris@16
|
357 return log_min_value<concepts::real_concept_base_type>();
|
Chris@16
|
358 }
|
Chris@16
|
359
|
Chris@16
|
360 template <>
|
Chris@16
|
361 inline concepts::real_concept epsilon<concepts::real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::real_concept))
|
Chris@16
|
362 {
|
Chris@16
|
363 #ifdef __SUNPRO_CC
|
Chris@16
|
364 return std::numeric_limits<concepts::real_concept_base_type>::epsilon();
|
Chris@16
|
365 #else
|
Chris@16
|
366 return tools::epsilon<concepts::real_concept_base_type>();
|
Chris@16
|
367 #endif
|
Chris@16
|
368 }
|
Chris@16
|
369
|
Chris@16
|
370 template <>
|
Chris@16
|
371 inline int digits<concepts::real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::real_concept))
|
Chris@16
|
372 {
|
Chris@16
|
373 // Assume number of significand bits is same as real_concept_base_type,
|
Chris@16
|
374 // unless std::numeric_limits<T>::is_specialized to provide digits.
|
Chris@16
|
375 return tools::digits<concepts::real_concept_base_type>();
|
Chris@16
|
376 // Note that if numeric_limits real concept is NOT specialized to provide digits10
|
Chris@16
|
377 // (or max_digits10) then the default precision of 6 decimal digits will be used
|
Chris@16
|
378 // by Boost test (giving misleading error messages like
|
Chris@16
|
379 // "difference between {9.79796} and {9.79796} exceeds 5.42101e-19%"
|
Chris@16
|
380 // and by Boost lexical cast and serialization causing loss of accuracy.
|
Chris@16
|
381 }
|
Chris@16
|
382
|
Chris@16
|
383 } // namespace tools
|
Chris@16
|
384
|
Chris@16
|
385 #if defined(__SGI_STL_PORT) || defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS)
|
Chris@16
|
386 //
|
Chris@16
|
387 // We shouldn't really need these type casts any more, but there are some
|
Chris@16
|
388 // STLport iostream bugs we work around by using them....
|
Chris@16
|
389 //
|
Chris@16
|
390 namespace tools
|
Chris@16
|
391 {
|
Chris@16
|
392 // real_cast converts from T to integer and narrower floating-point types.
|
Chris@16
|
393
|
Chris@16
|
394 // Convert from T to integer types.
|
Chris@16
|
395
|
Chris@16
|
396 template <>
|
Chris@16
|
397 inline unsigned int real_cast<unsigned int, concepts::real_concept>(concepts::real_concept r)
|
Chris@16
|
398 {
|
Chris@16
|
399 return static_cast<unsigned int>(r.value());
|
Chris@16
|
400 }
|
Chris@16
|
401
|
Chris@16
|
402 template <>
|
Chris@16
|
403 inline int real_cast<int, concepts::real_concept>(concepts::real_concept r)
|
Chris@16
|
404 {
|
Chris@16
|
405 return static_cast<int>(r.value());
|
Chris@16
|
406 }
|
Chris@16
|
407
|
Chris@16
|
408 template <>
|
Chris@16
|
409 inline long real_cast<long, concepts::real_concept>(concepts::real_concept r)
|
Chris@16
|
410 {
|
Chris@16
|
411 return static_cast<long>(r.value());
|
Chris@16
|
412 }
|
Chris@16
|
413
|
Chris@16
|
414 // Converts from T to narrower floating-point types, float, double & long double.
|
Chris@16
|
415
|
Chris@16
|
416 template <>
|
Chris@16
|
417 inline float real_cast<float, concepts::real_concept>(concepts::real_concept r)
|
Chris@16
|
418 {
|
Chris@16
|
419 return static_cast<float>(r.value());
|
Chris@16
|
420 }
|
Chris@16
|
421 template <>
|
Chris@16
|
422 inline double real_cast<double, concepts::real_concept>(concepts::real_concept r)
|
Chris@16
|
423 {
|
Chris@16
|
424 return static_cast<double>(r.value());
|
Chris@16
|
425 }
|
Chris@16
|
426 template <>
|
Chris@16
|
427 inline long double real_cast<long double, concepts::real_concept>(concepts::real_concept r)
|
Chris@16
|
428 {
|
Chris@16
|
429 return r.value();
|
Chris@16
|
430 }
|
Chris@16
|
431
|
Chris@16
|
432 } // STLPort
|
Chris@16
|
433
|
Chris@16
|
434 #endif
|
Chris@16
|
435
|
Chris@16
|
436 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1310)
|
Chris@16
|
437 //
|
Chris@16
|
438 // For some strange reason ADL sometimes fails to find the
|
Chris@16
|
439 // correct overloads, unless we bring these declarations into scope:
|
Chris@16
|
440 //
|
Chris@16
|
441 using concepts::itrunc;
|
Chris@16
|
442 using concepts::iround;
|
Chris@16
|
443
|
Chris@16
|
444 #endif
|
Chris@16
|
445
|
Chris@16
|
446 } // namespace math
|
Chris@16
|
447 } // namespace boost
|
Chris@16
|
448
|
Chris@16
|
449 #endif // BOOST_MATH_REAL_CONCEPT_HPP
|
Chris@16
|
450
|
Chris@16
|
451
|