brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.1 KiB · 8e731c0 Raw
111 lines · plain
1 2//  Copyright (c) 2011 John Maddock3//  Use, modification and distribution are subject to the4//  Boost Software License, Version 1.0. (See accompanying file5//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)6 7#ifndef BOOST_MATH_TOOLS_BIG_CONSTANT_HPP8#define BOOST_MATH_TOOLS_BIG_CONSTANT_HPP9 10#include <boost/math/tools/config.hpp>11 12// On NVRTC we don't need any of this13// We just have a simple definition of the macro since the largest float14// type on the platform is a 64-bit double15#ifndef BOOST_MATH_HAS_NVRTC 16 17#ifndef BOOST_MATH_STANDALONE18#include <boost/lexical_cast.hpp>19#endif20 21#include <cstdlib>22#include <type_traits>23#include <limits>24 25namespace boost{ namespace math{ 26 27namespace tools{28 29template <class T>30struct numeric_traits : public std::numeric_limits< T > {};31 32#ifdef BOOST_MATH_USE_FLOAT12833typedef __float128 largest_float;34#define BOOST_MATH_LARGEST_FLOAT_C(x) x##Q35template <>36struct numeric_traits<__float128>37{38   static const int digits = 113;39   static const int digits10 = 33;40   static const int max_exponent = 16384;41   static const bool is_specialized = true;42};43#elif LDBL_DIG > DBL_DIG44typedef long double largest_float;45#define BOOST_MATH_LARGEST_FLOAT_C(x) x##L46#else47typedef double largest_float;48#define BOOST_MATH_LARGEST_FLOAT_C(x) x49#endif50 51template <class T>52BOOST_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)53{54   return static_cast<T>(v);55}56template <class T>57BOOST_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)58{59   return static_cast<T>(v);60}61#ifndef BOOST_MATH_NO_LEXICAL_CAST62template <class T>63inline T make_big_value(largest_float, const char* s, std::false_type const&, std::false_type const&)64{65   return boost::lexical_cast<T>(s);66}67#else68template <typename T>69inline T make_big_value(largest_float, const char*, std::false_type const&, std::false_type const&)70{71   static_assert(sizeof(T) == 0, "Type is unsupported in standalone mode. Please disable and try again.");72}73#endif74template <class T>75inline constexpr T make_big_value(largest_float, const char* s, std::false_type const&, std::true_type const&) BOOST_MATH_NOEXCEPT(T)76{77   return T(s);78}79 80//81// For constants which might fit in a long double (if it's big enough):82//83// Note that gcc-13 has std::is_convertible<long double, std::float64_t>::value false, likewise84// std::is_constructible<std::float64_t, long double>::value, even though the conversions do85// actually work.  Workaround is the || std::is_floating_point<T>::value part which thankfully is true.86//87#define BOOST_MATH_BIG_CONSTANT(T, D, x)\88   boost::math::tools::make_big_value<T>(\89      BOOST_MATH_LARGEST_FLOAT_C(x), \90      BOOST_MATH_STRINGIZE(x), \91      std::integral_constant<bool, (std::is_convertible<boost::math::tools::largest_float, T>::value || std::is_floating_point<T>::value) && \92      ((D <= boost::math::tools::numeric_traits<boost::math::tools::largest_float>::digits) \93          || std::is_floating_point<T>::value \94          || (boost::math::tools::numeric_traits<T>::is_specialized && \95          (boost::math::tools::numeric_traits<T>::digits10 <= boost::math::tools::numeric_traits<boost::math::tools::largest_float>::digits10))) >(), \96      std::is_constructible<T, const char*>())97//98// For constants too huge for any conceivable long double (and which generate compiler errors if we try and declare them as such):99//100#define BOOST_MATH_HUGE_CONSTANT(T, D, x)\101   boost::math::tools::make_big_value<T>(0.0L, BOOST_MATH_STRINGIZE(x), \102   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)>(), \103   std::is_constructible<T, const char*>())104 105}}} // namespaces106 107#endif // BOOST_MATH_HAS_NVRTC108 109#endif110 111