]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/multiprecision/test/test_int_sqrt.cpp
1 ///////////////////////////////////////////////////////////////
2 // Copyright 2012 John Maddock. Distributed under the Boost
3 // Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
6 #include <boost/multiprecision/cpp_int.hpp>
9 using Integer
= boost::multiprecision::cpp_int
;
11 void check_sqrt(const Integer
& s
, const Integer
& r
, const Integer
& v
) {
12 BOOST_CHECK_EQUAL(s
* s
+ r
, v
);
13 BOOST_CHECK_GE(r
, Integer(0));
14 BOOST_CHECK_LE(s
* s
, v
);
15 BOOST_CHECK_GT((s
+ 1) * (s
+ 1), v
);
19 void check(const I
& v
) {
21 I s
= boost::multiprecision::sqrt(v
, r
);
22 check_sqrt(Integer(s
), Integer(r
), Integer(v
));
25 void check_types(const Integer
& v
) {
26 using namespace boost::multiprecision
;
32 check(static_cast<uint32_t>(v
));
35 check(static_cast<uint64_t>(v
));
49 void check_near(const Integer
& v
) {
51 for (size_t j
= 0; j
< 8; j
++) {
52 check_types(v
- Integer(1 << j
));
53 check_types(v
- Integer(1 << j
) - 1);
54 check_types(v
- Integer(1 << j
) + 1);
55 check_types(v
+ Integer(1 << j
));
56 check_types(v
+ Integer(1 << j
) - 1);
57 check_types(v
+ Integer(1 << j
) + 1);
62 for (size_t i
= 0; i
< (1 << 16); i
++) {
63 check_types(Integer(i
));
68 for (size_t i
= 256; i
< (1 << 14); i
++) {
69 check_near(Integer(i
) * Integer(i
));
74 for (size_t i
= 24; i
< 2048; i
++) {
75 check_near(Integer(i
) << i
);
80 for (size_t bits
= 128; bits
<= 2048; bits
*= 2) {
81 Integer i
= Integer(1) << bits
;
83 Integer step
= (i
- s
) / (1 << 8);
84 for (Integer j
= s
; j
<= i
; j
+= step
) {
92 using namespace boost::multiprecision
;
99 return boost::report_errors();