]> git.donarmstrong.com Git - rsem.git/blob - boost/math/tools/big_constant.hpp
Updated boost to v1.55.0
[rsem.git] / boost / math / tools / big_constant.hpp
1
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)
6
7 #ifndef BOOST_MATH_TOOLS_BIG_CONSTANT_HPP
8 #define BOOST_MATH_TOOLS_BIG_CONSTANT_HPP
9
10 #include <boost/math/tools/config.hpp>
11 #ifndef BOOST_MATH_NO_LEXICAL_CAST
12 #include <boost/lexical_cast.hpp>
13 #endif
14 #include <boost/type_traits/is_convertible.hpp>
15
16 namespace boost{ namespace math{ 
17
18 namespace tools{
19
20 template <class T>
21 inline BOOST_CONSTEXPR_OR_CONST T make_big_value(long double v, const char*, mpl::true_ const&, mpl::false_ const&)
22 {
23    return static_cast<T>(v);
24 }
25 template <class T>
26 inline BOOST_CONSTEXPR_OR_CONST T make_big_value(long double v, const char*, mpl::true_ const&, mpl::true_ const&)
27 {
28    return static_cast<T>(v);
29 }
30 #ifndef BOOST_MATH_NO_LEXICAL_CAST
31 template <class T>
32 inline T make_big_value(long double, const char* s, mpl::false_ const&, mpl::false_ const&)
33 {
34    return boost::lexical_cast<T>(s);
35 }
36 #endif
37 template <class T>
38 inline BOOST_CONSTEXPR const char* make_big_value(long double, const char* s, mpl::false_ const&, mpl::true_ const&)
39 {
40    return s;
41 }
42
43 //
44 // For constants which might fit in a long double (if it's big enough):
45 //
46 #define BOOST_MATH_BIG_CONSTANT(T, D, x)\
47    boost::math::tools::make_big_value<T>(\
48       BOOST_JOIN(x, L), \
49       BOOST_STRINGIZE(x), \
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>())
56 //
57 // For constants too huge for any conceivable long double (and which generate compiler errors if we try and declare them as such):
58 //
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>())
63
64 }}} // namespaces
65
66 #endif
67