Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / multiprecision / cpp_int / checked.hpp
index b3d499a..b1299f2 100644 (file)
@@ -6,7 +6,7 @@
 #ifndef BOOST_MP_CPP_INT_CHECKED_HPP
 #define BOOST_MP_CPP_INT_CHECKED_HPP
 
-namespace boost{ namespace multiprecision{ namespace backends{ namespace detail{
+namespace boost { namespace multiprecision { namespace backends { namespace detail {
 
 //
 // Simple routines for performing checked arithmetic with a builtin arithmetic type.
@@ -35,115 +35,114 @@ inline void raise_div_overflow()
 }
 
 template <class A>
-inline A checked_add_imp(A a, A b, const mpl::true_&)
+inline BOOST_MP_CXX14_CONSTEXPR A checked_add_imp(A a, A b, const mpl::true_&)
 {
-   if(a > 0)
+   if (a > 0)
    {
-      if((b > 0) && ((integer_traits<A>::const_max - b) < a))
+      if ((b > 0) && ((integer_traits<A>::const_max - b) < a))
          raise_add_overflow();
    }
    else
    {
-      if((b < 0) && ((integer_traits<A>::const_min - b) > a))
+      if ((b < 0) && ((integer_traits<A>::const_min - b) > a))
          raise_add_overflow();
    }
    return a + b;
 }
 template <class A>
-inline A checked_add_imp(A a, A b, const mpl::false_&)
+inline BOOST_MP_CXX14_CONSTEXPR A checked_add_imp(A a, A b, const mpl::false_&)
 {
-   if((integer_traits<A>::const_max - b) < a)
+   if ((integer_traits<A>::const_max - b) < a)
       raise_add_overflow();
    return a + b;
 }
 template <class A>
-inline A checked_add(A a, A b, const mpl::int_<checked>&)
+inline BOOST_MP_CXX14_CONSTEXPR A checked_add(A a, A b, const mpl::int_<checked>&)
 {
-   return checked_add_imp(a, b, boost::is_signed<A>());
+   return checked_add_imp(a, b, mpl::bool_<boost::is_signed<A>::value>());
 }
 template <class A>
-inline A checked_add(A a, A b, const mpl::int_<unchecked>&)
+inline BOOST_MP_CXX14_CONSTEXPR A checked_add(A a, A b, const mpl::int_<unchecked>&)
 {
    return a + b;
 }
 
 template <class A>
-inline A checked_subtract_imp(A a, A b, const mpl::true_&)
+inline BOOST_MP_CXX14_CONSTEXPR A checked_subtract_imp(A a, A b, const mpl::true_&)
 {
-   if(a > 0)
+   if (a > 0)
    {
-      if((b < 0) && ((integer_traits<A>::const_max + b) < a))
+      if ((b < 0) && ((integer_traits<A>::const_max + b) < a))
          raise_subtract_overflow();
    }
    else
    {
-      if((b > 0) && ((integer_traits<A>::const_min + b) > a))
+      if ((b > 0) && ((integer_traits<A>::const_min + b) > a))
          raise_subtract_overflow();
    }
    return a - b;
 }
 template <class A>
-inline A checked_subtract_imp(A a, A b, const mpl::false_&)
+inline BOOST_MP_CXX14_CONSTEXPR A checked_subtract_imp(A a, A b, const mpl::false_&)
 {
-   if(a < b)
+   if (a < b)
       raise_subtract_overflow();
    return a - b;
 }
 template <class A>
-inline A checked_subtract(A a, A b, const mpl::int_<checked>&)
+inline BOOST_MP_CXX14_CONSTEXPR A checked_subtract(A a, A b, const mpl::int_<checked>&)
 {
-   return checked_subtract_imp(a, b, boost::is_signed<A>());
+   return checked_subtract_imp(a, b, mpl::bool_<boost::is_signed<A>::value>());
 }
 template <class A>
-inline A checked_subtract(A a, A b, const mpl::int_<unchecked>&)
+inline BOOST_MP_CXX14_CONSTEXPR A checked_subtract(A a, A b, const mpl::int_<unchecked>&)
 {
    return a - b;
 }
 
 template <class A>
-inline A checked_multiply(A a, A b, const mpl::int_<checked>&)
+inline BOOST_MP_CXX14_CONSTEXPR A checked_multiply(A a, A b, const mpl::int_<checked>&)
 {
    BOOST_MP_USING_ABS
-   if(a && (integer_traits<A>::const_max / abs(a) < abs(b)))
+   if (a && (integer_traits<A>::const_max / abs(a) < abs(b)))
       raise_mul_overflow();
    return a * b;
 }
 template <class A>
-inline A checked_multiply(A a, A b, const mpl::int_<unchecked>&)
+inline BOOST_MP_CXX14_CONSTEXPR A checked_multiply(A a, A b, const mpl::int_<unchecked>&)
 {
    return a * b;
 }
 
 template <class A>
-inline A checked_divide(A a, A b, const mpl::int_<checked>&)
+inline BOOST_MP_CXX14_CONSTEXPR A checked_divide(A a, A b, const mpl::int_<checked>&)
 {
-   if(b == 0)
+   if (b == 0)
       raise_div_overflow();
    return a / b;
 }
 template <class A>
-inline A checked_divide(A a, A b, const mpl::int_<unchecked>&)
+inline BOOST_MP_CXX14_CONSTEXPR A checked_divide(A a, A b, const mpl::int_<unchecked>&)
 {
    return a / b;
 }
 
 template <class A>
-inline A checked_left_shift(A a, boost::ulong_long_type shift, const mpl::int_<checked>&)
+inline BOOST_MP_CXX14_CONSTEXPR A checked_left_shift(A a, boost::ulong_long_type shift, const mpl::int_<checked>&)
 {
-   if(a && shift)
+   if (a && shift)
    {
-      if((shift > sizeof(A) * CHAR_BIT) || (a >> (sizeof(A) * CHAR_BIT - shift)))
+      if ((shift > sizeof(A) * CHAR_BIT) || (a >> (sizeof(A) * CHAR_BIT - shift)))
          BOOST_THROW_EXCEPTION(std::overflow_error("Shift out of range"));
    }
    return a << shift;
 }
 template <class A>
-inline A checked_left_shift(A a, boost::ulong_long_type shift, const mpl::int_<unchecked>&)
+inline BOOST_MP_CXX14_CONSTEXPR A checked_left_shift(A a, boost::ulong_long_type shift, const mpl::int_<unchecked>&)
 {
    return (shift >= sizeof(A) * CHAR_BIT) ? 0 : a << shift;
 }
 
-}}}} // namespaces
+}}}} // namespace boost::multiprecision::backends::detail
 
 #endif
-