Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 08:49:48

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 
0012 // On NVRTC we don't need any of this
0013 // We just have a simple definition of the macro since the largest float
0014 // type on the platform is a 64-bit double
0015 #ifndef BOOST_MATH_HAS_NVRTC 
0016 
0017 #ifndef BOOST_MATH_STANDALONE
0018 #include <boost/lexical_cast.hpp>
0019 #endif
0020 
0021 #include <cstdlib>
0022 #include <type_traits>
0023 #include <limits>
0024 
0025 namespace boost{ namespace math{ 
0026 
0027 namespace tools{
0028 
0029 template <class T>
0030 struct numeric_traits : public std::numeric_limits< T > {};
0031 
0032 #ifdef BOOST_MATH_USE_FLOAT128
0033 typedef __float128 largest_float;
0034 #define BOOST_MATH_LARGEST_FLOAT_C(x) x##Q
0035 template <>
0036 struct numeric_traits<__float128>
0037 {
0038    static const int digits = 113;
0039    static const int digits10 = 33;
0040    static const int max_exponent = 16384;
0041    static const bool is_specialized = true;
0042 };
0043 #elif LDBL_DIG > DBL_DIG
0044 typedef long double largest_float;
0045 #define BOOST_MATH_LARGEST_FLOAT_C(x) x##L
0046 #else
0047 typedef double largest_float;
0048 #define BOOST_MATH_LARGEST_FLOAT_C(x) x
0049 #endif
0050 
0051 template <class T>
0052 BOOST_MATH_GPU_ENABLED constexpr T make_big_value(largest_float v, const char*, std::true_type const&, std::false_type const&) BOOST_MATH_NOEXCEPT(T)
0053 {
0054    return static_cast<T>(v);
0055 }
0056 template <class T>
0057 BOOST_MATH_GPU_ENABLED constexpr T make_big_value(largest_float v, const char*, std::true_type const&, std::true_type const&) BOOST_MATH_NOEXCEPT(T)
0058 {
0059    return static_cast<T>(v);
0060 }
0061 #ifndef BOOST_MATH_NO_LEXICAL_CAST
0062 template <class T>
0063 inline T make_big_value(largest_float, const char* s, std::false_type const&, std::false_type const&)
0064 {
0065    return boost::lexical_cast<T>(s);
0066 }
0067 #else
0068 template <typename T>
0069 inline T make_big_value(largest_float, const char*, std::false_type const&, std::false_type const&)
0070 {
0071    static_assert(sizeof(T) == 0, "Type is unsupported in standalone mode. Please disable and try again.");
0072 }
0073 #endif
0074 template <class T>
0075 inline constexpr T make_big_value(largest_float, const char* s, std::false_type const&, std::true_type const&) BOOST_MATH_NOEXCEPT(T)
0076 {
0077    return T(s);
0078 }
0079 
0080 //
0081 // For constants which might fit in a long double (if it's big enough):
0082 //
0083 #define BOOST_MATH_BIG_CONSTANT(T, D, x)\
0084    boost::math::tools::make_big_value<T>(\
0085       BOOST_MATH_LARGEST_FLOAT_C(x), \
0086       BOOST_MATH_STRINGIZE(x), \
0087       std::integral_constant<bool, (std::is_convertible<boost::math::tools::largest_float, T>::value) && \
0088       ((D <= boost::math::tools::numeric_traits<boost::math::tools::largest_float>::digits) \
0089           || std::is_floating_point<T>::value \
0090           || (boost::math::tools::numeric_traits<T>::is_specialized && \
0091           (boost::math::tools::numeric_traits<T>::digits10 <= boost::math::tools::numeric_traits<boost::math::tools::largest_float>::digits10))) >(), \
0092       std::is_constructible<T, const char*>())
0093 //
0094 // For constants too huge for any conceivable long double (and which generate compiler errors if we try and declare them as such):
0095 //
0096 #define BOOST_MATH_HUGE_CONSTANT(T, D, x)\
0097    boost::math::tools::make_big_value<T>(0.0L, BOOST_MATH_STRINGIZE(x), \
0098    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)>(), \
0099    std::is_constructible<T, const char*>())
0100 
0101 }}} // namespaces
0102 
0103 #endif // BOOST_MATH_HAS_NVRTC
0104 
0105 #endif
0106