Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / multiprecision / test / test_rat_float_interconv.cpp
index b9dc4d0..29393fd 100644 (file)
@@ -6,7 +6,7 @@
 // or copy at http://www.boost.org/LICENSE_1_0.txt)
 
 #ifdef _MSC_VER
-#  define _SCL_SECURE_NO_WARNINGS
+#define _SCL_SECURE_NO_WARNINGS
 #endif
 
 #if defined(TEST1) || defined(TEST2) || defined(TEST3) || defined(TEST4)
@@ -26,7 +26,7 @@
 #include <iomanip>
 
 #ifdef BOOST_MSVC
-#pragma warning(disable:4127)
+#pragma warning(disable : 4127)
 #endif
 
 template <class Clock>
@@ -46,12 +46,12 @@ struct stopwatch
       m_start = Clock::now();
    }
 
-private:
+ private:
    typename Clock::time_point m_start;
 };
 
 template <class T>
-struct exponent_type 
+struct exponent_type
 {
    typedef int type;
 };
@@ -66,10 +66,10 @@ T generate_random_float()
 {
    BOOST_MATH_STD_USING
    typedef typename exponent_type<T>::type e_type;
-   static boost::random::mt19937 gen;
-   T val = gen();
-   T prev_val = -1;
-   while(val != prev_val)
+   static boost::random::mt19937           gen;
+   T                                       val      = gen();
+   T                                       prev_val = -1;
+   while (val != prev_val)
    {
       val *= (gen.max)();
       prev_val = val;
@@ -78,7 +78,7 @@ T generate_random_float()
    e_type e;
    val = frexp(val, &e);
 
-   static const int max_exponent_value = (std::min)(static_cast<int>(std::numeric_limits<T>::max_exponent - std::numeric_limits<T>::digits - 20), 2000);
+   static const int                                       max_exponent_value = (std::min)(static_cast<int>(std::numeric_limits<T>::max_exponent - std::numeric_limits<T>::digits - 20), 2000);
    static boost::random::uniform_int_distribution<e_type> ui(0, max_exponent_value);
    return ldexp(val, ui(gen));
 }
@@ -88,7 +88,7 @@ void do_round_trip(const Float& val)
 {
 #ifndef BOOST_MP_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
    BOOST_MATH_STD_USING
-   Rat rat(val);
+   Rat   rat(val);
    Float new_f(rat);
    BOOST_CHECK_EQUAL(val, new_f);
    //
@@ -96,39 +96,39 @@ void do_round_trip(const Float& val)
    // (0.25ulp) from rat and check that it rounds to the same value:
    //
    typename exponent_type<Float>::type e;
-   Float t = frexp(val, &e);
+   Float                               t = frexp(val, &e);
    (void)t; // warning suppression
    e -= std::numeric_limits<Float>::digits + 2;
    BOOST_ASSERT(val == (val + ldexp(Float(1), e)));
-   Rat delta, rounded;
+   Rat                                                               delta, rounded;
    typedef typename boost::multiprecision::component_type<Rat>::type i_type;
-   i_type i(1);
+   i_type                                                            i(1);
    i <<= (e < 0 ? -e : e);
-   if(e > 0)
+   if (e > 0)
       delta.assign(i);
    else
       delta = Rat(i_type(1), i);
    rounded = rat + delta;
-   new_f = static_cast<Float>(rounded);
+   new_f   = static_cast<Float>(rounded);
    BOOST_CHECK_EQUAL(val, new_f);
    rounded = rat - delta;
-   new_f = static_cast<Float>(rounded);
+   new_f   = static_cast<Float>(rounded);
    BOOST_CHECK_EQUAL(val, new_f);
 
    delta /= 2;
    rounded = rat + delta;
-   new_f = static_cast<Float>(rounded);
+   new_f   = static_cast<Float>(rounded);
    BOOST_CHECK_EQUAL(val, new_f);
    rounded = rat - delta;
-   new_f = static_cast<Float>(rounded);
+   new_f   = static_cast<Float>(rounded);
    BOOST_CHECK_EQUAL(val, new_f);
 
    delta /= 2;
    rounded = rat + delta;
-   new_f = static_cast<Float>(rounded);
+   new_f   = static_cast<Float>(rounded);
    BOOST_CHECK_EQUAL(val, new_f);
    rounded = rat - delta;
-   new_f = static_cast<Float>(rounded);
+   new_f   = static_cast<Float>(rounded);
    BOOST_CHECK_EQUAL(val, new_f);
 #endif
 }
@@ -157,10 +157,10 @@ void test_round_trip()
       Float val = generate_random_float<Float>();
       do_round_trip<Float, Rat>(val);
       do_round_trip<Float, Rat>(Float(-val));
-      do_round_trip<Float, Rat>(Float(1/val));
-      do_round_trip<Float, Rat>(Float(-1/val));
+      do_round_trip<Float, Rat>(Float(1 / val));
+      do_round_trip<Float, Rat>(Float(-1 / val));
       count += 4;
-      if(boost::detail::test_errors() > 100)
+      if (boost::detail::test_errors() > 100)
          break;
    }
 
