2 // Copyright (c) 2011 John Maddock
3 // Use, modification and distribution are subject to the
4 // Boost Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 #ifndef BOOST_MATH_TOOLS_BIG_CONSTANT_HPP
8 #define BOOST_MATH_TOOLS_BIG_CONSTANT_HPP
10 #include <boost/math/tools/config.hpp>
11 #ifndef BOOST_MATH_NO_LEXICAL_CAST
12 #include <boost/lexical_cast.hpp>
14 #include <boost/type_traits/is_convertible.hpp>
16 namespace boost{ namespace math{
21 inline BOOST_CONSTEXPR_OR_CONST T make_big_value(long double v, const char*, mpl::true_ const&, mpl::false_ const&)
23 return static_cast<T>(v);
26 inline BOOST_CONSTEXPR_OR_CONST T make_big_value(long double v, const char*, mpl::true_ const&, mpl::true_ const&)
28 return static_cast<T>(v);
30 #ifndef BOOST_MATH_NO_LEXICAL_CAST
32 inline T make_big_value(long double, const char* s, mpl::false_ const&, mpl::false_ const&)
34 return boost::lexical_cast<T>(s);
38 inline BOOST_CONSTEXPR const char* make_big_value(long double, const char* s, mpl::false_ const&, mpl::true_ const&)
44 // For constants which might fit in a long double (if it's big enough):
46 #define BOOST_MATH_BIG_CONSTANT(T, D, x)\
47 boost::math::tools::make_big_value<T>(\
50 mpl::bool_< (is_convertible<long double, T>::value) && \
51 ((D <= std::numeric_limits<long double>::digits) \
52 || is_floating_point<T>::value \
53 || (std::numeric_limits<T>::is_specialized && \
54 (std::numeric_limits<T>::digits10 <= std::numeric_limits<long double>::digits10))) >(), \
55 boost::is_convertible<const char*, T>())
57 // For constants too huge for any conceivable long double (and which generate compiler errors if we try and declare them as such):
59 #define BOOST_MATH_HUGE_CONSTANT(T, D, x)\
60 boost::math::tools::make_big_value<T>(0.0L, BOOST_STRINGIZE(x), \
61 mpl::bool_<is_floating_point<T>::value || (std::numeric_limits<T>::is_specialized && std::numeric_limits<T>::max_exponent <= std::numeric_limits<long double>::max_exponent && std::numeric_limits<T>::digits <= std::numeric_limits<long double>::digits)>(), \
62 boost::is_convertible<const char*, T>())