// 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
#include <boost/multiprecision/cpp_bin_float.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;
return ldexp(val, ui(gen));
}
-
using namespace boost::multiprecision;
#ifdef TEST_MPFR
typedef number<mpfr_float_backend<35> > good_type;
void test_special_cases()
{
- test_type max_val = (std::numeric_limits<test_type>::max)();
- test_type min_val = (std::numeric_limits<test_type>::min)();
- test_type eps = std::numeric_limits<test_type>::epsilon();
- test_type inf_val = (std::numeric_limits<test_type>::infinity)();
- test_type nan_val = (std::numeric_limits<test_type>::quiet_NaN)();
- test_type half = 0.5;
+ test_type max_val = (std::numeric_limits<test_type>::max)();
+ test_type min_val = (std::numeric_limits<test_type>::min)();
+ test_type eps = std::numeric_limits<test_type>::epsilon();
+ test_type inf_val = (std::numeric_limits<test_type>::infinity)();
+ test_type nan_val = (std::numeric_limits<test_type>::quiet_NaN)();
+ test_type half = 0.5;
test_type one_point_5 = 1.5;
-
+
BOOST_CHECK((boost::math::isnormal)(max_val));
BOOST_CHECK((boost::math::isnormal)(-max_val));
BOOST_CHECK((boost::math::isnormal)(min_val));
BOOST_CHECK((boost::math::isnan)(nan_val));
BOOST_CHECK((boost::math::isnan)(-nan_val));
- if(std::numeric_limits<test_type>::has_denorm)
+ if (std::numeric_limits<test_type>::has_denorm)
min_val = std::numeric_limits<test_type>::denorm_min();
// Adding epsilon will increment 1.0:
BOOST_CHECK(test_type(1) + eps / 2 == test_type(1));
// But it's not the smallest value that will do that:
test_type small = 1 + eps;
- small = ldexp(small, -std::numeric_limits<test_type>::digits);
+ small = ldexp(small, -std::numeric_limits<test_type>::digits);
BOOST_CHECK(test_type(1) + small != test_type(1));
- // And if we increment 1.0 first, then an even smaller
+ // And if we increment 1.0 first, then an even smaller
// addition will round up:
test_type one_next = test_type(1) + eps;
BOOST_CHECK(one_next + eps / 2 != one_next);
BOOST_CHECK(boost::math::signbit(-min_val / -2) == 0);
BOOST_CHECK(boost::math::signbit(-min_val / 2));
test_type neg_zero = min_val * -min_val;
- test_type zero = 0;
+ test_type zero = 0;
// Arithmetic involving signed zero:
BOOST_CHECK_EQUAL(-neg_zero, 0);
BOOST_CHECK(!boost::math::signbit(-neg_zero));
BOOST_CHECK(boost::math::signbit(round(small)));
BOOST_CHECK(boost::math::signbit(trunc(small)));
-
BOOST_CHECK_EQUAL(neg_zero * 2, 0);
BOOST_CHECK_EQUAL(neg_zero * test_type(2), 0);
BOOST_CHECK_EQUAL(2 * neg_zero, 0);
BOOST_CHECK(!boost::math::signbit(zero.convert_to<long double>()));
// Conversions to other types of special values:
- if(std::numeric_limits<float>::has_infinity)
+ if (std::numeric_limits<float>::has_infinity)
{
BOOST_CHECK_EQUAL(inf_val.convert_to<float>(), std::numeric_limits<float>::infinity());
BOOST_CHECK_EQUAL((-inf_val).convert_to<float>(), -std::numeric_limits<float>::infinity());
}
- if(std::numeric_limits<float>::has_quiet_NaN)
+ if (std::numeric_limits<float>::has_quiet_NaN)
{
BOOST_CHECK((boost::math::isnan)(nan_val.convert_to<float>()));
}
- if(std::numeric_limits<double>::has_infinity)
+ if (std::numeric_limits<double>::has_infinity)
{
BOOST_CHECK_EQUAL(inf_val.convert_to<double>(), std::numeric_limits<double>::infinity());
BOOST_CHECK_EQUAL((-inf_val).convert_to<double>(), -std::numeric_limits<double>::infinity());
}
- if(std::numeric_limits<double>::has_quiet_NaN)
+ if (std::numeric_limits<double>::has_quiet_NaN)
{
BOOST_CHECK((boost::math::isnan)(nan_val.convert_to<double>()));
}
- if(std::numeric_limits<long double>::has_infinity)
+ if (std::numeric_limits<long double>::has_infinity)
{
BOOST_CHECK_EQUAL(inf_val.convert_to<long double>(), std::numeric_limits<long double>::infinity());
BOOST_CHECK_EQUAL((-inf_val).convert_to<long double>(), -std::numeric_limits<long double>::infinity());
}
- if(std::numeric_limits<long double>::has_quiet_NaN)
+ if (std::numeric_limits<long double>::has_quiet_NaN)
{
BOOST_CHECK((boost::math::isnan)(nan_val.convert_to<long double>()));
}
BOOST_CHECK_EQUAL(good_type(test_type(-a + -b)), good_type(-ga + -gb));
BOOST_CHECK_EQUAL(good_type(test_type(-b + -a)), good_type(-gb + -ga));
- b = ldexp(test_type(0.5), -std::numeric_limits<test_type>::digits);
+ b = ldexp(test_type(0.5), -std::numeric_limits<test_type>::digits);
gb = ldexp(good_type(0.5), -std::numeric_limits<good_type>::digits);
BOOST_CHECK_EQUAL(good_type(test_type(a - b)), good_type(ga - gb));
BOOST_CHECK_EQUAL(good_type(test_type(b - a)), good_type(gb - ga));
BOOST_CHECK_EQUAL(good_type(test_type(-a + -b)), good_type(-ga + -gb));
BOOST_CHECK_EQUAL(good_type(test_type(-b + -a)), good_type(-gb + -ga));
- b = ldexp(test_type(1), -std::numeric_limits<test_type>::digits);
+ b = ldexp(test_type(1), -std::numeric_limits<test_type>::digits);
gb = ldexp(good_type(1), -std::numeric_limits<good_type>::digits);
BOOST_CHECK_EQUAL(good_type(test_type(a - b)), good_type(ga - gb));
BOOST_CHECK_EQUAL(good_type(test_type(b - a)), good_type(gb - ga));
BOOST_CHECK_EQUAL(good_type(test_type(-a + -b)), good_type(-ga + -gb));
BOOST_CHECK_EQUAL(good_type(test_type(-b + -a)), good_type(-gb + -ga));
- b = ldexp(test_type(0.50000000001), -std::numeric_limits<test_type>::digits);
+ b = ldexp(test_type(0.50000000001), -std::numeric_limits<test_type>::digits);
gb = ldexp(good_type(0.50000000001), -std::numeric_limits<good_type>::digits);
BOOST_CHECK_EQUAL(good_type(test_type(a - b)), good_type(ga - gb));
BOOST_CHECK_EQUAL(good_type(test_type(b - a)), good_type(gb - ga));
BOOST_CHECK_EQUAL(good_type(test_type(-a + -b)), good_type(-ga + -gb));
BOOST_CHECK_EQUAL(good_type(test_type(-b + -a)), good_type(-gb + -ga));
- a = a + ldexp(a, -20);
+ a = a + ldexp(a, -20);
ga = ga + ldexp(ga, -20);
BOOST_CHECK_EQUAL(good_type(test_type(a - b)), good_type(ga - gb));
BOOST_CHECK_EQUAL(good_type(test_type(b - a)), good_type(gb - ga));
BOOST_CHECK_EQUAL(good_type(test_type(-a + -b)), good_type(-ga + -gb));
BOOST_CHECK_EQUAL(good_type(test_type(-b + -a)), good_type(-gb + -ga));
- b = ldexp(test_type(0.5), -std::numeric_limits<test_type>::digits);
+ b = ldexp(test_type(0.5), -std::numeric_limits<test_type>::digits);
gb = ldexp(good_type(0.5), -std::numeric_limits<good_type>::digits);
BOOST_CHECK_EQUAL(good_type(test_type(a - b)), good_type(ga - gb));
BOOST_CHECK_EQUAL(good_type(test_type(b - a)), good_type(gb - ga));
BOOST_CHECK_EQUAL(good_type(test_type(-a + -b)), good_type(-ga + -gb));
BOOST_CHECK_EQUAL(good_type(test_type(-b + -a)), good_type(-gb + -ga));
- b = ldexp(test_type(1), -std::numeric_limits<test_type>::digits);
+ b = ldexp(test_type(1), -std::numeric_limits<test_type>::digits);
gb = ldexp(good_type(1), -std::numeric_limits<good_type>::digits);
BOOST_CHECK_EQUAL(good_type(test_type(a - b)), good_type(ga - gb));
BOOST_CHECK_EQUAL(good_type(test_type(b - a)), good_type(gb - ga));
BOOST_CHECK_EQUAL(good_type(test_type(-a + -b)), good_type(-ga + -gb));
BOOST_CHECK_EQUAL(good_type(test_type(-b + -a)), good_type(-gb + -ga));
- b = ldexp(test_type(0.50000000001), -std::numeric_limits<test_type>::digits);
+ b = ldexp(test_type(0.50000000001), -std::numeric_limits<test_type>::digits);
gb = ldexp(good_type(0.50000000001), -std::numeric_limits<good_type>::digits);
BOOST_CHECK_EQUAL(good_type(test_type(a - b)), good_type(ga - gb));
BOOST_CHECK_EQUAL(good_type(test_type(b - a)), good_type(gb - ga));
BOOST_CHECK_EQUAL(good_type(test_type(-a + -b)), good_type(-ga + -gb));
BOOST_CHECK_EQUAL(good_type(test_type(-b + -a)), good_type(-gb + -ga));
- a = 1;
- a = boost::math::float_prior(a);
+ a = 1;
+ a = boost::math::float_prior(a);
ga = 1;
ga = boost::math::float_prior(ga);
BOOST_CHECK_EQUAL(good_type(test_type(a - b)), good_type(ga - gb));
BOOST_CHECK_EQUAL(good_type(test_type(-a + -b)), good_type(-ga + -gb));
BOOST_CHECK_EQUAL(good_type(test_type(-b + -a)), good_type(-gb + -ga));
- b = ldexp(test_type(0.5), -std::numeric_limits<test_type>::digits);
+ b = ldexp(test_type(0.5), -std::numeric_limits<test_type>::digits);
gb = ldexp(good_type(0.5), -std::numeric_limits<good_type>::digits);
BOOST_CHECK_EQUAL(good_type(test_type(a - b)), good_type(ga - gb));
BOOST_CHECK_EQUAL(good_type(test_type(b - a)), good_type(gb - ga));
BOOST_CHECK_EQUAL(good_type(test_type(-a + -b)), good_type(-ga + -gb));
BOOST_CHECK_EQUAL(good_type(test_type(-b + -a)), good_type(-gb + -ga));
- b = ldexp(test_type(1), -std::numeric_limits<test_type>::digits);
+ b = ldexp(test_type(1), -std::numeric_limits<test_type>::digits);
gb = ldexp(good_type(1), -std::numeric_limits<good_type>::digits);
BOOST_CHECK_EQUAL(good_type(test_type(a - b)), good_type(ga - gb));
BOOST_CHECK_EQUAL(good_type(test_type(b - a)), good_type(gb - ga));
BOOST_CHECK_EQUAL(good_type(test_type(-a + -b)), good_type(-ga + -gb));
BOOST_CHECK_EQUAL(good_type(test_type(-b + -a)), good_type(-gb + -ga));
- b = ldexp(test_type(0.50000000001), -std::numeric_limits<test_type>::digits);
+ b = ldexp(test_type(0.50000000001), -std::numeric_limits<test_type>::digits);
gb = ldexp(good_type(0.50000000001), -std::numeric_limits<good_type>::digits);
BOOST_CHECK_EQUAL(good_type(test_type(a - b)), good_type(ga - gb));
BOOST_CHECK_EQUAL(good_type(test_type(b - a)), good_type(gb - ga));
{
test_special_cases();
unsigned error_count = 0;
- for(unsigned i = 0; i < 100000; ++i)
+ for (unsigned i = 0; i < 100000; ++i)
{
good_type a = generate_random<good_type>();
good_type b = generate_random<good_type>();
BOOST_CHECK_EQUAL(test_type(a / ui), ta / ui);
BOOST_CHECK_EQUAL(test_type(-a / ui), -ta / ui);
// Error reporting:
- if(boost::detail::test_errors() != error_count)
+ if (boost::detail::test_errors() != error_count)
{
error_count = boost::detail::test_errors();
std::cout << std::setprecision(std::numeric_limits<test_type>::max_digits10) << std::scientific;
}
return boost::report_errors();
}
-