sf_concept_check_basic.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. // Copyright John Maddock 2012.
  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. // This tests that cpp_dec_float_50 meets our
  7. // conceptual requirements when used with Boost.Math.
  8. //
  9. #ifdef _MSC_VER
  10. #define _SCL_SECURE_NO_WARNINGS
  11. #pragma warning(disable : 4800)
  12. #pragma warning(disable : 4512)
  13. #pragma warning(disable : 4127)
  14. #pragma warning(disable : 4512)
  15. #pragma warning(disable : 4503) // decorated name length exceeded, name was truncated
  16. #endif
  17. #include <boost/container_hash/hash.hpp>
  18. #include <libs/math/test/compile_test/poison.hpp>
  19. #if !defined(TEST_MPF_50) && !defined(TEST_BACKEND) && !defined(TEST_MPZ) && !defined(TEST_CPP_DEC_FLOAT) && !defined(TEST_MPFR_50) && !defined(TEST_MPFR_6) && !defined(TEST_MPFR_15) && !defined(TEST_MPFR_17) && !defined(TEST_MPFR_30) && !defined(TEST_CPP_DEC_FLOAT_NO_ET) && !defined(TEST_LOGGED_ADAPTER) && !defined(TEST_CPP_BIN_FLOAT)
  20. #define TEST_MPF_50
  21. #define TEST_BACKEND
  22. #define TEST_MPZ
  23. #define TEST_MPFR_50
  24. #define TEST_MPFR_6
  25. #define TEST_MPFR_15
  26. #define TEST_MPFR_17
  27. #define TEST_MPFR_30
  28. #define TEST_CPP_DEC_FLOAT
  29. #define TEST_CPP_DEC_FLOAT_NO_ET
  30. #define TEST_LOGGED_ADAPTER
  31. #define TEST_CPP_BIN_FLOAT
  32. #ifdef _MSC_VER
  33. #pragma message("CAUTION!!: No backend type specified so testing everything.... this will take some time!!")
  34. #endif
  35. #ifdef __GNUC__
  36. #pragma warning "CAUTION!!: No backend type specified so testing everything.... this will take some time!!"
  37. #endif
  38. #endif
  39. #if defined(TEST_MPF_50) || defined(TEST_MPZ)
  40. #include <boost/multiprecision/gmp.hpp>
  41. #endif
  42. #ifdef TEST_BACKEND
  43. #include <boost/multiprecision/concepts/mp_number_archetypes.hpp>
  44. #endif
  45. #if defined(TEST_CPP_DEC_FLOAT) || defined(TEST_CPP_DEC_FLOAT_NO_ET) || defined(TEST_LOGGED_ADAPTER)
  46. #include <boost/multiprecision/cpp_dec_float.hpp>
  47. #endif
  48. #if defined(TEST_CPP_BIN_FLOAT)
  49. #include <boost/multiprecision/cpp_bin_float.hpp>
  50. #endif
  51. #if defined(TEST_MPFR_50) || defined(TEST_MPFR_6) || defined(TEST_MPFR_15) || defined(TEST_MPFR_17) || defined(TEST_MPFR_30)
  52. #include <boost/multiprecision/mpfr.hpp>
  53. #endif
  54. #ifdef TEST_LOGGED_ADAPTER
  55. #include <boost/multiprecision/logged_adaptor.hpp>
  56. #endif
  57. #include <boost/math/special_functions.hpp>
  58. template <class T>
  59. void test_extra(T)
  60. {
  61. T v1, v2, v3;
  62. int i;
  63. (boost::math::fpclassify)(v1);
  64. (boost::math::isfinite)(v1);
  65. (boost::math::isnormal)(v1);
  66. (boost::math::isnan)(v1);
  67. (boost::math::isinf)(v1);
  68. (boost::math::signbit)(v1);
  69. (boost::math::copysign)(v1, v2);
  70. (boost::math::changesign)(v1);
  71. (boost::math::sign)(v1);
  72. boost::math::log1p(v1);
  73. boost::math::expm1(v1);
  74. boost::math::cbrt(v1);
  75. boost::math::sqrt1pm1(v1);
  76. boost::math::powm1(v1, v2);
  77. boost::math::hypot(v1, v2);
  78. boost::math::sinc_pi(v1);
  79. boost::math::sinhc_pi(v1);
  80. boost::math::asinh(v1);
  81. boost::math::acosh(v1);
  82. boost::math::atanh(v1);
  83. boost::math::sin_pi(v1);
  84. boost::math::cos_pi(v1);
  85. boost::math::trunc(v1);
  86. boost::math::itrunc(v1);
  87. boost::math::ltrunc(v1);
  88. boost::math::round(v1);
  89. boost::math::iround(v1);
  90. boost::math::lround(v1);
  91. boost::math::modf(v1, &v1);
  92. boost::math::modf(v1, &i);
  93. long l;
  94. boost::math::modf(v1, &l);
  95. #ifdef BOOST_HAS_LONG_LONG
  96. boost::math::lltrunc(v1);
  97. boost::math::llround(v1);
  98. boost::long_long_type ll;
  99. boost::math::modf(v1, &ll);
  100. #endif
  101. boost::math::pow<2>(v1);
  102. boost::math::nextafter(v1, v1);
  103. boost::math::float_next(v1);
  104. boost::math::float_prior(v1);
  105. boost::math::float_distance(v1, v1);
  106. // Misc functions that don't fit elsewhere:
  107. boost::math::expint(v1);
  108. boost::math::expint(i);
  109. boost::math::expint(i, v2);
  110. boost::math::expint(i, i);
  111. boost::math::zeta(v1);
  112. boost::math::zeta(i);
  113. boost::math::owens_t(v1, v2);
  114. }
  115. void foo()
  116. {
  117. #ifdef TEST_BACKEND
  118. test_extra(boost::multiprecision::concepts::mp_number_float_architype());
  119. #endif
  120. #ifdef TEST_MPF_50
  121. test_extra(boost::multiprecision::mpf_float_50());
  122. #endif
  123. #ifdef TEST_MPFR_50
  124. test_extra(boost::multiprecision::mpfr_float_50());
  125. #endif
  126. #ifdef TEST_MPFR_6
  127. test_extra(boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<6> >());
  128. #endif
  129. #ifdef TEST_MPFR_15
  130. test_extra(boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<15> >());
  131. #endif
  132. #ifdef TEST_MPFR_17
  133. test_extra(boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<17> >());
  134. #endif
  135. #ifdef TEST_MPFR_30
  136. test_extra(boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<30> >());
  137. #endif
  138. #ifdef TEST_CPP_DEC_FLOAT
  139. test_extra(boost::multiprecision::cpp_dec_float_50());
  140. #endif
  141. #ifdef TEST_CPP_BIN_FLOAT
  142. test_extra(boost::multiprecision::cpp_bin_float_50());
  143. #endif
  144. #ifdef TEST_CPP_DEC_FLOAT_NO_ET
  145. test_extra(boost::multiprecision::number<boost::multiprecision::cpp_dec_float<100>, boost::multiprecision::et_off>());
  146. #endif
  147. #ifdef TEST_LOGGED_ADAPTER
  148. typedef boost::multiprecision::number<boost::multiprecision::logged_adaptor<boost::multiprecision::cpp_dec_float<50> > > num_t;
  149. test_extra(num_t());
  150. #endif
  151. }
  152. int main()
  153. {
  154. foo();
  155. }