@@ -172,7 +172,7 @@ void test_round_trip()
 template <class Int>
 Int generate_random_int()
 {
-   static boost::random::mt19937 gen;
+   static boost::random::mt19937                                                       gen;
    static boost::random::uniform_int_distribution<boost::random::mt19937::result_type> d(1, 20);
 
    int lim;
@@ -180,7 +180,7 @@ Int generate_random_int()
 
    lim = d(gen);
 
-   for(int i = 0; i < lim; ++i)
+   for (int i = 0; i < lim; ++i)
    {
       cppi *= (gen.max)();
       cppi += gen();
@@ -200,7 +200,7 @@ void test_random_rationals()
 #endif
 
    typedef typename boost::multiprecision::component_type<Rat>::type i_type;
-   stopwatch<boost::chrono::high_resolution_clock> w;
+   stopwatch<boost::chrono::high_resolution_clock>                   w;
 
    int count = 0;
 
@@ -210,18 +210,18 @@ void test_random_rationals()
    while (boost::chrono::duration_cast<boost::chrono::duration<double> >(w.elapsed()).count() < 50)
 #endif
    {
-      Rat rat(generate_random_int<i_type>(), generate_random_int<i_type>());
+      Rat   rat(generate_random_int<i_type>(), generate_random_int<i_type>());
       Float f(rat);
-      Rat new_rat(f); // rounded value
-      int c = new_rat.compare(rat);
-      if(c < 0)
+      Rat   new_rat(f); // rounded value
+      int   c = new_rat.compare(rat);
+      if (c < 0)
       {
          // If f was rounded down, next float up must be above the original value:
          f = boost::math::float_next(f);
          new_rat.assign(f);
          BOOST_CHECK(new_rat >= rat);
       }
-      else if(c > 0)
+      else if (c > 0)
       {
          // If f was rounded up, next float down must be below the original value:
          f = boost::math::float_prior(f);
@@ -232,7 +232,7 @@ void test_random_rationals()
       {
          // Values were equal... nothing to test.
       }
-      if(boost::detail::test_errors() > 100)
+      if (boost::detail::test_errors() > 100)
          break;
    }
 
@@ -263,7 +263,6 @@ void double_spot_tests()
    rat += boost::multiprecision::cpp_rational(boost::multiprecision::cpp_int(1), boost::multiprecision::cpp_int(boost::multiprecision::cpp_int(1) << 52));
    // tie, but last bit is now a 1 so we round up:
    BOOST_CHECK_NE(d, rat.convert_to<double>());
-
 }
 
 #endif
@@ -293,4 +292,3 @@ int main()
 #endif
    return boost::report_errors();
 }
-