constexpr_test_arithmetic_backend.cpp 4.1 KB

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