Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / multiprecision / test / test_cpp_bin_float_conv.cpp
index de3cd48..3ffebdb 100644 (file)
@@ -5,7 +5,7 @@
 //
 
 #ifdef _MSC_VER
-#  define _SCL_SECURE_NO_WARNINGS
+#define _SCL_SECURE_NO_WARNINGS
 #endif
 
 #include <boost/detail/lightweight_test.hpp>
 #include <boost/random/uniform_int.hpp>
 #include <boost/cstdint.hpp>
 
-
 template <class T>
 T generate_random()
 {
-   typedef int e_type;
+   typedef int                   e_type;
    static boost::random::mt19937 gen;
-   T val = gen();
-   T prev_val = -1;
-   while(val != prev_val)
+   T                             val      = gen();
+   T                             prev_val = -1;
+   while (val != prev_val)
    {
       val *= (gen.max)();
       prev_val = val;
@@ -42,11 +41,11 @@ T generate_random()
 template <class T>
 void check_round(const T& val, bool check_extended = false)
 {
-   double d1 = val.template convert_to<double>();
-   double d2 = boost::math::nextafter(d1, d1 < val ? DBL_MAX : -DBL_MAX);
-   T diff1 = abs(d1 - val);
-   T diff2 = abs(d2 - val);
-   if(diff2 < diff1)
+   double d1    = val.template convert_to<double>();
+   double d2    = boost::math::nextafter(d1, d1 < val ? DBL_MAX : -DBL_MAX);
+   T      diff1 = abs(d1 - val);
+   T      diff2 = abs(d2 - val);
+   if (diff2 < diff1)
    {
       // Some debugging code here...
       std::cout << val.str() << std::endl;
@@ -67,16 +66,16 @@ void check_round(const T& val, bool check_extended = false)
 
 #if !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
 
-   if(check_extended)
+   if (check_extended)
    {
       //
       // We should check long double as well:
       //
       long double l1 = val.template convert_to<long double>();
       long double l2 = boost::math::nextafter(d1, d1 < val ? LDBL_MAX : -LDBL_MAX);
-      diff1 = abs(l1 - val);
-      diff2 = abs(l2 - val);
-      if(diff2 < diff1)
+      diff1          = abs(l1 - val);
+      diff2          = abs(l2 - val);
+      if (diff2 < diff1)
       {
          // Some debugging code here...
          std::cout << val.str() << std::endl;
@@ -92,70 +91,68 @@ void check_round(const T& val, bool check_extended = false)
    }
 
 #endif
-
 }
 
-
 int main()
 {
    using namespace boost::multiprecision;
 
-   cpp_int i(20);
+   cpp_int          i(20);
    cpp_bin_float_50 f50(i);
    BOOST_CHECK_EQUAL(f50, 20);
    f50 = i.convert_to<cpp_bin_float_50>();
    BOOST_CHECK_EQUAL(f50, 20);
 
-   int1024_t i1024(45);
+   int1024_t         i1024(45);
    cpp_bin_float_100 f100(i1024);
    BOOST_CHECK_EQUAL(f100, 45);
    f100 = i1024.convert_to<cpp_bin_float_100>();
    BOOST_CHECK_EQUAL(f100, 45);
 
-   uint1024_t ui1024(55);
+   uint1024_t        ui1024(55);
    cpp_bin_float_100 f100b(ui1024);
    BOOST_CHECK_EQUAL(f100b, 55);
    f100b = ui1024.convert_to<cpp_bin_float_100>();
    BOOST_CHECK_EQUAL(f100b, 55);
 
    typedef number<cpp_int_backend<32, 32>, et_off> i32_t;
-   i32_t i32(67);
-   cpp_bin_float_100 f100c(i32);
+   i32_t                                           i32(67);
+   cpp_bin_float_100                               f100c(i32);
    BOOST_CHECK_EQUAL(f100c, 67);
    f100c = i32.convert_to<cpp_bin_float_100>();
    BOOST_CHECK_EQUAL(f100c, 67);
 
    typedef number<cpp_int_backend<32, 32, unsigned_magnitude>, et_off> ui32_t;
-   ui32_t ui32(98);
-   cpp_bin_float_100 f100d(ui32);
+   ui32_t                                                              ui32(98);
+   cpp_bin_float_100                                                   f100d(ui32);
    BOOST_CHECK_EQUAL(f100d, 98);
    f100d = ui32.convert_to<cpp_bin_float_100>();
    BOOST_CHECK_EQUAL(f100d, 98);
 
    typedef number<cpp_int_backend<64, 64>, et_off> i64_t;
-   i64_t i64(67);
-   cpp_bin_float_100 f100e(i64);
+   i64_t                                           i64(67);
+   cpp_bin_float_100                               f100e(i64);
    BOOST_CHECK_EQUAL(f100e, 67);
    f100e = i64.convert_to<cpp_bin_float_100>();
    BOOST_CHECK_EQUAL(f100e, 67);
 
    typedef number<cpp_int_backend<64, 64, unsigned_magnitude>, et_off> ui64_t;
-   ui64_t ui64(98);
-   cpp_bin_float_100 f100f(ui64);
+   ui64_t                                                              ui64(98);
+   cpp_bin_float_100                                                   f100f(ui64);
    BOOST_CHECK_EQUAL(f100f, 98);
    f100f = ui64.convert_to<cpp_bin_float_100>();
    BOOST_CHECK_EQUAL(f100f, 98);
 
    typedef number<cpp_int_backend<128, 128>, et_off> i128_t;
-   i128_t i128(67);
-   cpp_bin_float_100 f100g(i128);
+   i128_t                                            i128(67);
+   cpp_bin_float_100                                 f100g(i128);
    BOOST_CHECK_EQUAL(f100g, 67);
    f100g = i128.convert_to<cpp_bin_float_100>();
    BOOST_CHECK_EQUAL(f100g, 67);
 
    typedef number<cpp_int_backend<128, 128, unsigned_magnitude>, et_off> ui128_t;
-   ui128_t ui128(98);
-   cpp_bin_float_100 f100h(ui128);
+   ui128_t                                                               ui128(98);
+   cpp_bin_float_100                                                     f100h(ui128);
    BOOST_CHECK_EQUAL(f100h, 98);
    f100h = ui128.convert_to<cpp_bin_float_100>();
    BOOST_CHECK_EQUAL(f100h, 98);
@@ -181,7 +178,7 @@ int main()
    BOOST_CHECK_EQUAL(ext_float.convert_to<float>(), 0);
    ext_float = (std::numeric_limits<double>::max)();
    ext_float *= 16;
-   if(std::numeric_limits<double>::has_infinity)
+   if (std::numeric_limits<double>::has_infinity)
    {
       BOOST_CHECK_EQUAL(ext_float.convert_to<double>(), std::numeric_limits<double>::infinity());
    }
@@ -190,7 +187,7 @@ int main()
       BOOST_CHECK_EQUAL(ext_float.convert_to<double>(), (std::numeric_limits<double>::max)());
    }
    ext_float = -ext_float;
-   if(std::numeric_limits<double>::has_infinity)
+   if (std::numeric_limits<double>::has_infinity)
    {
       BOOST_CHECK_EQUAL(ext_float.convert_to<double>(), -std::numeric_limits<double>::infinity());
    }
@@ -232,7 +229,7 @@ int main()
       check_round(boost::math::float_next(r1));
       check_round(boost::math::float_prior(r1));
       r1 = ldexp(r1, -1);
-   } while(ilogb(r1) > std::numeric_limits<double>::min_exponent - 5 - std::numeric_limits<double>::digits);
+   } while (ilogb(r1) > std::numeric_limits<double>::min_exponent - 5 - std::numeric_limits<double>::digits);
    r1 = -3;
    r1 = ldexp(r1, std::numeric_limits<double>::min_exponent);
    do
@@ -241,7 +238,7 @@ int main()
       check_round(boost::math::float_next(r1));
       check_round(boost::math::float_prior(r1));
       r1 = ldexp(r1, -1);
-   } while(ilogb(r1) > std::numeric_limits<double>::min_exponent - 5 - std::numeric_limits<double>::digits);
+   } while (ilogb(r1) > std::numeric_limits<double>::min_exponent - 5 - std::numeric_limits<double>::digits);
    //
    // Again when not rounding up:
    //
