]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/libs/multiprecision/test/test_checked_cpp_int.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / multiprecision / test / test_checked_cpp_int.cpp
index 7ddfb19115d24ef4ef7dc440dfb82df1a0be1866..0fd256a92a1ae173dd21ad2e291e09566773961a 100644 (file)
@@ -1,14 +1,14 @@
 ///////////////////////////////////////////////////////////////
 //  Copyright 2012 John Maddock. Distributed under the Boost
 //  Software License, Version 1.0. (See accompanying file
-//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_
+//  LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
 
 //
 // Compare arithmetic results using fixed_int to GMP results.
 //
 
 #ifdef _MSC_VER
-#  define _SCL_SECURE_NO_WARNINGS
+#define _SCL_SECURE_NO_WARNINGS
 #endif
 
 #include <boost/multiprecision/cpp_int.hpp>
 template <class T>
 T generate_random(unsigned bits_wanted)
 {
-   static boost::random::mt19937 gen;
+   static boost::random::mt19937               gen;
    typedef boost::random::mt19937::result_type random_type;
 
-   T max_val;
+   T        max_val;
    unsigned digits;
-   if(std::numeric_limits<T>::is_bounded && (bits_wanted == (unsigned)std::numeric_limits<T>::digits))
+   if (std::numeric_limits<T>::is_bounded && (bits_wanted == (unsigned)std::numeric_limits<T>::digits))
    {
       max_val = (std::numeric_limits<T>::max)();
-      digits = std::numeric_limits<T>::digits;
+      digits  = std::numeric_limits<T>::digits;
    }
    else
    {
       max_val = T(1) << bits_wanted;
-      digits = bits_wanted;
+      digits  = bits_wanted;
    }
 
    unsigned bits_per_r_val = std::numeric_limits<random_type>::digits - 1;
-   while((random_type(1) << bits_per_r_val) > (gen.max)()) --bits_per_r_val;
+   while ((random_type(1) << bits_per_r_val) > (gen.max)())
+      --bits_per_r_val;
 
    unsigned terms_needed = digits / bits_per_r_val + 1;
 
    T val = 0;
-   for(unsigned i = 0; i < terms_needed; ++i)
+   for (unsigned i = 0; i < terms_needed; ++i)
    {
       val *= (gen.max)();
       val += gen();
@@ -50,7 +51,6 @@ T generate_random(unsigned bits_wanted)
    return val;
 }
 
-
 template <class Number>
 void test_signed_overflow(Number a, Number b, const boost::mpl::true_&)
 {
@@ -70,7 +70,7 @@ void test()
    using namespace boost::multiprecision;
    typedef Number test_type;
 
-   if(std::numeric_limits<test_type>::is_bounded)
+   if (std::numeric_limits<test_type>::is_bounded)
    {
       test_type val = (std::numeric_limits<test_type>::max)();
 #ifndef BOOST_NO_EXCEPTIONS
@@ -83,7 +83,7 @@ void test()
       val += 1;
       BOOST_CHECK_THROW(test_type(2 * val), std::overflow_error);
 
-      if(std::numeric_limits<test_type>::is_signed)
+      if (std::numeric_limits<test_type>::is_signed)
       {
          val = (std::numeric_limits<test_type>::min)();
          BOOST_CHECK_THROW(--val, std::overflow_error);
@@ -105,11 +105,11 @@ void test()
       //
       // Test overflow in random values:
       //
-      for(unsigned bits = 30; bits < std::numeric_limits<test_type>::digits; bits += 30)
+      for (unsigned bits = 30; bits < std::numeric_limits<test_type>::digits; bits += 30)
       {
-         for(unsigned i = 0; i < 100; ++i)
+         for (unsigned i = 0; i < 100; ++i)
          {
-            val = static_cast<test_type>(generate_random<cpp_int>(bits));
+            val            = static_cast<test_type>(generate_random<cpp_int>(bits));
             test_type val2 = 1 + (std::numeric_limits<test_type>::max)() / val;
             BOOST_CHECK_THROW(test_type(val2 * val), std::overflow_error);
             test_signed_overflow(val2, val, boost::mpl::bool_<std::numeric_limits<test_type>::is_signed>());
@@ -120,7 +120,7 @@ void test()
             ++val2;
             BOOST_CHECK_THROW(test_type(val2 + val), std::overflow_error);
             BOOST_CHECK((val2 - 1) + val == (std::numeric_limits<test_type>::max)());
-            if(std::numeric_limits<test_type>::is_signed)
+            if (std::numeric_limits<test_type>::is_signed)
             {
                val2 = (std::numeric_limits<test_type>::min)() + val;
                --val2;
@@ -135,7 +135,7 @@ void test()
    }
 
 #ifndef BOOST_NO_EXCEPTIONS
-   if(std::numeric_limits<test_type>::is_signed)
+   if (std::numeric_limits<test_type>::is_signed)
    {
       test_type a = -1;
       test_type b = 1;
@@ -149,7 +149,7 @@ void test()
       BOOST_CHECK_THROW(test_type(-2), std::range_error);
       BOOST_CHECK_THROW(test_type("-2"), std::range_error);
    }
-   if(std::numeric_limits<test_type>::digits < std::numeric_limits<long long>::digits)
+   if (std::numeric_limits<test_type>::digits < std::numeric_limits<long long>::digits)
    {
       long long llm = (std::numeric_limits<long long>::max)();
       test_type t;
@@ -168,7 +168,7 @@ void test()
    BOOST_CHECK_THROW(test_type("12A"), std::runtime_error);
    BOOST_CHECK_THROW(test_type("0658"), std::runtime_error);
 
-   if(std::numeric_limits<test_type>::is_signed)
+   if (std::numeric_limits<test_type>::is_signed)
    {
       BOOST_CHECK_THROW(test_type(-2).str(0, std::ios_base::hex), std::runtime_error);
       BOOST_CHECK_THROW(test_type(-2).str(0, std::ios_base::oct), std::runtime_error);
@@ -195,6 +195,3 @@ int main()
    test<number<cpp_int_backend<48, 48, unsigned_magnitude, checked, void> > >();
    return boost::report_errors();
 }
-
-
-