diff options
Diffstat (limited to 'boost/random/detail/signed_unsigned_tools.hpp')
-rw-r--r-- | boost/random/detail/signed_unsigned_tools.hpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/boost/random/detail/signed_unsigned_tools.hpp b/boost/random/detail/signed_unsigned_tools.hpp index 988cfb84db..1979908a31 100644 --- a/boost/random/detail/signed_unsigned_tools.hpp +++ b/boost/random/detail/signed_unsigned_tools.hpp @@ -13,7 +13,7 @@ #include <boost/limits.hpp> #include <boost/config.hpp> -#include <boost/type_traits/make_unsigned.hpp> +#include <boost/random/traits.hpp> namespace boost { namespace random { @@ -24,7 +24,7 @@ namespace detail { * Compute x - y, we know that x >= y, return an unsigned value. */ -template<class T, bool sgn = std::numeric_limits<T>::is_signed> +template<class T, bool sgn = std::numeric_limits<T>::is_signed && std::numeric_limits<T>::is_bounded> struct subtract { }; template<class T> @@ -37,7 +37,7 @@ struct subtract<T, /* signed */ false> template<class T> struct subtract<T, /* signed */ true> { - typedef typename make_unsigned<T>::type result_type; + typedef typename boost::random::traits::make_unsigned_or_unbounded<T>::type result_type; result_type operator()(T x, T y) { if (y >= 0) // because x >= y, it follows that x >= 0, too @@ -54,11 +54,11 @@ struct subtract<T, /* signed */ true> * Compute x + y, x is unsigned, result fits in type of "y". */ -template<class T1, class T2, bool sgn = std::numeric_limits<T2>::is_signed> +template<class T1, class T2, bool sgn = (std::numeric_limits<T2>::is_signed && (std::numeric_limits<T1>::digits >= std::numeric_limits<T2>::digits))> struct add { }; template<class T1, class T2> -struct add<T1, T2, /* signed */ false> +struct add<T1, T2, /* signed or else T2 has more digits than T1 so the cast always works - needed when T2 is a multiprecision type and T1 is a native integer */ false> { typedef T2 result_type; result_type operator()(T1 x, T2 y) { return T2(x) + y; } |