• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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>
non_constexpr_invoke(F f,V v)15 decltype(std::declval<F>()(std::declval<V>())) non_constexpr_invoke(F f, V v)
16 {
17    return f(v);
18 }
19 
main()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       static_assert(llv == -108);
36 
37       BOOST_CHECK_EQUAL(b, non_constexpr_invoke(test_constexpr_add_subtract<int_backend>, a));
38       BOOST_CHECK_EQUAL(d, non_constexpr_invoke(test_constexpr_add_subtract<unsigned_backend>, c));
39    }
40    {
41       constexpr int_backend a(22);
42       constexpr unsigned_backend c(22);
43       constexpr int_backend b      = test_constexpr_mul_divide(a);
44       constexpr unsigned_backend d = test_constexpr_mul_divide(c);
45       static_assert(b == 22);
46       static_assert(d == 22);
47 
48       BOOST_CHECK_EQUAL(b, non_constexpr_invoke(test_constexpr_mul_divide<int_backend>, a));
49       BOOST_CHECK_EQUAL(d, non_constexpr_invoke(test_constexpr_mul_divide<unsigned_backend>, c));
50    }
51    {
52       constexpr int_backend a(22);
53       constexpr unsigned_backend c(22);
54       constexpr int_backend b      = test_constexpr_bitwise(a);
55       constexpr unsigned_backend d = test_constexpr_bitwise(c);
56 #ifdef BOOST_HAS_INT128
57       static_assert(b == 230);
58       static_assert(d == 120);
59 #else
60       static_assert(b == 210);
61       static_assert(d == 106);
62 #endif
63 
64       BOOST_CHECK_EQUAL(b, non_constexpr_invoke(test_constexpr_bitwise<int_backend>, a));
65       BOOST_CHECK_EQUAL(d, non_constexpr_invoke(test_constexpr_bitwise<unsigned_backend>, c));
66    }
67    {
68       constexpr int_backend a(22);
69       constexpr unsigned_backend c(22);
70       constexpr int_backend b = test_constexpr_logical(a);
71       constexpr unsigned_backend d = test_constexpr_logical(c);
72 #ifdef BOOST_HAS_INT128
73       //static_assert(b == 95);
74       //static_assert(d == 95);
75 #else
76       static_assert(b == 82);
77       static_assert(d == 82);
78 #endif
79       BOOST_CHECK_EQUAL(b, non_constexpr_invoke(test_constexpr_logical<int_backend>, a));
80       BOOST_CHECK_EQUAL(d, non_constexpr_invoke(test_constexpr_logical<unsigned_backend>, c));
81    }
82    {
83       constexpr int_backend a(22);
84       constexpr unsigned_backend c(22);
85       constexpr int_backend b      = test_constexpr_compare(a);
86       constexpr unsigned_backend d = test_constexpr_compare(c);
87 #ifdef BOOST_HAS_INT128
88       static_assert(b == 95);
89       static_assert(d == 95);
90 #else
91       static_assert(b == 95);
92       static_assert(d == 95);
93 #endif
94       BOOST_CHECK_EQUAL(b, non_constexpr_invoke(test_constexpr_compare<int_backend>, a));
95       BOOST_CHECK_EQUAL(d, non_constexpr_invoke(test_constexpr_compare<unsigned_backend>, c));
96    }
97    return boost::report_errors();
98 }
99 #else
main()100 int main(){}
101 #endif
102 
103