annotate DEPENDENCIES/generic/include/boost/math/concepts/std_real_concept.hpp @ 133:4acb5d8d80b6 tip

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