• 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 "constexpr_arithmetric_test.hpp"
7 #include "../performance/arithmetic_backend.hpp"
8 
main()9 int main()
10 {
11    typedef boost::multiprecision::number<boost::multiprecision::backends::arithmetic_backend<long long>, boost::multiprecision::et_off>          int_backend;
12    typedef boost::multiprecision::number<boost::multiprecision::backends::arithmetic_backend<unsigned long long>, boost::multiprecision::et_off> unsigned_backend;
13 
14    typedef boost::multiprecision::number<boost::multiprecision::backends::arithmetic_backend<long long>, boost::multiprecision::et_on>          int_backend_et;
15    typedef boost::multiprecision::number<boost::multiprecision::backends::arithmetic_backend<unsigned long long>, boost::multiprecision::et_on> unsigned_backend_et;
16 
17    {
18       constexpr int_backend a(22);
19       constexpr unsigned_backend c(22);
20       constexpr int_backend b      = test_constexpr_add_subtract(a);
21       constexpr unsigned_backend d = test_constexpr_add_subtract(c);
22 
23       constexpr long long llv = (long long)b;
24 
25       static_assert(b == -108);
26       static_assert(llv == -108);
27       static_assert(d == 554);
28    }
29    {
30       constexpr int_backend a(22);
31       constexpr unsigned_backend c(22);
32       constexpr int_backend b      = test_constexpr_mul_divide(a);
33       constexpr unsigned_backend d = test_constexpr_mul_divide(c);
34       static_assert(b == 22);
35       static_assert(d == 22);
36    }
37    {
38       constexpr int_backend a(22);
39       constexpr unsigned_backend c(22);
40       constexpr int_backend b      = test_constexpr_bitwise(a);
41       constexpr unsigned_backend d = test_constexpr_bitwise(c);
42 #ifdef BOOST_HAS_INT128
43       static_assert(b == 230);
44       static_assert(d == 120);
45 #else
46       static_assert(b == 210);
47       static_assert(d == 106);
48 #endif
49    }
50    {
51       constexpr int_backend a(22);
52       constexpr unsigned_backend c(22);
53       constexpr int_backend b      = test_constexpr_logical(a);
54       constexpr unsigned_backend d = test_constexpr_logical(c);
55       static_assert(b == 82);
56       static_assert(d == 82);
57    }
58    {
59       constexpr int_backend a(22);
60       constexpr unsigned_backend c(22);
61       constexpr int_backend b      = test_constexpr_compare(a);
62       constexpr unsigned_backend d = test_constexpr_compare(c);
63       static_assert(b == 95);
64       static_assert(d == 95);
65    }
66    //
67    // Over again with expression templates turned on:
68    //
69    {
70       constexpr int_backend_et a(22);
71       constexpr unsigned_backend_et c(22);
72       constexpr int_backend_et b      = test_constexpr_add_subtract(a);
73       constexpr unsigned_backend_et d = test_constexpr_add_subtract(c);
74 
75       static_assert(b == -108);
76       static_assert(d == 554);
77    }
78    {
79       constexpr int_backend_et a(22);
80       constexpr unsigned_backend_et c(22);
81       constexpr int_backend_et b      = test_constexpr_mul_divide(a);
82       constexpr unsigned_backend_et d = test_constexpr_mul_divide(c);
83       static_assert(b == 22);
84       static_assert(d == 22);
85    }
86    {
87       constexpr int_backend_et a(22);
88       constexpr unsigned_backend_et c(22);
89       constexpr int_backend_et b      = test_constexpr_bitwise(a);
90       constexpr unsigned_backend_et d = test_constexpr_bitwise(c);
91 #ifdef BOOST_HAS_INT128
92       static_assert(b == 230);
93       static_assert(d == 120);
94 #else
95       static_assert(b == 210);
96       static_assert(d == 106);
97 #endif
98    }
99    {
100       constexpr int_backend_et a(22);
101       constexpr unsigned_backend_et c(22);
102       constexpr int_backend_et b      = test_constexpr_logical(a);
103       constexpr unsigned_backend_et d = test_constexpr_logical(c);
104       static_assert(b == 82);
105       static_assert(d == 82);
106    }
107    {
108       constexpr int_backend_et a(22);
109       constexpr unsigned_backend_et c(22);
110       constexpr int_backend_et b      = test_constexpr_compare(a);
111       constexpr unsigned_backend_et d = test_constexpr_compare(c);
112       static_assert(b == 95);
113       static_assert(d == 95);
114    }
115    std::cout << "Done!" << std::endl;
116 }
117