test_gamma_hooks.hpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. // (C) 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. #ifndef BOOST_MATH_TEST_GAMMA_OTHER_HOOKS_HPP
  6. #define BOOST_MATH_TEST_GAMMA_OTHER_HOOKS_HPP
  7. #ifdef TEST_CEPHES
  8. namespace other{
  9. extern "C" {
  10. double gamma(double);
  11. float gammaf(float);
  12. long double gammal(long double);
  13. double lgam(double);
  14. float lgamf(float);
  15. long double lgaml(long double);
  16. float igamf(float, float);
  17. double igam(double, double);
  18. long double igaml(long double, long double);
  19. float igamcf(float, float);
  20. double igamc(double, double);
  21. long double igamcl(long double, long double);
  22. }
  23. inline float tgamma(float x)
  24. { return gammaf(x); }
  25. inline double tgamma(double x)
  26. { return gamma(x); }
  27. inline long double tgamma(long double x)
  28. {
  29. #ifdef BOOST_MSVC
  30. return gamma((double)x);
  31. #else
  32. return gammal(x);
  33. #endif
  34. }
  35. inline float lgamma(float x)
  36. { return lgamf(x); }
  37. inline double lgamma(double x)
  38. { return lgam(x); }
  39. inline long double lgamma(long double x)
  40. {
  41. #ifdef BOOST_MSVC
  42. return lgam((double)x);
  43. #else
  44. return lgaml(x);
  45. #endif
  46. }
  47. inline float gamma_q(float x, float y)
  48. { return igamcf(x, y); }
  49. inline double gamma_q(double x, double y)
  50. { return igamc(x, y); }
  51. inline long double gamma_q(long double x, long double y)
  52. {
  53. #ifdef BOOST_MSVC
  54. return igamc((double)x, (double)y);
  55. #else
  56. return igamcl(x, y);
  57. #endif
  58. }
  59. inline float gamma_p(float x, float y)
  60. { return igamf(x, y); }
  61. inline double gamma_p(double x, double y)
  62. { return igam(x, y); }
  63. inline long double gamma_p(long double x, long double y)
  64. {
  65. #ifdef BOOST_MSVC
  66. return igam((double)x, (double)y);
  67. #else
  68. return igaml(x, y);
  69. #endif
  70. }
  71. }
  72. #define TEST_OTHER
  73. #endif
  74. #ifdef TEST_NATIVE
  75. #include <math.h>
  76. namespace other{
  77. #if defined(__FreeBSD__)
  78. // no float version:
  79. inline float tgamma(float x)
  80. { return ::tgamma(x); }
  81. #else
  82. inline float tgamma(float x)
  83. { return ::tgammaf(x); }
  84. #endif
  85. inline double tgamma(double x)
  86. { return ::tgamma(x); }
  87. inline long double tgamma(long double x)
  88. {
  89. #if defined(__CYGWIN__) || defined(__FreeBSD__)
  90. // no long double versions:
  91. return ::tgamma(x);
  92. #else
  93. return ::tgammal(x);
  94. #endif
  95. }
  96. #if defined(__FreeBSD__)
  97. inline float lgamma(float x)
  98. { return ::lgamma(x); }
  99. #else
  100. inline float lgamma(float x)
  101. { return ::lgammaf(x); }
  102. #endif
  103. inline double lgamma(double x)
  104. { return ::lgamma(x); }
  105. inline long double lgamma(long double x)
  106. {
  107. #if defined(__CYGWIN__) || defined(__FreeBSD__)
  108. // no long double versions:
  109. return ::lgamma(x);
  110. #else
  111. return ::lgammal(x);
  112. #endif
  113. }
  114. }
  115. #define TEST_OTHER
  116. #endif
  117. #ifdef TEST_GSL
  118. #define TEST_OTHER
  119. #include <gsl/gsl_sf_gamma.h>
  120. namespace other{
  121. float tgamma(float z)
  122. {
  123. return (float)gsl_sf_gamma(z);
  124. }
  125. double tgamma(double z)
  126. {
  127. return gsl_sf_gamma(z);
  128. }
  129. long double tgamma(long double z)
  130. {
  131. return gsl_sf_gamma(z);
  132. }
  133. float lgamma(float z)
  134. {
  135. return (float)gsl_sf_lngamma(z);
  136. }
  137. double lgamma(double z)
  138. {
  139. return gsl_sf_lngamma(z);
  140. }
  141. long double lgamma(long double z)
  142. {
  143. return gsl_sf_lngamma(z);
  144. }
  145. inline float gamma_q(float x, float y)
  146. { return (float)gsl_sf_gamma_inc_Q(x, y); }
  147. inline double gamma_q(double x, double y)
  148. { return gsl_sf_gamma_inc_Q(x, y); }
  149. inline long double gamma_q(long double x, long double y)
  150. { return gsl_sf_gamma_inc_Q(x, y); }
  151. inline float gamma_p(float x, float y)
  152. { return (float)gsl_sf_gamma_inc_P(x, y); }
  153. inline double gamma_p(double x, double y)
  154. { return gsl_sf_gamma_inc_P(x, y); }
  155. inline long double gamma_p(long double x, long double y)
  156. { return gsl_sf_gamma_inc_P(x, y); }
  157. }
  158. #endif
  159. #ifdef TEST_DCDFLIB
  160. #define TEST_OTHER
  161. #include <dcdflib.h>
  162. namespace other{
  163. float tgamma(float z)
  164. {
  165. double v = z;
  166. return (float)gamma_x(&v);
  167. }
  168. double tgamma(double z)
  169. {
  170. return gamma_x(&z);
  171. }
  172. long double tgamma(long double z)
  173. {
  174. double v = z;
  175. return gamma_x(&v);
  176. }
  177. float lgamma(float z)
  178. {
  179. double v = z;
  180. return (float)gamma_log(&v);
  181. }
  182. double lgamma(double z)
  183. {
  184. double v = z;
  185. return gamma_log(&v);
  186. }
  187. long double lgamma(long double z)
  188. {
  189. double v = z;
  190. return gamma_log(&v);
  191. }
  192. inline double gamma_q(double x, double y)
  193. {
  194. double ans, qans;
  195. int i = 0;
  196. gamma_inc (&x, &y, &ans, &qans, &i);
  197. return qans;
  198. }
  199. inline float gamma_q(float x, float y)
  200. {
  201. return (float)gamma_q((double)x, (double)y);
  202. }
  203. inline long double gamma_q(long double x, long double y)
  204. {
  205. return gamma_q((double)x, (double)y);
  206. }
  207. inline double gamma_p(double x, double y)
  208. {
  209. double ans, qans;
  210. int i = 0;
  211. gamma_inc (&x, &y, &ans, &qans, &i);
  212. return ans;
  213. }
  214. inline float gamma_p(float x, float y)
  215. {
  216. return (float)gamma_p((double)x, (double)y);
  217. }
  218. inline long double gamma_p(long double x, long double y)
  219. {
  220. return gamma_p((double)x, (double)y);
  221. }
  222. inline double gamma_q_inv(double x, double y)
  223. {
  224. double ans, p, nul;
  225. int i = 0;
  226. p = 1 - y;
  227. nul = 0;
  228. gamma_inc_inv (&x, &ans, &nul, &p, &y, &i);
  229. return ans;
  230. }
  231. inline float gamma_q_inv(float x, float y)
  232. {
  233. return (float)gamma_q_inv((double)x, (double)y);
  234. }
  235. inline long double gamma_q_inv(long double x, long double y)
  236. {
  237. return gamma_q_inv((double)x, (double)y);
  238. }
  239. inline double gamma_p_inv(double x, double y)
  240. {
  241. double ans, p, nul;
  242. int i = 0;
  243. p = 1 - y;
  244. nul = 0;
  245. gamma_inc_inv (&x, &ans, &nul, &y, &p, &i);
  246. return ans;
  247. }
  248. inline float gamma_p_inv(float x, float y)
  249. {
  250. return (float)gamma_p_inv((double)x, (double)y);
  251. }
  252. inline long double gamma_p_inv(long double x, long double y)
  253. {
  254. return gamma_p_inv((double)x, (double)y);
  255. }
  256. }
  257. #endif
  258. #ifdef TEST_OTHER
  259. namespace other{
  260. boost::math::concepts::real_concept tgamma(boost::math::concepts::real_concept){ return 0; }
  261. boost::math::concepts::real_concept lgamma(boost::math::concepts::real_concept){ return 0; }
  262. boost::math::concepts::real_concept gamma_q(boost::math::concepts::real_concept, boost::math::concepts::real_concept){ return 0; }
  263. boost::math::concepts::real_concept gamma_p(boost::math::concepts::real_concept, boost::math::concepts::real_concept){ return 0; }
  264. boost::math::concepts::real_concept gamma_p_inv(boost::math::concepts::real_concept x, boost::math::concepts::real_concept y){ return 0; }
  265. boost::math::concepts::real_concept gamma_q_inv(boost::math::concepts::real_concept x, boost::math::concepts::real_concept y){ return 0; }
  266. }
  267. #endif
  268. #endif