1 ///////////////////////////////////////////////////////////////
2 // Copyright 2013 Christopher Kormanyos. Distributed under the Boost
3 // Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_
7 // Test case for ticket:
8 // #8065: Multiprecision rounding issue
11 # define _SCL_SECURE_NO_WARNINGS
14 #include <boost/detail/lightweight_test.hpp>
16 #include <boost/multiprecision/cpp_dec_float.hpp>
17 #include <boost/math/special_functions/round.hpp>
20 static bool round_test_imp()
22 typedef boost::multiprecision::cpp_dec_float<N> mp_backend_type;
23 typedef boost::multiprecision::number<mp_backend_type, boost::multiprecision::et_off> mp_type;
25 const mp_type original_digits(1.0F);
27 const mp_type scale = pow(mp_type(10), N);
29 mp_type these_digits = original_digits * scale;
31 these_digits = boost::math::round(these_digits);
32 these_digits /= scale;
34 const std::string result = these_digits.str();
36 return (result == original_digits.str());
44 return (round_test_imp<N>() && round_test<N - 1>::test());
53 return round_test_imp<0>();
60 // Test cpp_dec_float rounding with boost::math::round() at various precisions:
62 const bool round_test_result = round_test<40>::test();
64 BOOST_CHECK_EQUAL(round_test_result, true);
66 return boost::report_errors();