]>
Commit | Line | Data |
---|---|---|
92f5a8d4 TL |
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 | #if !defined(BOOST_MP_NO_CONSTEXPR_DETECTION) && !defined(DISABLE_TESTS) | |
11 | ||
12 | template <class F, class V> | |
13 | decltype(std::declval<F>()(std::declval<V>())) non_constexpr_invoke(F f, V v) | |
14 | { | |
15 | return f(v); | |
16 | } | |
17 | ||
18 | int main() | |
19 | { | |
20 | typedef boost::multiprecision::int256_t int_backend; | |
21 | typedef boost::multiprecision::uint256_t unsigned_backend; | |
22 | ||
23 | { | |
24 | constexpr int_backend a(22); | |
25 | constexpr unsigned_backend c(22); | |
26 | constexpr int_backend b = test_constexpr_add_subtract(a); | |
27 | constexpr unsigned_backend d = test_constexpr_add_subtract(c); | |
28 | ||
29 | constexpr long long llv = (long long)b; | |
30 | ||
31 | static_assert(b == -108); | |
32 | static_assert(d == 554); | |
f67539c2 | 33 | static_assert(llv == -108); |
92f5a8d4 TL |
34 | |
35 | BOOST_CHECK_EQUAL(b, non_constexpr_invoke(test_constexpr_add_subtract<int_backend>, a)); | |
36 | BOOST_CHECK_EQUAL(d, non_constexpr_invoke(test_constexpr_add_subtract<unsigned_backend>, c)); | |
37 | } | |
38 | { | |
39 | constexpr int_backend a(22); | |
40 | constexpr unsigned_backend c(22); | |
41 | constexpr int_backend b = test_constexpr_mul_divide(a); | |
42 | constexpr unsigned_backend d = test_constexpr_mul_divide(c); | |
43 | static_assert(b == 22); | |
44 | static_assert(d == 22); | |
45 | ||
46 | BOOST_CHECK_EQUAL(b, non_constexpr_invoke(test_constexpr_mul_divide<int_backend>, a)); | |
47 | BOOST_CHECK_EQUAL(d, non_constexpr_invoke(test_constexpr_mul_divide<unsigned_backend>, c)); | |
48 | } | |
49 | { | |
50 | constexpr int_backend a(22); | |
51 | constexpr unsigned_backend c(22); | |
52 | constexpr int_backend b = test_constexpr_bitwise(a); | |
53 | constexpr unsigned_backend d = test_constexpr_bitwise(c); | |
54 | #ifdef BOOST_HAS_INT128 | |
55 | static_assert(b == 230); | |
56 | static_assert(d == 120); | |
57 | #else | |
58 | static_assert(b == 210); | |
59 | static_assert(d == 106); | |
60 | #endif | |
61 | ||
62 | BOOST_CHECK_EQUAL(b, non_constexpr_invoke(test_constexpr_bitwise<int_backend>, a)); | |
63 | BOOST_CHECK_EQUAL(d, non_constexpr_invoke(test_constexpr_bitwise<unsigned_backend>, c)); | |
64 | } | |
65 | { | |
66 | constexpr int_backend a(22); | |
67 | constexpr unsigned_backend c(22); | |
68 | constexpr int_backend b = test_constexpr_logical(a); | |
69 | constexpr unsigned_backend d = test_constexpr_logical(c); | |
70 | #ifdef BOOST_HAS_INT128 | |
71 | //static_assert(b == 95); | |
72 | //static_assert(d == 95); | |
73 | #else | |
74 | static_assert(b == 82); | |
75 | static_assert(d == 82); | |
76 | #endif | |
77 | BOOST_CHECK_EQUAL(b, non_constexpr_invoke(test_constexpr_logical<int_backend>, a)); | |
78 | BOOST_CHECK_EQUAL(d, non_constexpr_invoke(test_constexpr_logical<unsigned_backend>, c)); | |
79 | } | |
80 | { | |
81 | constexpr int_backend a(22); | |
82 | constexpr unsigned_backend c(22); | |
83 | constexpr int_backend b = test_constexpr_compare(a); | |
84 | constexpr unsigned_backend d = test_constexpr_compare(c); | |
85 | #ifdef BOOST_HAS_INT128 | |
86 | static_assert(b == 95); | |
87 | static_assert(d == 95); | |
88 | #else | |
89 | static_assert(b == 95); | |
90 | static_assert(d == 95); | |
91 | #endif | |
92 | BOOST_CHECK_EQUAL(b, non_constexpr_invoke(test_constexpr_compare<int_backend>, a)); | |
93 | BOOST_CHECK_EQUAL(d, non_constexpr_invoke(test_constexpr_compare<unsigned_backend>, c)); | |
94 | } | |
95 | return boost::report_errors(); | |
96 | } | |
97 | #else | |
98 | int main() {} | |
99 | #endif | |
100 |