1 // (C) Copyright John Maddock 2019.
2 // Use, modification and distribution are subject to the
3 // Boost Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 #include "constexpr_arithmetric_test.hpp"
7 #include "boost/multiprecision/cpp_int.hpp"
8 #include "test.hpp"
9
10 template <class F, class V>
non_constexpr_invoke(F f,V v)11 decltype(std::declval<F>()(std::declval<V>())) non_constexpr_invoke(F f, V v)
12 {
13 return f(v);
14 }
15
main()16 int main()
17 {
18 typedef boost::multiprecision::checked_int128_t int_backend;
19 typedef boost::multiprecision::checked_uint128_t unsigned_backend;
20
21 {
22 constexpr int_backend a(22);
23 constexpr unsigned_backend c(22);
24 constexpr int_backend b = test_constexpr_add_subtract(a);
25 constexpr unsigned_backend d = test_constexpr_add_subtract(c);
26
27 constexpr long long llv = (long long)b;
28
29 static_assert(b == -108);
30 static_assert(d == 554);
31 static_assert(llv == -108);
32
33 BOOST_CHECK_EQUAL(b, non_constexpr_invoke(test_constexpr_add_subtract<int_backend>, a));
34 BOOST_CHECK_EQUAL(d, non_constexpr_invoke(test_constexpr_add_subtract<unsigned_backend>, c));
35 }
36 {
37 constexpr int_backend a(22);
38 constexpr unsigned_backend c(22);
39 constexpr int_backend b = test_constexpr_mul_divide(a);
40 constexpr unsigned_backend d = test_constexpr_mul_divide(c);
41 static_assert(b == 22);
42 static_assert(d == 22);
43
44 BOOST_CHECK_EQUAL(b, non_constexpr_invoke(test_constexpr_mul_divide<int_backend>, a));
45 BOOST_CHECK_EQUAL(d, non_constexpr_invoke(test_constexpr_mul_divide<unsigned_backend>, c));
46 }
47 {
48 constexpr int_backend a(22);
49 constexpr unsigned_backend c(22);
50 constexpr int_backend b = test_constexpr_bitwise(a);
51 constexpr unsigned_backend d = test_constexpr_bitwise(c);
52 #ifdef BOOST_HAS_INT128
53 static_assert(b == 230);
54 static_assert(d == 120);
55 #else
56 static_assert(b == 210);
57 static_assert(d == 106);
58 #endif
59
60 BOOST_CHECK_EQUAL(b, non_constexpr_invoke(test_constexpr_bitwise<int_backend>, a));
61 BOOST_CHECK_EQUAL(d, non_constexpr_invoke(test_constexpr_bitwise<unsigned_backend>, c));
62 }
63 {
64 constexpr int_backend a(22);
65 constexpr unsigned_backend c(22);
66 constexpr int_backend b = test_constexpr_logical(a);
67 constexpr unsigned_backend d = test_constexpr_logical(c);
68 #ifdef BOOST_HAS_INT128
69 //static_assert(b == 95);
70 //static_assert(d == 95);
71 #else
72 static_assert(b == 82);
73 static_assert(d == 82);
74 #endif
75 BOOST_CHECK_EQUAL(b, non_constexpr_invoke(test_constexpr_logical<int_backend>, a));
76 BOOST_CHECK_EQUAL(d, non_constexpr_invoke(test_constexpr_logical<unsigned_backend>, c));
77 }
78 {
79 constexpr int_backend a(22);
80 constexpr unsigned_backend c(22);
81 constexpr int_backend b = test_constexpr_compare(a);
82 constexpr unsigned_backend d = test_constexpr_compare(c);
83 #ifdef BOOST_HAS_INT128
84 static_assert(b == 95);
85 static_assert(d == 95);
86 #else
87 static_assert(b == 95);
88 static_assert(d == 95);
89 #endif
90 BOOST_CHECK_EQUAL(b, non_constexpr_invoke(test_constexpr_compare<int_backend>, a));
91 BOOST_CHECK_EQUAL(d, non_constexpr_invoke(test_constexpr_compare<unsigned_backend>, c));
92 }
93 return boost::report_errors();
94 }
95