diff options
Diffstat (limited to 'boost/math/special_functions/trunc.hpp')
-rw-r--r-- | boost/math/special_functions/trunc.hpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/boost/math/special_functions/trunc.hpp b/boost/math/special_functions/trunc.hpp index 8a7b042449..2671a0dc88 100644 --- a/boost/math/special_functions/trunc.hpp +++ b/boost/math/special_functions/trunc.hpp @@ -14,6 +14,8 @@ #include <boost/math/tools/config.hpp> #include <boost/math/policies/error_handling.hpp> #include <boost/math/special_functions/fpclassify.hpp> +#include <boost/type_traits/is_constructible.hpp> +#include <boost/core/enable_if.hpp> namespace boost{ namespace math{ namespace detail{ @@ -106,6 +108,55 @@ inline boost::long_long_type lltrunc(const T& v) #endif +template <class T, class Policy> +inline typename boost::enable_if_c<boost::is_constructible<int, T>::value, int>::type + iconvert(const T& v, const Policy&) +{ + return static_cast<int>(v); +} + +template <class T, class Policy> +inline typename boost::disable_if_c<boost::is_constructible<int, T>::value, int>::type + iconvert(const T& v, const Policy& pol) +{ + using boost::math::itrunc; + return itrunc(v, pol); +} + +template <class T, class Policy> +inline typename boost::enable_if_c<boost::is_constructible<long, T>::value, long>::type + lconvert(const T& v, const Policy&) +{ + return static_cast<long>(v); +} + +template <class T, class Policy> +inline typename boost::disable_if_c<boost::is_constructible<long, T>::value, long>::type + lconvert(const T& v, const Policy& pol) +{ + using boost::math::ltrunc; + return ltrunc(v, pol); +} + +#ifdef BOOST_HAS_LONG_LONG + +template <class T, class Policy> +inline typename boost::enable_if_c<boost::is_constructible<boost::long_long_type, T>::value, boost::long_long_type>::type + llconvertert(const T& v, const Policy&) +{ + return static_cast<boost::long_long_type>(v); +} + +template <class T, class Policy> +inline typename boost::disable_if_c<boost::is_constructible<boost::long_long_type, T>::value, boost::long_long_type>::type + llconvertert(const T& v, const Policy& pol) +{ + using boost::math::lltrunc; + return lltrunc(v, pol); +} + +#endif + }} // namespaces #endif // BOOST_MATH_TRUNC_HPP |