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