/////////////////////////////////////////////////////////////// // Copyright 2013 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_ // // Compare arithmetic results using fixed_int to GMP results. // #ifdef _MSC_VER # define _SCL_SECURE_NO_WARNINGS #endif #include #include #include #include #include "test.hpp" #include #include #include #include #include template T generate_random(unsigned bits_wanted) { typedef typename T::backend_type::exponent_type e_type; static boost::random::mt19937 gen; T val = gen(); T prev_val = -1; while(val != prev_val) { val *= (gen.max)(); prev_val = val; val += gen(); } e_type e; val = frexp(val, &e); static boost::random::uniform_int_distribution ui(std::numeric_limits::min_exponent + 1, std::numeric_limits::max_exponent - 1); return ldexp(val, ui(gen)); } template void test() { boost::timer tim; while(true) { T val = generate_random(boost::math::tools::digits()); std::stringstream ss; boost::archive::text_oarchive oa(ss); oa << static_cast(val); boost::archive::text_iarchive ia(ss); T val2; ia >> val2; BOOST_CHECK_EQUAL(val, val2); // // Check to see if test is taking too long. // Tests run on the compiler farm time out after 300 seconds, // so don't get too close to that: // if(tim.elapsed() > 150) { std::cout << "Timeout reached, aborting tests now....\n"; break; } } } #if !defined(TEST1) && !defined(TEST2) # define TEST1 # define TEST2 #endif int main() { using namespace boost::multiprecision; #ifdef TEST1 test(); #endif #ifndef TEST2 test > > >(); #endif return boost::report_errors(); }