Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:40:39

0001 
0002 //  Copyright (c) 2011 John Maddock
0003 //  Use, modification and distribution are subject to the
0004 //  Boost Software License, Version 1.0. (See accompanying file
0005 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 
0007 #ifndef BOOST_MATH_TOOLS_BIG_CONSTANT_HPP
0008 #define BOOST_MATH_TOOLS_BIG_CONSTANT_HPP
0009 
0010 #include <boost/math/tools/config.hpp>
0011 #ifndef BOOST_MATH_STANDALONE
0012 #include <boost/lexical_cast.hpp>
0013 #endif
0014 
0015 #include <cstdlib>
0016 #include <type_traits>
0017 #include <limits>
0018 
0019 namespace boost{ namespace math{ 
0020 
0021 namespace tools{
0022 
0023 template <class T>
0024 struct numeric_traits : public std::numeric_limits< T > {};
0025 
0026 #ifdef BOOST_MATH_USE_FLOAT128
0027 typedef __float128 largest_float;
0028 #define BOOST_MATH_LARGEST_FLOAT_C(x) x##Q
0029 template <>
0030 struct numeric_traits<__float128>
0031 {
0032    static const int digits = 113;
0033    static const int digits10 = 33;
0034    static const int max_exponent = 16384;
0035    static const bool is_specialized = true;
0036 };
0037 #elif LDBL_DIG > DBL_DIG
0038 typedef long double largest_float;
0039 #define BOOST_MATH_LARGEST_FLOAT_C(x) x##L
0040 #else
0041 typedef double largest_float;
0042 #define BOOST_MATH_LARGEST_FLOAT_C(x) x
0043 #endif
0044 
0045 template <class T>
0046 inline constexpr T make_big_value(largest_float v, const char*, std::true_type const&, std::false_type const&) BOOST_MATH_NOEXCEPT(T)
0047 {
0048    return static_cast<T>(v);
0049 }
0050 template <class T>
0051 inline constexpr T make_big_value(largest_float v, const char*, std::true_type const&, std::true_type const&) BOOST_MATH_NOEXCEPT(T)
0052 {
0053    return static_cast<T>(v);
0054 }
0055 #ifndef BOOST_MATH_NO_LEXICAL_CAST
0056 template <class T>
0057 inline T make_big_value(largest_float, const char* s, std::false_type const&, std::false_type const&)
0058 {
0059    return boost::lexical_cast<T>(s);
0060 }
0061 #else
0062 template <typename T>
0063 inline T make_big_value(largest_float, const char*, std::false_type const&, std::false_type const&)
0064 {
0065    static_assert(sizeof(T) == 0, "Type is unsupported in standalone mode. Please disable and try again.");
0066 }
0067 #endif
0068 template <class T>
0069 inline constexpr T make_big_value(largest_float, const char* s, std::false_type const&, std::true_type const&) BOOST_MATH_NOEXCEPT(T)
0070 {
0071    return T(s);
0072 }
0073 
0074 //
0075 // For constants which might fit in a long double (if it's big enough):
0076 //
0077 #define BOOST_MATH_BIG_CONSTANT(T, D, x)\
0078    boost::math::tools::make_big_value<T>(\
0079       BOOST_MATH_LARGEST_FLOAT_C(x), \
0080       BOOST_STRINGIZE(x), \
0081       std::integral_constant<bool, (std::is_convertible<boost::math::tools::largest_float, T>::value) && \
0082       ((D <= boost::math::tools::numeric_traits<boost::math::tools::largest_float>::digits) \
0083           || std::is_floating_point<T>::value \
0084           || (boost::math::tools::numeric_traits<T>::is_specialized && \
0085           (boost::math::tools::numeric_traits<T>::digits10 <= boost::math::tools::numeric_traits<boost::math::tools::largest_float>::digits10))) >(), \
0086       std::is_constructible<T, const char*>())
0087 //
0088 // For constants too huge for any conceivable long double (and which generate compiler errors if we try and declare them as such):
0089 //
0090 #define BOOST_MATH_HUGE_CONSTANT(T, D, x)\
0091    boost::math::tools::make_big_value<T>(0.0L, BOOST_STRINGIZE(x), \
0092    std::integral_constant<bool, std::is_floating_point<T>::value || (boost::math::tools::numeric_traits<T>::is_specialized && boost::math::tools::numeric_traits<T>::max_exponent <= boost::math::tools::numeric_traits<boost::math::tools::largest_float>::max_exponent && boost::math::tools::numeric_traits<T>::digits <= boost::math::tools::numeric_traits<boost::math::tools::largest_float>::digits)>(), \
0093    std::is_constructible<T, const char*>())
0094 
0095 }}} // namespaces
0096 
0097 #endif
0098