@@ -253,7 +250,7 @@ int main()
       check_round(boost::math::float_next(r1));
       check_round(boost::math::float_prior(r1));
       r1 = ldexp(r1, -1);
-   } while(ilogb(r1) > std::numeric_limits<double>::min_exponent - 5 - std::numeric_limits<double>::digits);
+   } while (ilogb(r1) > std::numeric_limits<double>::min_exponent - 5 - std::numeric_limits<double>::digits);
    r1 = -1;
    r1 = ldexp(r1, std::numeric_limits<double>::min_exponent);
    do
@@ -262,15 +259,14 @@ int main()
       check_round(boost::math::float_next(r1));
       check_round(boost::math::float_prior(r1));
       r1 = ldexp(r1, -1);
-   } while(ilogb(r1) > std::numeric_limits<double>::min_exponent - 5 - std::numeric_limits<double>::digits);
+   } while (ilogb(r1) > std::numeric_limits<double>::min_exponent - 5 - std::numeric_limits<double>::digits);
    //
    // Test random conversions:
    //
-   for(unsigned j = 0; j < 10000; ++j)
+   for (unsigned j = 0; j < 10000; ++j)
    {
       check_round(generate_random<cpp_bin_float_50>(), true);
    }
 
    return boost::report_errors();
 }
-