Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-05 08:36:51

0001 //  Copyright John Maddock 2006.
0002 //  Use, modification and distribution are subject to the
0003 //  Boost Software License, Version 1.0. (See accompanying file
0004 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 // std_real_concept is an archetype for built-in Real types.
0007 
0008 // The main purpose in providing this type is to verify
0009 // that std lib functions are found via a using declaration
0010 // bringing those functions into the current scope, and not
0011 // just because they happen to be in global scope.
0012 //
0013 // If ::pow is found rather than std::pow say, then the code
0014 // will silently compile, but truncation of long doubles to
0015 // double will cause a significant loss of precision.
0016 // A template instantiated with std_real_concept will *only*
0017 // compile if it std::whatever is in scope.
0018 
0019 #include <boost/math/policies/policy.hpp>
0020 #include <boost/math/special_functions/math_fwd.hpp>
0021 #include <limits>
0022 #include <ostream>
0023 #include <istream>
0024 #include <cmath>
0025 
0026 #ifndef BOOST_MATH_STD_REAL_CONCEPT_HPP
0027 #define BOOST_MATH_STD_REAL_CONCEPT_HPP
0028 
0029 namespace boost{ namespace math{
0030 
0031 namespace concepts
0032 {
0033 
0034 #ifdef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
0035    typedef double std_real_concept_base_type;
0036 #else
0037    typedef long double std_real_concept_base_type;
0038 #endif
0039 
0040 class std_real_concept
0041 {
0042 public:
0043    // Constructors:
0044    std_real_concept() : m_value(0){}
0045    std_real_concept(char c) : m_value(c){}
0046 #ifndef BOOST_NO_INTRINSIC_WCHAR_T
0047    std_real_concept(wchar_t c) : m_value(c){}
0048 #endif
0049    std_real_concept(unsigned char c) : m_value(c){}
0050    std_real_concept(signed char c) : m_value(c){}
0051    std_real_concept(unsigned short c) : m_value(c){}
0052    std_real_concept(short c) : m_value(c){}
0053    std_real_concept(unsigned int c) : m_value(c){}
0054    std_real_concept(int c) : m_value(c){}
0055    std_real_concept(unsigned long c) : m_value(c){}
0056    std_real_concept(long c) : m_value(c){}
0057 #if defined(__DECCXX) || defined(__SUNPRO_CC)
0058    std_real_concept(unsigned long long c) : m_value(static_cast<std_real_concept_base_type>(c)){}
0059    std_real_concept(long long c) : m_value(static_cast<std_real_concept_base_type>(c)){}
0060 #endif
0061    std_real_concept(unsigned long long c) : m_value(static_cast<std_real_concept_base_type>(c)){}
0062    std_real_concept(long long c) : m_value(static_cast<std_real_concept_base_type>(c)){}
0063    std_real_concept(float c) : m_value(c){}
0064    std_real_concept(double c) : m_value(c){}
0065    std_real_concept(long double c) : m_value(c){}
0066 #ifdef BOOST_MATH_USE_FLOAT128
0067    std_real_concept(BOOST_MATH_FLOAT128_TYPE c) : m_value(c){}
0068 #endif
0069 
0070    // Assignment:
0071    std_real_concept& operator=(char c) { m_value = c; return *this; }
0072    std_real_concept& operator=(unsigned char c) { m_value = c; return *this; }
0073    std_real_concept& operator=(signed char c) { m_value = c; return *this; }
0074 #ifndef BOOST_NO_INTRINSIC_WCHAR_T
0075    std_real_concept& operator=(wchar_t c) { m_value = c; return *this; }
0076 #endif
0077    std_real_concept& operator=(short c) { m_value = c; return *this; }
0078    std_real_concept& operator=(unsigned short c) { m_value = c; return *this; }
0079    std_real_concept& operator=(int c) { m_value = c; return *this; }
0080    std_real_concept& operator=(unsigned int c) { m_value = c; return *this; }
0081    std_real_concept& operator=(long c) { m_value = c; return *this; }
0082    std_real_concept& operator=(unsigned long c) { m_value = c; return *this; }
0083 #if defined(__DECCXX) || defined(__SUNPRO_CC)
0084    std_real_concept& operator=(unsigned long long c) { m_value = static_cast<std_real_concept_base_type>(c); return *this; }
0085    std_real_concept& operator=(long long c) { m_value = static_cast<std_real_concept_base_type>(c); return *this; }
0086 #endif
0087    std_real_concept& operator=(long long c) { m_value = static_cast<std_real_concept_base_type>(c); return *this; }
0088    std_real_concept& operator=(unsigned long long c) { m_value = static_cast<std_real_concept_base_type>(c); return *this; }
0089 
0090    std_real_concept& operator=(float c) { m_value = c; return *this; }
0091    std_real_concept& operator=(double c) { m_value = c; return *this; }
0092    std_real_concept& operator=(long double c) { m_value = c; return *this; }
0093 #ifdef BOOST_MATH_USE_FLOAT128
0094    std_real_concept& operator=(BOOST_MATH_FLOAT128_TYPE c) { m_value = c; return *this; }
0095 #endif
0096 
0097    // Access:
0098    std_real_concept_base_type value()const{ return m_value; }
0099 
0100    // Member arithmetic:
0101    std_real_concept& operator+=(const std_real_concept& other)
0102    { m_value += other.value(); return *this; }
0103    std_real_concept& operator-=(const std_real_concept& other)
0104    { m_value -= other.value(); return *this; }
0105    std_real_concept& operator*=(const std_real_concept& other)
0106    { m_value *= other.value(); return *this; }
0107    std_real_concept& operator/=(const std_real_concept& other)
0108    { m_value /= other.value(); return *this; }
0109    std_real_concept operator-()const
0110    { return -m_value; }
0111    std_real_concept const& operator+()const
0112    { return *this; }
0113 
0114 private:
0115    std_real_concept_base_type m_value;
0116 };
0117 
0118 // Non-member arithmetic:
0119 inline std_real_concept operator+(const std_real_concept& a, const std_real_concept& b)
0120 {
0121    std_real_concept result(a);
0122    result += b;
0123    return result;
0124 }
0125 inline std_real_concept operator-(const std_real_concept& a, const std_real_concept& b)
0126 {
0127    std_real_concept result(a);
0128    result -= b;
0129    return result;
0130 }
0131 inline std_real_concept operator*(const std_real_concept& a, const std_real_concept& b)
0132 {
0133    std_real_concept result(a);
0134    result *= b;
0135    return result;
0136 }
0137 inline std_real_concept operator/(const std_real_concept& a, const std_real_concept& b)
0138 {
0139    std_real_concept result(a);
0140    result /= b;
0141    return result;
0142 }
0143 
0144 // Comparison:
0145 inline bool operator == (const std_real_concept& a, const std_real_concept& b)
0146 { return a.value() == b.value(); }
0147 inline bool operator != (const std_real_concept& a, const std_real_concept& b)
0148 { return a.value() != b.value();}
0149 inline bool operator < (const std_real_concept& a, const std_real_concept& b)
0150 { return a.value() < b.value(); }
0151 inline bool operator <= (const std_real_concept& a, const std_real_concept& b)
0152 { return a.value() <= b.value(); }
0153 inline bool operator > (const std_real_concept& a, const std_real_concept& b)
0154 { return a.value() > b.value(); }
0155 inline bool operator >= (const std_real_concept& a, const std_real_concept& b)
0156 { return a.value() >= b.value(); }
0157 
0158 } // namespace concepts
0159 } // namespace math
0160 } // namespace boost
0161 
0162 namespace std{
0163 
0164 // Non-member functions:
0165 inline boost::math::concepts::std_real_concept acos(boost::math::concepts::std_real_concept a)
0166 { return std::acos(a.value()); }
0167 inline boost::math::concepts::std_real_concept cos(boost::math::concepts::std_real_concept a)
0168 { return std::cos(a.value()); }
0169 inline boost::math::concepts::std_real_concept asin(boost::math::concepts::std_real_concept a)
0170 { return std::asin(a.value()); }
0171 inline boost::math::concepts::std_real_concept atan(boost::math::concepts::std_real_concept a)
0172 { return std::atan(a.value()); }
0173 inline boost::math::concepts::std_real_concept atan2(boost::math::concepts::std_real_concept a, boost::math::concepts::std_real_concept b)
0174 { return std::atan2(a.value(), b.value()); }
0175 inline boost::math::concepts::std_real_concept ceil(boost::math::concepts::std_real_concept a)
0176 { return std::ceil(a.value()); }
0177 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
0178 inline boost::math::concepts::std_real_concept fmod(boost::math::concepts::std_real_concept a, boost::math::concepts::std_real_concept b)
0179 { return fmodl(a.value(), b.value()); }
0180 #else
0181 inline boost::math::concepts::std_real_concept fmod(boost::math::concepts::std_real_concept a, boost::math::concepts::std_real_concept b)
0182 { return std::fmod(a.value(), b.value()); }
0183 #endif
0184 inline boost::math::concepts::std_real_concept cosh(boost::math::concepts::std_real_concept a)
0185 { return std::cosh(a.value()); }
0186 inline boost::math::concepts::std_real_concept exp(boost::math::concepts::std_real_concept a)
0187 { return std::exp(a.value()); }
0188 inline boost::math::concepts::std_real_concept fabs(boost::math::concepts::std_real_concept a)
0189 { return std::fabs(a.value()); }
0190 inline boost::math::concepts::std_real_concept abs(boost::math::concepts::std_real_concept a)
0191 { return std::abs(a.value()); }
0192 inline boost::math::concepts::std_real_concept floor(boost::math::concepts::std_real_concept a)
0193 { return std::floor(a.value()); }
0194 inline boost::math::concepts::std_real_concept modf(boost::math::concepts::std_real_concept a, boost::math::concepts::std_real_concept* ipart)
0195 {
0196    boost::math::concepts::std_real_concept_base_type ip;
0197    boost::math::concepts::std_real_concept_base_type result = std::modf(a.value(), &ip);
0198    *ipart = ip;
0199    return result;
0200 }
0201 inline boost::math::concepts::std_real_concept frexp(boost::math::concepts::std_real_concept a, int* expon)
0202 { return std::frexp(a.value(), expon); }
0203 inline boost::math::concepts::std_real_concept ldexp(boost::math::concepts::std_real_concept a, int expon)
0204 { return std::ldexp(a.value(), expon); }
0205 inline boost::math::concepts::std_real_concept log(boost::math::concepts::std_real_concept a)
0206 { return std::log(a.value()); }
0207 inline boost::math::concepts::std_real_concept log10(boost::math::concepts::std_real_concept a)
0208 { return std::log10(a.value()); }
0209 inline boost::math::concepts::std_real_concept tan(boost::math::concepts::std_real_concept a)
0210 { return std::tan(a.value()); }
0211 inline boost::math::concepts::std_real_concept pow(boost::math::concepts::std_real_concept a, boost::math::concepts::std_real_concept b)
0212 { return std::pow(a.value(), b.value()); }
0213 #if !defined(__SUNPRO_CC)
0214 inline boost::math::concepts::std_real_concept pow(boost::math::concepts::std_real_concept a, int b)
0215 { return std::pow(a.value(), b); }
0216 #else
0217 inline boost::math::concepts::std_real_concept pow(boost::math::concepts::std_real_concept a, int b)
0218 { return std::pow(a.value(), static_cast<long double>(b)); }
0219 #endif
0220 inline boost::math::concepts::std_real_concept sin(boost::math::concepts::std_real_concept a)
0221 { return std::sin(a.value()); }
0222 inline boost::math::concepts::std_real_concept sinh(boost::math::concepts::std_real_concept a)
0223 { return std::sinh(a.value()); }
0224 inline boost::math::concepts::std_real_concept sqrt(boost::math::concepts::std_real_concept a)
0225 { return std::sqrt(a.value()); }
0226 inline boost::math::concepts::std_real_concept tanh(boost::math::concepts::std_real_concept a)
0227 { return std::tanh(a.value()); }
0228 inline boost::math::concepts::std_real_concept (nextafter)(boost::math::concepts::std_real_concept a, boost::math::concepts::std_real_concept b)
0229 { return (boost::math::nextafter)(a, b); }
0230 //
0231 // C++11 ism's
0232 // Note that these must not actually call the std:: versions as that precludes using this
0233 // header to test in C++03 mode, call the Boost versions instead:
0234 //
0235 inline boost::math::concepts::std_real_concept asinh(boost::math::concepts::std_real_concept a)
0236 { return boost::math::asinh(a.value(), boost::math::policies::make_policy(boost::math::policies::overflow_error<boost::math::policies::ignore_error>())); }
0237 inline boost::math::concepts::std_real_concept acosh(boost::math::concepts::std_real_concept a)
0238 { return boost::math::acosh(a.value(), boost::math::policies::make_policy(boost::math::policies::overflow_error<boost::math::policies::ignore_error>())); }
0239 inline boost::math::concepts::std_real_concept atanh(boost::math::concepts::std_real_concept a)
0240 { return boost::math::atanh(a.value(), boost::math::policies::make_policy(boost::math::policies::overflow_error<boost::math::policies::ignore_error>())); }
0241 inline bool (isfinite)(boost::math::concepts::std_real_concept a)
0242 {
0243    return (boost::math::isfinite)(a.value());
0244 }
0245 
0246 
0247 } // namespace std
0248 
0249 #include <boost/math/special_functions/round.hpp>
0250 #include <boost/math/special_functions/trunc.hpp>
0251 #include <boost/math/special_functions/modf.hpp>
0252 #include <boost/math/tools/precision.hpp>
0253 
0254 namespace boost{ namespace math{ namespace concepts{
0255 
0256 //
0257 // Conversion and truncation routines:
0258 //
0259 template <class Policy>
0260 inline int iround(const concepts::std_real_concept& v, const Policy& pol)
0261 {
0262    return boost::math::iround(v.value(), pol);
0263 }
0264 inline int iround(const concepts::std_real_concept& v)
0265 {
0266    return boost::math::iround(v.value(), policies::policy<>());
0267 }
0268 
0269 template <class Policy>
0270 inline long lround(const concepts::std_real_concept& v, const Policy& pol)
0271 {
0272    return boost::math::lround(v.value(), pol);
0273 }
0274 inline long lround(const concepts::std_real_concept& v)
0275 {
0276    return boost::math::lround(v.value(), policies::policy<>());
0277 }
0278 
0279 template <class Policy>
0280 inline long long llround(const concepts::std_real_concept& v, const Policy& pol)
0281 {
0282    return boost::math::llround(v.value(), pol);
0283 }
0284 inline long long llround(const concepts::std_real_concept& v)
0285 {
0286    return boost::math::llround(v.value(), policies::policy<>());
0287 }
0288 
0289 template <class Policy>
0290 inline int itrunc(const concepts::std_real_concept& v, const Policy& pol)
0291 {
0292    return boost::math::itrunc(v.value(), pol);
0293 }
0294 inline int itrunc(const concepts::std_real_concept& v)
0295 {
0296    return boost::math::itrunc(v.value(), policies::policy<>());
0297 }
0298 
0299 template <class Policy>
0300 inline long ltrunc(const concepts::std_real_concept& v, const Policy& pol)
0301 {
0302    return boost::math::ltrunc(v.value(), pol);
0303 }
0304 inline long ltrunc(const concepts::std_real_concept& v)
0305 {
0306    return boost::math::ltrunc(v.value(), policies::policy<>());
0307 }
0308 
0309 template <class Policy>
0310 inline long long lltrunc(const concepts::std_real_concept& v, const Policy& pol)
0311 {
0312    return boost::math::lltrunc(v.value(), pol);
0313 }
0314 inline long long lltrunc(const concepts::std_real_concept& v)
0315 {
0316    return boost::math::lltrunc(v.value(), policies::policy<>());
0317 }
0318 
0319 // Streaming:
0320 template <class charT, class traits>
0321 inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os, const std_real_concept& a)
0322 {
0323    return os << a.value();
0324 }
0325 template <class charT, class traits>
0326 inline std::basic_istream<charT, traits>& operator>>(std::basic_istream<charT, traits>& is, std_real_concept& a)
0327 {
0328 #if defined(__SGI_STL_PORT) || defined(_RWSTD_VER) || defined(__LIBCOMO__) || defined(_LIBCPP_VERSION)
0329    std::string s;
0330    std_real_concept_base_type d;
0331    is >> s;
0332    std::sscanf(s.c_str(), "%Lf", &d);
0333    a = d;
0334    return is;
0335 #else
0336    std_real_concept_base_type v;
0337    is >> v;
0338    a = v;
0339    return is;
0340 #endif
0341 }
0342 
0343 } // namespace concepts
0344 }}
0345 
0346 #include <boost/math/tools/big_constant.hpp>
0347 
0348 namespace boost{ namespace math{
0349 namespace tools
0350 {
0351 
0352 template <>
0353 inline concepts::std_real_concept make_big_value<concepts::std_real_concept>(boost::math::tools::largest_float val, const char*, std::false_type const&, std::false_type const&)
0354 {
0355    return val;  // Can't use lexical_cast here, sometimes it fails....
0356 }
0357 
0358 template <>
0359 inline concepts::std_real_concept max_value<concepts::std_real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept))
0360 {
0361    return max_value<concepts::std_real_concept_base_type>();
0362 }
0363 
0364 template <>
0365 inline concepts::std_real_concept min_value<concepts::std_real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept))
0366 {
0367    return min_value<concepts::std_real_concept_base_type>();
0368 }
0369 
0370 template <>
0371 inline concepts::std_real_concept log_max_value<concepts::std_real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept))
0372 {
0373    return log_max_value<concepts::std_real_concept_base_type>();
0374 }
0375 
0376 template <>
0377 inline concepts::std_real_concept log_min_value<concepts::std_real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept))
0378 {
0379    return log_min_value<concepts::std_real_concept_base_type>();
0380 }
0381 
0382 template <>
0383 inline concepts::std_real_concept epsilon(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept))
0384 {
0385    return tools::epsilon<concepts::std_real_concept_base_type>();
0386 }
0387 
0388 template <>
0389 inline constexpr int digits<concepts::std_real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept)) noexcept
0390 { // Assume number of significand bits is same as std_real_concept_base_type,
0391   // unless std::numeric_limits<T>::is_specialized to provide digits.
0392    return digits<concepts::std_real_concept_base_type>();
0393 }
0394 
0395 template <>
0396 inline double real_cast<double, concepts::std_real_concept>(concepts::std_real_concept r)
0397 {
0398    return static_cast<double>(r.value());
0399 }
0400 
0401 
0402 } // namespace tools
0403 
0404 #if defined(_MSC_VER) && (_MSC_VER <= 1310)
0405 using concepts::itrunc;
0406 using concepts::ltrunc;
0407 using concepts::lltrunc;
0408 using concepts::iround;
0409 using concepts::lround;
0410 using concepts::llround;
0411 #endif
0412 
0413 } // namespace math
0414 } // namespace boost
0415 
0416 //
0417 // These must go at the end, as they include stuff that won't compile until
0418 // after std_real_concept has been defined:
0419 //
0420 #include <boost/math/special_functions/acosh.hpp>
0421 #include <boost/math/special_functions/asinh.hpp>
0422 #include <boost/math/special_functions/atanh.hpp>
0423 
0424 #endif // BOOST_MATH_STD_REAL_CONCEPT_HPP