number_concept_check.cpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. // Copyright John Maddock 2011.
  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.
  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/concepts/real_type_concept.hpp>
  58. template <class T>
  59. void test_extra(T)
  60. {
  61. T t = 1;
  62. t = abs(t);
  63. t = abs(t * t);
  64. t = fabs(t);
  65. t = fabs(t * t);
  66. t = sqrt(t);
  67. t = sqrt(t * t);
  68. t = floor(t);
  69. t = floor(t * t);
  70. t = ceil(t);
  71. t = ceil(t * t);
  72. t = trunc(t);
  73. t = trunc(t * t);
  74. t = round(t);
  75. t = round(t * t);
  76. t = exp(t);
  77. t = exp(t * t);
  78. t = log(t);
  79. t = log(t * t);
  80. t = log10(t);
  81. t = log10(t * t);
  82. t = cos(t);
  83. t = cos(t * t);
  84. t = sin(t);
  85. t = sin(t * t);
  86. t = tan(t);
  87. t = tan(t * t);
  88. t = asin(t);
  89. t = asin(t * t);
  90. t = atan(t);
  91. t = atan(t * t);
  92. t = acos(t);
  93. t = acos(t * t);
  94. t = cosh(t);
  95. t = cosh(t * t);
  96. t = sinh(t);
  97. t = sinh(t * t);
  98. t = tanh(t);
  99. t = tanh(t * t);
  100. double dval = 2;
  101. t = pow(t, t);
  102. t = pow(t, t * t);
  103. t = pow(t, dval);
  104. t = pow(t * t, t);
  105. t = pow(t * t, t * t);
  106. t = pow(t * t, dval);
  107. t = pow(dval, t);
  108. t = pow(dval, t * t);
  109. t = atan2(t, t);
  110. t = atan2(t, t * t);
  111. t = atan2(t, dval);
  112. t = atan2(t * t, t);
  113. t = atan2(t * t, t * t);
  114. t = atan2(t * t, dval);
  115. t = atan2(dval, t);
  116. t = atan2(dval, t * t);
  117. t = fmod(t, t);
  118. t = fmod(t, t * t);
  119. t = fmod(t, dval);
  120. t = fmod(t * t, t);
  121. t = fmod(t * t, t * t);
  122. t = fmod(t * t, dval);
  123. t = fmod(dval, t);
  124. t = fmod(dval, t * t);
  125. typedef typename T::backend_type backend_type;
  126. typedef typename backend_type::exponent_type exp_type;
  127. exp_type e = 0;
  128. int i = 0;
  129. t = ldexp(t, i);
  130. t = ldexp(t * t, i);
  131. t = ldexp(t, e);
  132. t = ldexp(t * t, e);
  133. t = frexp(t, &i);
  134. t = frexp(t * t, &i);
  135. t = frexp(t, &e);
  136. t = frexp(t * t, &e);
  137. t = scalbn(t, i);
  138. t = scalbn(t * t, i);
  139. t = scalbn(t, e);
  140. t = scalbn(t * t, e);
  141. t = logb(t);
  142. t = logb(t * t);
  143. e = ilogb(t);
  144. e = ilogb(t * t);
  145. }
  146. void foo()
  147. {
  148. #ifdef TEST_BACKEND
  149. test_extra(boost::multiprecision::concepts::mp_number_float_architype());
  150. #endif
  151. #ifdef TEST_MPF_50
  152. test_extra(boost::multiprecision::mpf_float_50());
  153. #endif
  154. #ifdef TEST_MPFR_50
  155. test_extra(boost::multiprecision::mpfr_float_50());
  156. #endif
  157. #ifdef TEST_MPFR_6
  158. test_extra(boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<6> >());
  159. #endif
  160. #ifdef TEST_MPFR_15
  161. test_extra(boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<15> >());
  162. #endif
  163. #ifdef TEST_MPFR_17
  164. test_extra(boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<17> >());
  165. #endif
  166. #ifdef TEST_MPFR_30
  167. test_extra(boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<30> >());
  168. #endif
  169. #ifdef TEST_CPP_DEC_FLOAT
  170. test_extra(boost::multiprecision::cpp_dec_float_50());
  171. #endif
  172. #ifdef TEST_CPP_BIN_FLOAT
  173. test_extra(boost::multiprecision::cpp_bin_float_50());
  174. #endif
  175. #ifdef TEST_CPP_DEC_FLOAT_NO_ET
  176. test_extra(boost::multiprecision::number<boost::multiprecision::cpp_dec_float<100>, boost::multiprecision::et_off>());
  177. #endif
  178. }
  179. int main()
  180. {
  181. #ifdef TEST_BACKEND
  182. BOOST_CONCEPT_ASSERT((boost::math::concepts::RealTypeConcept<boost::multiprecision::concepts::mp_number_float_architype>));
  183. #endif
  184. #ifdef TEST_MPF_50
  185. BOOST_CONCEPT_ASSERT((boost::math::concepts::RealTypeConcept<boost::multiprecision::mpf_float_50>));
  186. #endif
  187. #ifdef TEST_MPFR_50
  188. BOOST_CONCEPT_ASSERT((boost::math::concepts::RealTypeConcept<boost::multiprecision::mpfr_float_50>));
  189. #endif
  190. #ifdef TEST_MPFR_6
  191. BOOST_CONCEPT_ASSERT((boost::math::concepts::RealTypeConcept<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<6> > >));
  192. #endif
  193. #ifdef TEST_MPFR_15
  194. BOOST_CONCEPT_ASSERT((boost::math::concepts::RealTypeConcept<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<15> > >));
  195. #endif
  196. #ifdef TEST_MPFR_17
  197. BOOST_CONCEPT_ASSERT((boost::math::concepts::RealTypeConcept<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<17> > >));
  198. #endif
  199. #ifdef TEST_MPFR_30
  200. BOOST_CONCEPT_ASSERT((boost::math::concepts::RealTypeConcept<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<30> > >));
  201. #endif
  202. #ifdef TEST_MPFR_50
  203. BOOST_CONCEPT_ASSERT((boost::math::concepts::RealTypeConcept<boost::multiprecision::mpfr_float_50>));
  204. #endif
  205. #ifdef TEST_CPP_DEC_FLOAT
  206. BOOST_CONCEPT_ASSERT((boost::math::concepts::RealTypeConcept<boost::multiprecision::cpp_dec_float_50>));
  207. #endif
  208. #ifdef TEST_CPP_BIN_FLOAT
  209. BOOST_CONCEPT_ASSERT((boost::math::concepts::RealTypeConcept<boost::multiprecision::cpp_bin_float_50>));
  210. #endif
  211. #ifdef TEST_LOGGED_ADAPTER
  212. typedef boost::multiprecision::number<boost::multiprecision::logged_adaptor<boost::multiprecision::cpp_dec_float<50> > > num_t;
  213. test_extra(num_t());
  214. #endif
  215. }