]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/libs/multiprecision/performance/arithmetic_backend.hpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / libs / multiprecision / performance / arithmetic_backend.hpp
index 0538f8b5e1751f9b047c6dcfb88eb6f8cfd6fd06..59e5bceef6a2e3d4f57f29aa3947855c41bf968f 100644 (file)
@@ -14,6 +14,7 @@
 #include <boost/math/concepts/real_concept.hpp>
 #include <boost/multiprecision/number.hpp>
 #include <boost/math/common_factor_rt.hpp>
+#include <boost/type_traits/common_type.hpp>
 
 namespace boost{
 namespace multiprecision{
@@ -116,7 +117,24 @@ private:
 };
 
 template <class R, class Arithmetic>
-inline void eval_convert_to(R* result, const arithmetic_backend<Arithmetic>& backend)
+inline typename enable_if_c<boost::is_integral<R>::value>::type eval_convert_to(R* result, const arithmetic_backend<Arithmetic>& backend)
+{
+   typedef typename boost::common_type<R, Arithmetic>::type c_type;
+   static const c_type max = static_cast<c_type>((std::numeric_limits<R>::max)());
+   static const c_type min = static_cast<c_type>((std::numeric_limits<R>::min)());
+   c_type ct = static_cast<c_type>(backend.data());
+   if ((backend.data() < 0) && !std::numeric_limits<R>::is_signed)
+      BOOST_THROW_EXCEPTION(std::range_error("Attempt to convert negative number to unsigned type."));
+   if (ct > max)
+      *result = (std::numeric_limits<R>::max)();
+   else if (std::numeric_limits<Arithmetic>::is_signed && (ct < min))
+      *result = (std::numeric_limits<R>::min)();
+   else
+      *result = backend.data();
+}
+
+template <class R, class Arithmetic>
+inline typename disable_if_c<boost::is_integral<R>::value>::type eval_convert_to(R* result, const arithmetic_backend<Arithmetic>& backend)
 {
    *result = backend.data();
 }