quaternion_constexpr_test.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. // test file for quaternion.hpp
  2. // (C) Copyright Hubert Holin 2001.
  3. // Distributed under the Boost Software License, Version 1.0. (See
  4. // accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. #include <boost/math/quaternion.hpp>
  7. typedef boost::math::quaternion<double> qt;
  8. typedef std::complex<double> ct;
  9. #ifndef BOOST_NO_CXX14_CONSTEXPR
  10. constexpr qt full_constexpr_test(qt a, qt b, double d, ct c)
  11. {
  12. a.swap(b);
  13. qt result(a), t;
  14. result += d;
  15. result += c;
  16. result += b;
  17. t = result;
  18. t = d;
  19. t = c;
  20. result -= d;
  21. result -= c;
  22. result -= a;
  23. result *= d;
  24. result *= c;
  25. result *= a;
  26. result /= d;
  27. result /= c;
  28. result /= b;
  29. result += a + d;
  30. result += d + a;
  31. result += a + c;
  32. result += c + a;
  33. result += a + b;
  34. result += a - d;
  35. result += d - a;
  36. result += a - c;
  37. result += c - a;
  38. result += a - b;
  39. result += a * d;
  40. result += d * a;
  41. result += a * c;
  42. result += c * a;
  43. result += a * b;
  44. result += a / d;
  45. result += d / a;
  46. result += a / c;
  47. result += c / a;
  48. result += a / b;
  49. result += norm(a);
  50. result += conj(a);
  51. return result;
  52. }
  53. #endif
  54. int main()
  55. {
  56. #ifndef BOOST_NO_CXX11_CONSTEXPR
  57. constexpr qt q1;
  58. constexpr qt q2(2.0);
  59. constexpr qt q3(2.0, 3.0);
  60. constexpr qt q4(2.0, 3.9, 3.0);
  61. constexpr qt q5(2.0, 3.9, 3.0, 5.);
  62. constexpr ct c1(2., 3.);
  63. constexpr qt q6(c1);
  64. constexpr qt q7(c1, c1);
  65. constexpr qt q8(q1);
  66. constexpr double d1 = q5.real();
  67. constexpr qt q9 = q1.unreal();
  68. constexpr double d2 = q1.R_component_1();
  69. constexpr double d3 = q1.R_component_2();
  70. constexpr double d4 = q1.R_component_3();
  71. constexpr double d5 = q1.R_component_4();
  72. constexpr ct c2 = q1.C_component_1();
  73. constexpr ct c3 = q1.C_component_1();
  74. constexpr qt q10 = q1 + d1;
  75. constexpr qt q11 = d1 + q1;
  76. constexpr qt q12 = c2 + q1;
  77. constexpr qt q13 = q1 + c2;
  78. constexpr qt q14 = q1 + q2;
  79. constexpr qt q15 = q1 - d1;
  80. constexpr qt q16 = d1 - q1;
  81. constexpr qt q17 = c2 - q1;
  82. constexpr qt q18 = q1 - c2;
  83. constexpr qt q19 = q1 - q2;
  84. constexpr qt q20 = q1 * d1;
  85. constexpr qt q21 = d1 * q1;
  86. constexpr qt q22 = q5 / d1;
  87. constexpr double d6 = real(q5);
  88. constexpr qt q23 = unreal(q1);
  89. constexpr bool b1 = q1 == d1;
  90. constexpr bool b2 = d1 == q1;
  91. constexpr bool b3 = q1 != d1;
  92. constexpr bool b4 = d1 != q1;
  93. constexpr bool b5 = q1 == c2;
  94. constexpr bool b6 = c2 == q1;
  95. constexpr bool b7 = q1 != c2;
  96. constexpr bool b8 = c2 != q1;
  97. constexpr bool b9 = q2 == q1;
  98. constexpr bool b10 = q1 != q2;
  99. (void)q9;
  100. (void)d2;
  101. (void)d3;
  102. (void)d4;
  103. (void)d6;
  104. (void)d5;
  105. (void)c3;
  106. (void)q10;
  107. (void)q11;
  108. (void)q12;
  109. (void)q13;
  110. (void)q14;
  111. (void)q15;
  112. (void)q16;
  113. (void)q17;
  114. (void)q18;
  115. (void)q19;
  116. (void)q20;
  117. (void)q21;
  118. (void)q22;
  119. (void)q23;
  120. (void)b1;
  121. (void)b2;
  122. (void)b3;
  123. (void)b4;
  124. (void)b5;
  125. (void)b6;
  126. (void)b7;
  127. (void)b8;
  128. (void)b9;
  129. (void)b10;
  130. #endif
  131. #ifndef BOOST_NO_CXX14_CONSTEXPR
  132. constexpr qt q24 = full_constexpr_test(q5, q5 + 1, 3.2, q5.C_component_1());
  133. (void)q24;
  134. #endif
  135. return 0;
  136. }