]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/multiprecision/test/test_cpp_dec_float_round.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / multiprecision / test / test_cpp_dec_float_round.cpp
CommitLineData
7c673cae
FG
1///////////////////////////////////////////////////////////////
2// Copyright 2013 Christopher Kormanyos. Distributed under the Boost
3// Software License, Version 1.0. (See accompanying file
92f5a8d4 4// LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
7c673cae
FG
5//
6
7// Test case for ticket:
8// #8065: Multiprecision rounding issue
9
10#ifdef _MSC_VER
92f5a8d4 11#define _SCL_SECURE_NO_WARNINGS
7c673cae
FG
12#endif
13
14#include <boost/detail/lightweight_test.hpp>
15#include "test.hpp"
16#include <boost/multiprecision/cpp_dec_float.hpp>
17#include <boost/math/special_functions/round.hpp>
18
92f5a8d4 19template <int N>
7c673cae
FG
20static bool round_test_imp()
21{
92f5a8d4
TL
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;
7c673cae 24
92f5a8d4 25 const mp_type original_digits(1.0F);
7c673cae 26
92f5a8d4 27 const mp_type scale = pow(mp_type(10), N);
7c673cae 28
92f5a8d4 29 mp_type these_digits = original_digits * scale;
7c673cae 30
92f5a8d4
TL
31 these_digits = boost::math::round(these_digits);
32 these_digits /= scale;
7c673cae 33
92f5a8d4 34 const std::string result = these_digits.str();
7c673cae 35
92f5a8d4 36 return (result == original_digits.str());
7c673cae
FG
37}
38
92f5a8d4 39template <int N>
7c673cae
FG
40struct round_test
41{
92f5a8d4
TL
42 static bool test()
43 {
44 return (round_test_imp<N>() && round_test<N - 1>::test());
45 }
7c673cae
FG
46};
47
92f5a8d4 48template <>
7c673cae
FG
49struct round_test<0>
50{
92f5a8d4
TL
51 static bool test()
52 {
53 return round_test_imp<0>();
54 }
7c673cae
FG
55};
56
57int main()
58{
59 //
60 // Test cpp_dec_float rounding with boost::math::round() at various precisions:
61 //
62 const bool round_test_result = round_test<40>::test();
63
64 BOOST_CHECK_EQUAL(round_test_result, true);
65
66 return boost::report_errors();
67}