std_real_concept_check.cpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. // Copyright John Maddock 2006.
  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. #define BOOST_MATH_ASSERT_UNDEFINED_POLICY false
  6. #include "poison.hpp"
  7. #include <boost/math/concepts/std_real_concept.hpp>
  8. #include <boost/math/concepts/distributions.hpp>
  9. #include "instantiate.hpp"
  10. //
  11. // The purpose of this test is to verify that our code compiles
  12. // cleanly with a type whose std lib functions are in namespace
  13. // std and can *not* be found by ADL. This verifies that we're
  14. // not finding std lib functions that are in the global namespace
  15. // for example calling ::pow(double) rather than std::pow(long double).
  16. // This is a silent error that does the wrong thing at runtime, and
  17. // of course we can't call std::pow() directly because we want
  18. // the functions to be found by ADL when that's appropriate.
  19. //
  20. // Furthermore our code does different things internally depending
  21. // on numeric_limits<>::digits, so there are some macros that can
  22. // be defined that cause our concept-archetype to emulate various
  23. // floating point types:
  24. //
  25. // EMULATE32: 32-bit float
  26. // EMULATE64: 64-bit double
  27. // EMULATE80: 80-bit long double
  28. // EMULATE128: 128-bit long double
  29. //
  30. // In order to ensure total code coverage this file must be
  31. // compiled with each of the above macros in turn, and then
  32. // without any of the above as well!
  33. //
  34. #define NULL_MACRO /**/
  35. #ifdef EMULATE32
  36. namespace std{
  37. template<>
  38. struct numeric_limits<boost::math::concepts::std_real_concept>
  39. {
  40. static const bool is_specialized = true;
  41. static boost::math::concepts::std_real_concept min NULL_MACRO() throw();
  42. static boost::math::concepts::std_real_concept max NULL_MACRO() throw();
  43. static const int digits = 24;
  44. static const int digits10 = 6;
  45. static const int max_digits10 = 9;
  46. static const bool is_signed = true;
  47. static const bool is_integer = false;
  48. static const bool is_exact = false;
  49. static const int radix = 2;
  50. static boost::math::concepts::std_real_concept epsilon() throw();
  51. static boost::math::concepts::std_real_concept round_error() throw();
  52. static const int min_exponent = -125;
  53. static const int min_exponent10 = -37;
  54. static const int max_exponent = 128;
  55. static const int max_exponent10 = 38;
  56. static const bool has_infinity = true;
  57. static const bool has_quiet_NaN = true;
  58. static const bool has_signaling_NaN = true;
  59. static const float_denorm_style has_denorm = denorm_absent;
  60. static const bool has_denorm_loss = false;
  61. static boost::math::concepts::std_real_concept infinity() throw();
  62. static boost::math::concepts::std_real_concept quiet_NaN() throw();
  63. static boost::math::concepts::std_real_concept signaling_NaN() throw();
  64. static boost::math::concepts::std_real_concept denorm_min() throw();
  65. static const bool is_iec559 = true;
  66. static const bool is_bounded = false;
  67. static const bool is_modulo = false;
  68. static const bool traps = false;
  69. static const bool tinyness_before = false;
  70. static const float_round_style round_style = round_toward_zero;
  71. };
  72. }
  73. #endif
  74. #ifdef EMULATE64
  75. namespace std{
  76. template<>
  77. struct numeric_limits<boost::math::concepts::std_real_concept>
  78. {
  79. static const bool is_specialized = true;
  80. static boost::math::concepts::std_real_concept min NULL_MACRO() throw();
  81. static boost::math::concepts::std_real_concept max NULL_MACRO() throw();
  82. static const int digits = 53;
  83. static const int digits10 = 15;
  84. static const int max_digits10 = 17;
  85. static const bool is_signed = true;
  86. static const bool is_integer = false;
  87. static const bool is_exact = false;
  88. static const int radix = 2;
  89. static boost::math::concepts::std_real_concept epsilon() throw();
  90. static boost::math::concepts::std_real_concept round_error() throw();
  91. static const int min_exponent = -1021;
  92. static const int min_exponent10 = -307;
  93. static const int max_exponent = 1024;
  94. static const int max_exponent10 = 308;
  95. static const bool has_infinity = true;
  96. static const bool has_quiet_NaN = true;
  97. static const bool has_signaling_NaN = true;
  98. static const float_denorm_style has_denorm = denorm_absent;
  99. static const bool has_denorm_loss = false;
  100. static boost::math::concepts::std_real_concept infinity() throw();
  101. static boost::math::concepts::std_real_concept quiet_NaN() throw();
  102. static boost::math::concepts::std_real_concept signaling_NaN() throw();
  103. static boost::math::concepts::std_real_concept denorm_min() throw();
  104. static const bool is_iec559 = true;
  105. static const bool is_bounded = false;
  106. static const bool is_modulo = false;
  107. static const bool traps = false;
  108. static const bool tinyness_before = false;
  109. static const float_round_style round_style = round_toward_zero;
  110. };
  111. }
  112. #endif
  113. #ifdef EMULATE80
  114. namespace std{
  115. template<>
  116. struct numeric_limits<boost::math::concepts::std_real_concept>
  117. {
  118. static const bool is_specialized = true;
  119. static boost::math::concepts::std_real_concept min NULL_MACRO() throw();
  120. static boost::math::concepts::std_real_concept max NULL_MACRO() throw();
  121. static const int digits = 64;
  122. static const int digits10 = 18;
  123. static const int max_digits10 = 22;
  124. static const bool is_signed = true;
  125. static const bool is_integer = false;
  126. static const bool is_exact = false;
  127. static const int radix = 2;
  128. static boost::math::concepts::std_real_concept epsilon() throw();
  129. static boost::math::concepts::std_real_concept round_error() throw();
  130. static const int min_exponent = -16381;
  131. static const int min_exponent10 = -4931;
  132. static const int max_exponent = 16384;
  133. static const int max_exponent10 = 4932;
  134. static const bool has_infinity = true;
  135. static const bool has_quiet_NaN = true;
  136. static const bool has_signaling_NaN = true;
  137. static const float_denorm_style has_denorm = denorm_absent;
  138. static const bool has_denorm_loss = false;
  139. static boost::math::concepts::std_real_concept infinity() throw();
  140. static boost::math::concepts::std_real_concept quiet_NaN() throw();
  141. static boost::math::concepts::std_real_concept signaling_NaN() throw();
  142. static boost::math::concepts::std_real_concept denorm_min() throw();
  143. static const bool is_iec559 = true;
  144. static const bool is_bounded = false;
  145. static const bool is_modulo = false;
  146. static const bool traps = false;
  147. static const bool tinyness_before = false;
  148. static const float_round_style round_style = round_toward_zero;
  149. };
  150. }
  151. #endif
  152. #ifdef EMULATE128
  153. namespace std{
  154. template<>
  155. struct numeric_limits<boost::math::concepts::std_real_concept>
  156. {
  157. static const bool is_specialized = true;
  158. static boost::math::concepts::std_real_concept min NULL_MACRO() throw();
  159. static boost::math::concepts::std_real_concept max NULL_MACRO() throw();
  160. static const int digits = 113;
  161. static const int digits10 = 33;
  162. static const int max_digits10 = 37;
  163. static const bool is_signed = true;
  164. static const bool is_integer = false;
  165. static const bool is_exact = false;
  166. static const int radix = 2;
  167. static boost::math::concepts::std_real_concept epsilon() throw();
  168. static boost::math::concepts::std_real_concept round_error() throw();
  169. static const int min_exponent = -16381;
  170. static const int min_exponent10 = -4931;
  171. static const int max_exponent = 16384;
  172. static const int max_exponent10 = 4932;
  173. static const bool has_infinity = true;
  174. static const bool has_quiet_NaN = true;
  175. static const bool has_signaling_NaN = true;
  176. static const float_denorm_style has_denorm = denorm_absent;
  177. static const bool has_denorm_loss = false;
  178. static boost::math::concepts::std_real_concept infinity() throw();
  179. static boost::math::concepts::std_real_concept quiet_NaN() throw();
  180. static boost::math::concepts::std_real_concept signaling_NaN() throw();
  181. static boost::math::concepts::std_real_concept denorm_min() throw();
  182. static const bool is_iec559 = true;
  183. static const bool is_bounded = false;
  184. static const bool is_modulo = false;
  185. static const bool traps = false;
  186. static const bool tinyness_before = false;
  187. static const float_round_style round_style = round_toward_zero;
  188. };
  189. }
  190. #endif
  191. int main(int argc, char*[])
  192. {
  193. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  194. if(argc > 1000)
  195. instantiate(boost::math::concepts::std_real_concept(0));
  196. #endif
  197. }