cstdfloat_cmath.hpp 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Copyright Christopher Kormanyos 2014.
  3. // Copyright John Maddock 2014.
  4. // Copyright Paul Bristow 2014.
  5. // Distributed under the Boost Software License,
  6. // Version 1.0. (See accompanying file LICENSE_1_0.txt
  7. // or copy at http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // Implement quadruple-precision <cmath> support.
  10. #ifndef BOOST_MATH_CSTDFLOAT_CMATH_2014_02_15_HPP_
  11. #define BOOST_MATH_CSTDFLOAT_CMATH_2014_02_15_HPP_
  12. #include <boost/math/cstdfloat/cstdfloat_types.hpp>
  13. #include <boost/math/cstdfloat/cstdfloat_limits.hpp>
  14. #if defined(BOOST_CSTDFLOAT_HAS_INTERNAL_FLOAT128_T) && defined(BOOST_MATH_USE_FLOAT128) && !defined(BOOST_CSTDFLOAT_NO_LIBQUADMATH_SUPPORT)
  15. #include <cstdint>
  16. #include <cmath>
  17. #include <stdexcept>
  18. #include <iostream>
  19. #include <type_traits>
  20. #include <memory>
  21. #include <boost/math/tools/assert.hpp>
  22. #include <boost/math/tools/nothrow.hpp>
  23. #include <boost/math/tools/throw_exception.hpp>
  24. #if defined(_WIN32) && defined(__GNUC__)
  25. // Several versions of Mingw and probably cygwin too have broken
  26. // libquadmath implementations that segfault as soon as you call
  27. // expq or any function that depends on it.
  28. #define BOOST_CSTDFLOAT_BROKEN_FLOAT128_MATH_FUNCTIONS
  29. #endif
  30. // Here is a helper function used for raising the value of a given
  31. // floating-point type to the power of n, where n has integral type.
  32. namespace boost {
  33. namespace math {
  34. namespace cstdfloat {
  35. namespace detail {
  36. template<class float_type, class integer_type>
  37. inline float_type pown(const float_type& x, const integer_type p)
  38. {
  39. const bool isneg = (x < 0);
  40. const bool isnan = (x != x);
  41. const bool isinf = ((!isneg) ? bool(+x > (std::numeric_limits<float_type>::max)())
  42. : bool(-x > (std::numeric_limits<float_type>::max)()));
  43. if (isnan) { return x; }
  44. if (isinf) { return std::numeric_limits<float_type>::quiet_NaN(); }
  45. const bool x_is_neg = (x < 0);
  46. const float_type abs_x = (x_is_neg ? -x : x);
  47. if (p < static_cast<integer_type>(0))
  48. {
  49. if (abs_x < (std::numeric_limits<float_type>::min)())
  50. {
  51. return (x_is_neg ? -std::numeric_limits<float_type>::infinity()
  52. : +std::numeric_limits<float_type>::infinity());
  53. }
  54. else
  55. {
  56. return float_type(1) / pown(x, static_cast<integer_type>(-p));
  57. }
  58. }
  59. if (p == static_cast<integer_type>(0))
  60. {
  61. return float_type(1);
  62. }
  63. else
  64. {
  65. if (p == static_cast<integer_type>(1)) { return x; }
  66. if (abs_x > (std::numeric_limits<float_type>::max)())
  67. {
  68. return (x_is_neg ? -std::numeric_limits<float_type>::infinity()
  69. : +std::numeric_limits<float_type>::infinity());
  70. }
  71. if (p == static_cast<integer_type>(2)) { return (x * x); }
  72. else if (p == static_cast<integer_type>(3)) { return ((x * x) * x); }
  73. else if (p == static_cast<integer_type>(4)) { const float_type x2 = (x * x); return (x2 * x2); }
  74. else
  75. {
  76. // The variable xn stores the binary powers of x.
  77. float_type result(((p % integer_type(2)) != integer_type(0)) ? x : float_type(1));
  78. float_type xn(x);
  79. integer_type p2 = p;
  80. while (integer_type(p2 /= 2) != integer_type(0))
  81. {
  82. // Square xn for each binary power.
  83. xn *= xn;
  84. const bool has_binary_power = (integer_type(p2 % integer_type(2)) != integer_type(0));
  85. if (has_binary_power)
  86. {
  87. // Multiply the result with each binary power contained in the exponent.
  88. result *= xn;
  89. }
  90. }
  91. return result;
  92. }
  93. }
  94. }
  95. }
  96. }
  97. }
  98. } // boost::math::cstdfloat::detail
  99. // We will now define preprocessor symbols representing quadruple-precision <cmath> functions.
  100. #if defined(__INTEL_COMPILER)
  101. #define BOOST_CSTDFLOAT_FLOAT128_LDEXP __ldexpq
  102. #define BOOST_CSTDFLOAT_FLOAT128_FREXP __frexpq
  103. #define BOOST_CSTDFLOAT_FLOAT128_FABS __fabsq
  104. #define BOOST_CSTDFLOAT_FLOAT128_FLOOR __floorq
  105. #define BOOST_CSTDFLOAT_FLOAT128_CEIL __ceilq
  106. #if !defined(BOOST_CSTDFLOAT_FLOAT128_SQRT)
  107. #define BOOST_CSTDFLOAT_FLOAT128_SQRT __sqrtq
  108. #endif
  109. #define BOOST_CSTDFLOAT_FLOAT128_TRUNC __truncq
  110. #define BOOST_CSTDFLOAT_FLOAT128_EXP __expq
  111. #define BOOST_CSTDFLOAT_FLOAT128_EXPM1 __expm1q
  112. #define BOOST_CSTDFLOAT_FLOAT128_POW __powq
  113. #define BOOST_CSTDFLOAT_FLOAT128_LOG __logq
  114. #define BOOST_CSTDFLOAT_FLOAT128_LOG10 __log10q
  115. #define BOOST_CSTDFLOAT_FLOAT128_SIN __sinq
  116. #define BOOST_CSTDFLOAT_FLOAT128_COS __cosq
  117. #define BOOST_CSTDFLOAT_FLOAT128_TAN __tanq
  118. #define BOOST_CSTDFLOAT_FLOAT128_ASIN __asinq
  119. #define BOOST_CSTDFLOAT_FLOAT128_ACOS __acosq
  120. #define BOOST_CSTDFLOAT_FLOAT128_ATAN __atanq
  121. #define BOOST_CSTDFLOAT_FLOAT128_SINH __sinhq
  122. #define BOOST_CSTDFLOAT_FLOAT128_COSH __coshq
  123. #define BOOST_CSTDFLOAT_FLOAT128_TANH __tanhq
  124. #define BOOST_CSTDFLOAT_FLOAT128_ASINH __asinhq
  125. #define BOOST_CSTDFLOAT_FLOAT128_ACOSH __acoshq
  126. #define BOOST_CSTDFLOAT_FLOAT128_ATANH __atanhq
  127. #define BOOST_CSTDFLOAT_FLOAT128_FMOD __fmodq
  128. #define BOOST_CSTDFLOAT_FLOAT128_ATAN2 __atan2q
  129. #define BOOST_CSTDFLOAT_FLOAT128_LGAMMA __lgammaq
  130. #define BOOST_CSTDFLOAT_FLOAT128_TGAMMA __tgammaq
  131. // begin more functions
  132. #define BOOST_CSTDFLOAT_FLOAT128_REMAINDER __remainderq
  133. #define BOOST_CSTDFLOAT_FLOAT128_REMQUO __remquoq
  134. #define BOOST_CSTDFLOAT_FLOAT128_FMA __fmaq
  135. #define BOOST_CSTDFLOAT_FLOAT128_FMAX __fmaxq
  136. #define BOOST_CSTDFLOAT_FLOAT128_FMIN __fminq
  137. #define BOOST_CSTDFLOAT_FLOAT128_FDIM __fdimq
  138. #define BOOST_CSTDFLOAT_FLOAT128_NAN __nanq
  139. //#define BOOST_CSTDFLOAT_FLOAT128_EXP2 __exp2q
  140. #define BOOST_CSTDFLOAT_FLOAT128_LOG2 __log2q
  141. #define BOOST_CSTDFLOAT_FLOAT128_LOG1P __log1pq
  142. #define BOOST_CSTDFLOAT_FLOAT128_CBRT __cbrtq
  143. #define BOOST_CSTDFLOAT_FLOAT128_HYPOT __hypotq
  144. #define BOOST_CSTDFLOAT_FLOAT128_ERF __erfq
  145. #define BOOST_CSTDFLOAT_FLOAT128_ERFC __erfcq
  146. #define BOOST_CSTDFLOAT_FLOAT128_LLROUND __llroundq
  147. #define BOOST_CSTDFLOAT_FLOAT128_LROUND __lroundq
  148. #define BOOST_CSTDFLOAT_FLOAT128_ROUND __roundq
  149. #define BOOST_CSTDFLOAT_FLOAT128_NEARBYINT __nearbyintq
  150. #define BOOST_CSTDFLOAT_FLOAT128_LLRINT __llrintq
  151. #define BOOST_CSTDFLOAT_FLOAT128_LRINT __lrintq
  152. #define BOOST_CSTDFLOAT_FLOAT128_RINT __rintq
  153. #define BOOST_CSTDFLOAT_FLOAT128_MODF __modfq
  154. #define BOOST_CSTDFLOAT_FLOAT128_SCALBLN __scalblnq
  155. #define BOOST_CSTDFLOAT_FLOAT128_SCALBN __scalbnq
  156. #define BOOST_CSTDFLOAT_FLOAT128_ILOGB __ilogbq
  157. #define BOOST_CSTDFLOAT_FLOAT128_LOGB __logbq
  158. #define BOOST_CSTDFLOAT_FLOAT128_NEXTAFTER __nextafterq
  159. //#define BOOST_CSTDFLOAT_FLOAT128_NEXTTOWARD __nexttowardq
  160. #define BOOST_CSTDFLOAT_FLOAT128_COPYSIGN __copysignq
  161. #define BOOST_CSTDFLOAT_FLOAT128_SIGNBIT __signbitq
  162. //#define BOOST_CSTDFLOAT_FLOAT128_FPCLASSIFY __fpclassifyq
  163. //#define BOOST_CSTDFLOAT_FLOAT128_ISFINITE __isfiniteq
  164. #define BOOST_CSTDFLOAT_FLOAT128_ISINF __isinfq
  165. #define BOOST_CSTDFLOAT_FLOAT128_ISNAN __isnanq
  166. //#define BOOST_CSTDFLOAT_FLOAT128_ISNORMAL __isnormalq
  167. //#define BOOST_CSTDFLOAT_FLOAT128_ISGREATER __isgreaterq
  168. //#define BOOST_CSTDFLOAT_FLOAT128_ISGREATEREQUAL __isgreaterequalq
  169. //#define BOOST_CSTDFLOAT_FLOAT128_ISLESS __islessq
  170. //#define BOOST_CSTDFLOAT_FLOAT128_ISLESSEQUAL __islessequalq
  171. //#define BOOST_CSTDFLOAT_FLOAT128_ISLESSGREATER __islessgreaterq
  172. //#define BOOST_CSTDFLOAT_FLOAT128_ISUNORDERED __isunorderedq
  173. // end more functions
  174. #elif defined(__GNUC__)
  175. #define BOOST_CSTDFLOAT_FLOAT128_LDEXP ldexpq
  176. #define BOOST_CSTDFLOAT_FLOAT128_FREXP frexpq
  177. #define BOOST_CSTDFLOAT_FLOAT128_FABS fabsq
  178. #define BOOST_CSTDFLOAT_FLOAT128_FLOOR floorq
  179. #define BOOST_CSTDFLOAT_FLOAT128_CEIL ceilq
  180. #if !defined(BOOST_CSTDFLOAT_FLOAT128_SQRT)
  181. #define BOOST_CSTDFLOAT_FLOAT128_SQRT sqrtq
  182. #endif
  183. #define BOOST_CSTDFLOAT_FLOAT128_TRUNC truncq
  184. #define BOOST_CSTDFLOAT_FLOAT128_POW powq
  185. #define BOOST_CSTDFLOAT_FLOAT128_LOG logq
  186. #define BOOST_CSTDFLOAT_FLOAT128_LOG10 log10q
  187. #define BOOST_CSTDFLOAT_FLOAT128_SIN sinq
  188. #define BOOST_CSTDFLOAT_FLOAT128_COS cosq
  189. #define BOOST_CSTDFLOAT_FLOAT128_TAN tanq
  190. #define BOOST_CSTDFLOAT_FLOAT128_ASIN asinq
  191. #define BOOST_CSTDFLOAT_FLOAT128_ACOS acosq
  192. #define BOOST_CSTDFLOAT_FLOAT128_ATAN atanq
  193. #define BOOST_CSTDFLOAT_FLOAT128_FMOD fmodq
  194. #define BOOST_CSTDFLOAT_FLOAT128_ATAN2 atan2q
  195. #define BOOST_CSTDFLOAT_FLOAT128_LGAMMA lgammaq
  196. #if !defined(BOOST_CSTDFLOAT_BROKEN_FLOAT128_MATH_FUNCTIONS)
  197. #define BOOST_CSTDFLOAT_FLOAT128_EXP expq
  198. #define BOOST_CSTDFLOAT_FLOAT128_EXPM1 expm1q
  199. #define BOOST_CSTDFLOAT_FLOAT128_SINH sinhq
  200. #define BOOST_CSTDFLOAT_FLOAT128_COSH coshq
  201. #define BOOST_CSTDFLOAT_FLOAT128_TANH tanhq
  202. #define BOOST_CSTDFLOAT_FLOAT128_ASINH asinhq
  203. #define BOOST_CSTDFLOAT_FLOAT128_ACOSH acoshq
  204. #define BOOST_CSTDFLOAT_FLOAT128_ATANH atanhq
  205. #define BOOST_CSTDFLOAT_FLOAT128_TGAMMA tgammaq
  206. #else // BOOST_CSTDFLOAT_BROKEN_FLOAT128_MATH_FUNCTIONS
  207. #define BOOST_CSTDFLOAT_FLOAT128_EXP expq_patch
  208. #define BOOST_CSTDFLOAT_FLOAT128_SINH sinhq_patch
  209. #define BOOST_CSTDFLOAT_FLOAT128_COSH coshq_patch
  210. #define BOOST_CSTDFLOAT_FLOAT128_TANH tanhq_patch
  211. #define BOOST_CSTDFLOAT_FLOAT128_ASINH asinhq_patch
  212. #define BOOST_CSTDFLOAT_FLOAT128_ACOSH acoshq_patch
  213. #define BOOST_CSTDFLOAT_FLOAT128_ATANH atanhq_patch
  214. #define BOOST_CSTDFLOAT_FLOAT128_TGAMMA tgammaq_patch
  215. #endif // BOOST_CSTDFLOAT_BROKEN_FLOAT128_MATH_FUNCTIONS
  216. // begin more functions
  217. #define BOOST_CSTDFLOAT_FLOAT128_REMAINDER remainderq
  218. #define BOOST_CSTDFLOAT_FLOAT128_REMQUO remquoq
  219. #define BOOST_CSTDFLOAT_FLOAT128_FMA fmaq
  220. #define BOOST_CSTDFLOAT_FLOAT128_FMAX fmaxq
  221. #define BOOST_CSTDFLOAT_FLOAT128_FMIN fminq
  222. #define BOOST_CSTDFLOAT_FLOAT128_FDIM fdimq
  223. #define BOOST_CSTDFLOAT_FLOAT128_NAN nanq
  224. //#define BOOST_CSTDFLOAT_FLOAT128_EXP2 exp2q
  225. #define BOOST_CSTDFLOAT_FLOAT128_LOG2 log2q
  226. #define BOOST_CSTDFLOAT_FLOAT128_LOG1P log1pq
  227. #define BOOST_CSTDFLOAT_FLOAT128_CBRT cbrtq
  228. #define BOOST_CSTDFLOAT_FLOAT128_HYPOT hypotq
  229. #define BOOST_CSTDFLOAT_FLOAT128_ERF erfq
  230. #define BOOST_CSTDFLOAT_FLOAT128_ERFC erfcq
  231. #define BOOST_CSTDFLOAT_FLOAT128_LLROUND llroundq
  232. #define BOOST_CSTDFLOAT_FLOAT128_LROUND lroundq
  233. #define BOOST_CSTDFLOAT_FLOAT128_ROUND roundq
  234. #define BOOST_CSTDFLOAT_FLOAT128_NEARBYINT nearbyintq
  235. #define BOOST_CSTDFLOAT_FLOAT128_LLRINT llrintq
  236. #define BOOST_CSTDFLOAT_FLOAT128_LRINT lrintq
  237. #define BOOST_CSTDFLOAT_FLOAT128_RINT rintq
  238. #define BOOST_CSTDFLOAT_FLOAT128_MODF modfq
  239. #define BOOST_CSTDFLOAT_FLOAT128_SCALBLN scalblnq
  240. #define BOOST_CSTDFLOAT_FLOAT128_SCALBN scalbnq
  241. #define BOOST_CSTDFLOAT_FLOAT128_ILOGB ilogbq
  242. #define BOOST_CSTDFLOAT_FLOAT128_LOGB logbq
  243. #define BOOST_CSTDFLOAT_FLOAT128_NEXTAFTER nextafterq
  244. //#define BOOST_CSTDFLOAT_FLOAT128_NEXTTOWARD nexttowardq
  245. #define BOOST_CSTDFLOAT_FLOAT128_COPYSIGN copysignq
  246. #define BOOST_CSTDFLOAT_FLOAT128_SIGNBIT signbitq
  247. //#define BOOST_CSTDFLOAT_FLOAT128_FPCLASSIFY fpclassifyq
  248. //#define BOOST_CSTDFLOAT_FLOAT128_ISFINITE isfiniteq
  249. #define BOOST_CSTDFLOAT_FLOAT128_ISINF isinfq
  250. #define BOOST_CSTDFLOAT_FLOAT128_ISNAN isnanq
  251. //#define BOOST_CSTDFLOAT_FLOAT128_ISNORMAL isnormalq
  252. //#define BOOST_CSTDFLOAT_FLOAT128_ISGREATER isgreaterq
  253. //#define BOOST_CSTDFLOAT_FLOAT128_ISGREATEREQUAL isgreaterequalq
  254. //#define BOOST_CSTDFLOAT_FLOAT128_ISLESS islessq
  255. //#define BOOST_CSTDFLOAT_FLOAT128_ISLESSEQUAL islessequalq
  256. //#define BOOST_CSTDFLOAT_FLOAT128_ISLESSGREATER islessgreaterq
  257. //#define BOOST_CSTDFLOAT_FLOAT128_ISUNORDERED isunorderedq
  258. // end more functions
  259. #endif
  260. // Implement quadruple-precision <cmath> functions in the namespace
  261. // boost::math::cstdfloat::detail. Subsequently inject these into the
  262. // std namespace via *using* directive.
  263. // Begin with some forward function declarations. Also implement patches
  264. // for compilers that have broken float128 exponential functions.
  265. extern "C" int quadmath_snprintf(char*, std::size_t, const char*, ...) BOOST_MATH_NOTHROW;
  266. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_LDEXP(boost::math::cstdfloat::detail::float_internal128_t, int) BOOST_MATH_NOTHROW;
  267. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_FREXP(boost::math::cstdfloat::detail::float_internal128_t, int*) BOOST_MATH_NOTHROW;
  268. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_FABS(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  269. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_FLOOR(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  270. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_CEIL(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  271. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_SQRT(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  272. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_TRUNC(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  273. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_POW(boost::math::cstdfloat::detail::float_internal128_t, boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  274. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_LOG(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  275. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_LOG10(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  276. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_SIN(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  277. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_COS(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  278. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_TAN(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  279. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_ASIN(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  280. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_ACOS(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  281. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_ATAN(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  282. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_FMOD(boost::math::cstdfloat::detail::float_internal128_t, boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  283. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_ATAN2(boost::math::cstdfloat::detail::float_internal128_t, boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  284. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_LGAMMA(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  285. // begin more functions
  286. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_REMAINDER(boost::math::cstdfloat::detail::float_internal128_t, boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  287. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_REMQUO(boost::math::cstdfloat::detail::float_internal128_t, boost::math::cstdfloat::detail::float_internal128_t, int*) BOOST_MATH_NOTHROW;
  288. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_FMA(boost::math::cstdfloat::detail::float_internal128_t, boost::math::cstdfloat::detail::float_internal128_t, boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  289. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_FMAX(boost::math::cstdfloat::detail::float_internal128_t, boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  290. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_FMIN(boost::math::cstdfloat::detail::float_internal128_t, boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  291. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_FDIM(boost::math::cstdfloat::detail::float_internal128_t, boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  292. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_NAN(const char*) BOOST_MATH_NOTHROW;
  293. //extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_EXP2 (boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  294. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_LOG2(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  295. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_LOG1P(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  296. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_CBRT(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  297. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_HYPOT(boost::math::cstdfloat::detail::float_internal128_t, boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  298. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_ERF(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  299. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_ERFC(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  300. extern "C" long long int BOOST_CSTDFLOAT_FLOAT128_LLROUND(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  301. extern "C" long int BOOST_CSTDFLOAT_FLOAT128_LROUND(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  302. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_ROUND(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  303. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_NEARBYINT(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  304. extern "C" long long int BOOST_CSTDFLOAT_FLOAT128_LLRINT(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  305. extern "C" long int BOOST_CSTDFLOAT_FLOAT128_LRINT(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  306. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_RINT(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  307. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_MODF(boost::math::cstdfloat::detail::float_internal128_t, boost::math::cstdfloat::detail::float_internal128_t*) BOOST_MATH_NOTHROW;
  308. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_SCALBLN(boost::math::cstdfloat::detail::float_internal128_t, long int) BOOST_MATH_NOTHROW;
  309. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_SCALBN(boost::math::cstdfloat::detail::float_internal128_t, int) BOOST_MATH_NOTHROW;
  310. extern "C" int BOOST_CSTDFLOAT_FLOAT128_ILOGB(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  311. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_LOGB(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  312. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_NEXTAFTER(boost::math::cstdfloat::detail::float_internal128_t, boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  313. //extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_NEXTTOWARD (boost::math::cstdfloat::detail::float_internal128_t, boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  314. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_COPYSIGN(boost::math::cstdfloat::detail::float_internal128_t, boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  315. extern "C" int BOOST_CSTDFLOAT_FLOAT128_SIGNBIT(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  316. //extern "C" int BOOST_CSTDFLOAT_FLOAT128_FPCLASSIFY (boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  317. //extern "C" int BOOST_CSTDFLOAT_FLOAT128_ISFINITE (boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  318. extern "C" int BOOST_CSTDFLOAT_FLOAT128_ISINF(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  319. extern "C" int BOOST_CSTDFLOAT_FLOAT128_ISNAN(boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  320. //extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_ISNORMAL (boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  321. //extern "C" int BOOST_CSTDFLOAT_FLOAT128_ISGREATER (boost::math::cstdfloat::detail::float_internal128_t, boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  322. //extern "C" int BOOST_CSTDFLOAT_FLOAT128_ISGREATEREQUAL(boost::math::cstdfloat::detail::float_internal128_t, boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  323. //extern "C" int BOOST_CSTDFLOAT_FLOAT128_ISLESS (boost::math::cstdfloat::detail::float_internal128_t, boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  324. //extern "C" int BOOST_CSTDFLOAT_FLOAT128_ISLESSEQUAL (boost::math::cstdfloat::detail::float_internal128_t, boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  325. //extern "C" int BOOST_CSTDFLOAT_FLOAT128_ISLESSGREATER(boost::math::cstdfloat::detail::float_internal128_t, boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  326. //extern "C" int BOOST_CSTDFLOAT_FLOAT128_ISUNORDERED (boost::math::cstdfloat::detail::float_internal128_t, boost::math::cstdfloat::detail::float_internal128_t) BOOST_MATH_NOTHROW;
  327. // end more functions
  328. #if !defined(BOOST_CSTDFLOAT_BROKEN_FLOAT128_MATH_FUNCTIONS)
  329. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_EXP(boost::math::cstdfloat::detail::float_internal128_t x) BOOST_MATH_NOTHROW;
  330. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_EXPM1(boost::math::cstdfloat::detail::float_internal128_t x) BOOST_MATH_NOTHROW;
  331. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_SINH(boost::math::cstdfloat::detail::float_internal128_t x) BOOST_MATH_NOTHROW;
  332. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_COSH(boost::math::cstdfloat::detail::float_internal128_t x) BOOST_MATH_NOTHROW;
  333. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_TANH(boost::math::cstdfloat::detail::float_internal128_t x) BOOST_MATH_NOTHROW;
  334. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_ASINH(boost::math::cstdfloat::detail::float_internal128_t x) BOOST_MATH_NOTHROW;
  335. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_ACOSH(boost::math::cstdfloat::detail::float_internal128_t x) BOOST_MATH_NOTHROW;
  336. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_ATANH(boost::math::cstdfloat::detail::float_internal128_t x) BOOST_MATH_NOTHROW;
  337. extern "C" boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_TGAMMA(boost::math::cstdfloat::detail::float_internal128_t x) BOOST_MATH_NOTHROW;
  338. #else // BOOST_CSTDFLOAT_BROKEN_FLOAT128_MATH_FUNCTIONS
  339. // Forward declaration of the patched exponent function, exp(x).
  340. inline boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_EXP(boost::math::cstdfloat::detail::float_internal128_t x);
  341. inline boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_EXPM1(boost::math::cstdfloat::detail::float_internal128_t x)
  342. {
  343. // Compute exp(x) - 1 for x small.
  344. // Use an order-12 Pade approximation of the exponential function.
  345. // PadeApproximant[Exp[x] - 1, {x, 0, 12, 12}].
  346. typedef boost::math::cstdfloat::detail::float_internal128_t float_type;
  347. float_type sum;
  348. if (x > BOOST_FLOAT128_C(0.693147180559945309417232121458176568075500134360255))
  349. {
  350. sum = ::BOOST_CSTDFLOAT_FLOAT128_EXP(x) - float_type(1);
  351. }
  352. else
  353. {
  354. const float_type x2 = (x * x);
  355. const float_type top = ((((( float_type(BOOST_FLOAT128_C(2.4087176110456818621091195109360728010934088788572E-13)) * x2
  356. + float_type(BOOST_FLOAT128_C(9.2735628025258751691201101171038802842096241836000E-10))) * x2
  357. + float_type(BOOST_FLOAT128_C(9.0806726962333369656024118266681195742980640005812E-07))) * x2
  358. + float_type(BOOST_FLOAT128_C(3.1055900621118012422360248447204968944099378881988E-04))) * x2
  359. + float_type(BOOST_FLOAT128_C(3.6231884057971014492753623188405797101449275362319E-02))) * x2
  360. + float_type(BOOST_FLOAT128_C(1.00000000000000000000000000000000000000000000000000000)))
  361. ;
  362. const float_type bot = (((((((((((( float_type(BOOST_FLOAT128_C(+7.7202487533515444298369215094104897470942592271063E-16)) * x
  363. + float_type(BOOST_FLOAT128_C(-1.2043588055228409310545597554680364005467044394286E-13))) * x
  364. + float_type(BOOST_FLOAT128_C(+9.2735628025258751691201101171038802842096241836000E-12))) * x
  365. + float_type(BOOST_FLOAT128_C(-4.6367814012629375845600550585519401421048120918000E-10))) * x
  366. + float_type(BOOST_FLOAT128_C(+1.6692413044546575304416198210786984511577323530480E-08))) * x
  367. + float_type(BOOST_FLOAT128_C(-4.5403363481166684828012059133340597871490320002906E-07))) * x
  368. + float_type(BOOST_FLOAT128_C(+9.5347063310450038138825324180015255530129672006102E-06))) * x
  369. + float_type(BOOST_FLOAT128_C(-1.5527950310559006211180124223602484472049689440994E-04))) * x
  370. + float_type(BOOST_FLOAT128_C(+1.9409937888198757763975155279503105590062111801242E-03))) * x
  371. + float_type(BOOST_FLOAT128_C(-1.8115942028985507246376811594202898550724637681159E-02))) * x
  372. + float_type(BOOST_FLOAT128_C(+1.1956521739130434782608695652173913043478260869565E-01))) * x
  373. + float_type(BOOST_FLOAT128_C(-0.50000000000000000000000000000000000000000000000000000))) * x
  374. + float_type(BOOST_FLOAT128_C(+1.00000000000000000000000000000000000000000000000000000)))
  375. ;
  376. sum = (x * top) / bot;
  377. }
  378. return sum;
  379. }
  380. inline boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_EXP(boost::math::cstdfloat::detail::float_internal128_t x)
  381. {
  382. // Patch the expq() function for a subset of broken GCC compilers
  383. // like GCC 4.7, 4.8 on MinGW.
  384. typedef boost::math::cstdfloat::detail::float_internal128_t float_type;
  385. // Scale the argument x to the range (-ln2 < x < ln2).
  386. constexpr float_type one_over_ln2 = float_type(BOOST_FLOAT128_C(1.44269504088896340735992468100189213742664595415299));
  387. const float_type x_over_ln2 = x * one_over_ln2;
  388. int n;
  389. if (x != x)
  390. {
  391. // The argument is NaN.
  392. return std::numeric_limits<float_type>::quiet_NaN();
  393. }
  394. else if (::BOOST_CSTDFLOAT_FLOAT128_FABS(x) > BOOST_FLOAT128_C(+0.693147180559945309417232121458176568075500134360255))
  395. {
  396. // The absolute value of the argument exceeds ln2.
  397. n = static_cast<int>(::BOOST_CSTDFLOAT_FLOAT128_FLOOR(x_over_ln2));
  398. }
  399. else if (::BOOST_CSTDFLOAT_FLOAT128_FABS(x) < BOOST_FLOAT128_C(+0.693147180559945309417232121458176568075500134360255))
  400. {
  401. // The absolute value of the argument is less than ln2.
  402. n = 0;
  403. }
  404. else
  405. {
  406. // The absolute value of the argument is exactly equal to ln2 (in the sense of floating-point equality).
  407. return float_type(2);
  408. }
  409. // Check if the argument is very near an integer.
  410. const float_type floor_of_x = ::BOOST_CSTDFLOAT_FLOAT128_FLOOR(x);
  411. if (::BOOST_CSTDFLOAT_FLOAT128_FABS(x - floor_of_x) < float_type(BOOST_CSTDFLOAT_FLOAT128_EPS))
  412. {
  413. // Return e^n for arguments very near an integer.
  414. return boost::math::cstdfloat::detail::pown(BOOST_FLOAT128_C(2.71828182845904523536028747135266249775724709369996), static_cast<std::int_fast32_t>(floor_of_x));
  415. }
  416. // Compute the scaled argument alpha.
  417. const float_type alpha = x - (n * BOOST_FLOAT128_C(0.693147180559945309417232121458176568075500134360255));
  418. // Compute the polynomial approximation of expm1(alpha) and add to it
  419. // in order to obtain the scaled result.
  420. const float_type scaled_result = ::BOOST_CSTDFLOAT_FLOAT128_EXPM1(alpha) + float_type(1);
  421. // Rescale the result and return it.
  422. return scaled_result * boost::math::cstdfloat::detail::pown(float_type(2), n);
  423. }
  424. inline boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_SINH(boost::math::cstdfloat::detail::float_internal128_t x)
  425. {
  426. // Patch the sinhq() function for a subset of broken GCC compilers
  427. // like GCC 4.7, 4.8 on MinGW.
  428. typedef boost::math::cstdfloat::detail::float_internal128_t float_type;
  429. // Here, we use the following:
  430. // Set: ex = exp(x)
  431. // Set: em1 = expm1(x)
  432. // Then
  433. // sinh(x) = (ex - 1/ex) / 2 ; for |x| >= 1
  434. // sinh(x) = (2em1 + em1^2) / (2ex) ; for |x| < 1
  435. const float_type ex = ::BOOST_CSTDFLOAT_FLOAT128_EXP(x);
  436. if (::BOOST_CSTDFLOAT_FLOAT128_FABS(x) < float_type(+1))
  437. {
  438. const float_type em1 = ::BOOST_CSTDFLOAT_FLOAT128_EXPM1(x);
  439. return ((em1 * 2) + (em1 * em1)) / (ex * 2);
  440. }
  441. else
  442. {
  443. return (ex - (float_type(1) / ex)) / 2;
  444. }
  445. }
  446. inline boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_COSH(boost::math::cstdfloat::detail::float_internal128_t x)
  447. {
  448. // Patch the coshq() function for a subset of broken GCC compilers
  449. // like GCC 4.7, 4.8 on MinGW.
  450. typedef boost::math::cstdfloat::detail::float_internal128_t float_type;
  451. const float_type ex = ::BOOST_CSTDFLOAT_FLOAT128_EXP(x);
  452. return (ex + (float_type(1) / ex)) / 2;
  453. }
  454. inline boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_TANH(boost::math::cstdfloat::detail::float_internal128_t x)
  455. {
  456. // Patch the tanhq() function for a subset of broken GCC compilers
  457. // like GCC 4.7, 4.8 on MinGW.
  458. typedef boost::math::cstdfloat::detail::float_internal128_t float_type;
  459. const float_type ex_plus = ::BOOST_CSTDFLOAT_FLOAT128_EXP(x);
  460. const float_type ex_minus = (float_type(1) / ex_plus);
  461. return (ex_plus - ex_minus) / (ex_plus + ex_minus);
  462. }
  463. inline boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_ASINH(boost::math::cstdfloat::detail::float_internal128_t x) BOOST_MATH_NOTHROW
  464. {
  465. // Patch the asinh() function since quadmath does not have it.
  466. typedef boost::math::cstdfloat::detail::float_internal128_t float_type;
  467. return ::BOOST_CSTDFLOAT_FLOAT128_LOG(x + ::BOOST_CSTDFLOAT_FLOAT128_SQRT((x * x) + float_type(1)));
  468. }
  469. inline boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_ACOSH(boost::math::cstdfloat::detail::float_internal128_t x) BOOST_MATH_NOTHROW
  470. {
  471. // Patch the acosh() function since quadmath does not have it.
  472. typedef boost::math::cstdfloat::detail::float_internal128_t float_type;
  473. const float_type zp(x + float_type(1));
  474. const float_type zm(x - float_type(1));
  475. return ::BOOST_CSTDFLOAT_FLOAT128_LOG(x + (zp * ::BOOST_CSTDFLOAT_FLOAT128_SQRT(zm / zp)));
  476. }
  477. inline boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_ATANH(boost::math::cstdfloat::detail::float_internal128_t x) BOOST_MATH_NOTHROW
  478. {
  479. // Patch the atanh() function since quadmath does not have it.
  480. typedef boost::math::cstdfloat::detail::float_internal128_t float_type;
  481. return (::BOOST_CSTDFLOAT_FLOAT128_LOG(float_type(1) + x)
  482. - ::BOOST_CSTDFLOAT_FLOAT128_LOG(float_type(1) - x)) / 2;
  483. }
  484. inline boost::math::cstdfloat::detail::float_internal128_t BOOST_CSTDFLOAT_FLOAT128_TGAMMA(boost::math::cstdfloat::detail::float_internal128_t x) BOOST_MATH_NOTHROW
  485. {
  486. // Patch the tgammaq() function for a subset of broken GCC compilers
  487. // like GCC 4.7, 4.8 on MinGW.
  488. typedef boost::math::cstdfloat::detail::float_internal128_t float_type;
  489. if (x > float_type(0))
  490. {
  491. return ::BOOST_CSTDFLOAT_FLOAT128_EXP(::BOOST_CSTDFLOAT_FLOAT128_LGAMMA(x));
  492. }
  493. else if (x < float_type(0))
  494. {
  495. // For x < 0, compute tgamma(-x) and use the reflection formula.
  496. const float_type positive_x = -x;
  497. float_type gamma_value = ::BOOST_CSTDFLOAT_FLOAT128_TGAMMA(positive_x);
  498. const float_type floor_of_positive_x = ::BOOST_CSTDFLOAT_FLOAT128_FLOOR(positive_x);
  499. // Take the reflection checks (slightly adapted) from <boost/math/gamma.hpp>.
  500. const bool floor_of_z_is_equal_to_z = (positive_x == ::BOOST_CSTDFLOAT_FLOAT128_FLOOR(positive_x));
  501. constexpr float_type my_pi = BOOST_FLOAT128_C(3.14159265358979323846264338327950288419716939937511);
  502. if (floor_of_z_is_equal_to_z)
  503. {
  504. const bool is_odd = ((std::int32_t(floor_of_positive_x) % std::int32_t(2)) != std::int32_t(0));
  505. return (is_odd ? -std::numeric_limits<float_type>::infinity()
  506. : +std::numeric_limits<float_type>::infinity());
  507. }
  508. const float_type sinpx_value = x * ::BOOST_CSTDFLOAT_FLOAT128_SIN(my_pi * x);
  509. gamma_value *= sinpx_value;
  510. const bool result_is_too_large_to_represent = ((::BOOST_CSTDFLOAT_FLOAT128_FABS(gamma_value) < float_type(1))
  511. && (((std::numeric_limits<float_type>::max)() * ::BOOST_CSTDFLOAT_FLOAT128_FABS(gamma_value)) < my_pi));
  512. if (result_is_too_large_to_represent)
  513. {
  514. const bool is_odd = ((std::int32_t(floor_of_positive_x) % std::int32_t(2)) != std::int32_t(0));
  515. return (is_odd ? -std::numeric_limits<float_type>::infinity()
  516. : +std::numeric_limits<float_type>::infinity());
  517. }
  518. gamma_value = -my_pi / gamma_value;
  519. if ((gamma_value > float_type(0)) || (gamma_value < float_type(0)))
  520. {
  521. return gamma_value;
  522. }
  523. else
  524. {
  525. // The value of gamma is too small to represent. Return 0.0 here.
  526. return float_type(0);
  527. }
  528. }
  529. else
  530. {
  531. // Gamma of zero is complex infinity. Return NaN here.
  532. return std::numeric_limits<float_type>::quiet_NaN();
  533. }
  534. }
  535. #endif // BOOST_CSTDFLOAT_BROKEN_FLOAT128_MATH_FUNCTIONS
  536. // Define the quadruple-precision <cmath> functions in the namespace boost::math::cstdfloat::detail.
  537. namespace boost {
  538. namespace math {
  539. namespace cstdfloat {
  540. namespace detail {
  541. inline boost::math::cstdfloat::detail::float_internal128_t ldexp(boost::math::cstdfloat::detail::float_internal128_t x, int n) { return ::BOOST_CSTDFLOAT_FLOAT128_LDEXP(x, n); }
  542. inline boost::math::cstdfloat::detail::float_internal128_t frexp(boost::math::cstdfloat::detail::float_internal128_t x, int* pn) { return ::BOOST_CSTDFLOAT_FLOAT128_FREXP(x, pn); }
  543. inline boost::math::cstdfloat::detail::float_internal128_t fabs(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_FABS(x); }
  544. inline boost::math::cstdfloat::detail::float_internal128_t abs(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_FABS(x); }
  545. inline boost::math::cstdfloat::detail::float_internal128_t floor(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_FLOOR(x); }
  546. inline boost::math::cstdfloat::detail::float_internal128_t ceil(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_CEIL(x); }
  547. inline boost::math::cstdfloat::detail::float_internal128_t sqrt(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_SQRT(x); }
  548. inline boost::math::cstdfloat::detail::float_internal128_t trunc(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_TRUNC(x); }
  549. inline boost::math::cstdfloat::detail::float_internal128_t exp(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_EXP(x); }
  550. inline boost::math::cstdfloat::detail::float_internal128_t expm1(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_EXPM1(x); }
  551. inline boost::math::cstdfloat::detail::float_internal128_t pow(boost::math::cstdfloat::detail::float_internal128_t x, boost::math::cstdfloat::detail::float_internal128_t a) { return ::BOOST_CSTDFLOAT_FLOAT128_POW(x, a); }
  552. inline boost::math::cstdfloat::detail::float_internal128_t pow(boost::math::cstdfloat::detail::float_internal128_t x, int a) { return ::BOOST_CSTDFLOAT_FLOAT128_POW(x, boost::math::cstdfloat::detail::float_internal128_t(a)); }
  553. inline boost::math::cstdfloat::detail::float_internal128_t log(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_LOG(x); }
  554. inline boost::math::cstdfloat::detail::float_internal128_t log10(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_LOG10(x); }
  555. inline boost::math::cstdfloat::detail::float_internal128_t sin(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_SIN(x); }
  556. inline boost::math::cstdfloat::detail::float_internal128_t cos(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_COS(x); }
  557. inline boost::math::cstdfloat::detail::float_internal128_t tan(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_TAN(x); }
  558. inline boost::math::cstdfloat::detail::float_internal128_t asin(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_ASIN(x); }
  559. inline boost::math::cstdfloat::detail::float_internal128_t acos(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_ACOS(x); }
  560. inline boost::math::cstdfloat::detail::float_internal128_t atan(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_ATAN(x); }
  561. inline boost::math::cstdfloat::detail::float_internal128_t sinh(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_SINH(x); }
  562. inline boost::math::cstdfloat::detail::float_internal128_t cosh(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_COSH(x); }
  563. inline boost::math::cstdfloat::detail::float_internal128_t tanh(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_TANH(x); }
  564. inline boost::math::cstdfloat::detail::float_internal128_t asinh(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_ASINH(x); }
  565. inline boost::math::cstdfloat::detail::float_internal128_t acosh(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_ACOSH(x); }
  566. inline boost::math::cstdfloat::detail::float_internal128_t atanh(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_ATANH(x); }
  567. inline boost::math::cstdfloat::detail::float_internal128_t fmod(boost::math::cstdfloat::detail::float_internal128_t a, boost::math::cstdfloat::detail::float_internal128_t b) { return ::BOOST_CSTDFLOAT_FLOAT128_FMOD(a, b); }
  568. inline boost::math::cstdfloat::detail::float_internal128_t atan2(boost::math::cstdfloat::detail::float_internal128_t y, boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_ATAN2(y, x); }
  569. inline boost::math::cstdfloat::detail::float_internal128_t lgamma(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_LGAMMA(x); }
  570. inline boost::math::cstdfloat::detail::float_internal128_t tgamma(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_TGAMMA(x); }
  571. // begin more functions
  572. inline boost::math::cstdfloat::detail::float_internal128_t remainder(boost::math::cstdfloat::detail::float_internal128_t x, boost::math::cstdfloat::detail::float_internal128_t y) { return ::BOOST_CSTDFLOAT_FLOAT128_REMAINDER(x, y); }
  573. inline boost::math::cstdfloat::detail::float_internal128_t remquo(boost::math::cstdfloat::detail::float_internal128_t x, boost::math::cstdfloat::detail::float_internal128_t y, int* z) { return ::BOOST_CSTDFLOAT_FLOAT128_REMQUO(x, y, z); }
  574. inline boost::math::cstdfloat::detail::float_internal128_t fma(boost::math::cstdfloat::detail::float_internal128_t x, boost::math::cstdfloat::detail::float_internal128_t y, boost::math::cstdfloat::detail::float_internal128_t z) { return BOOST_CSTDFLOAT_FLOAT128_FMA(x, y, z); }
  575. inline boost::math::cstdfloat::detail::float_internal128_t fmax(boost::math::cstdfloat::detail::float_internal128_t x, boost::math::cstdfloat::detail::float_internal128_t y) { return ::BOOST_CSTDFLOAT_FLOAT128_FMAX(x, y); }
  576. template <class T>
  577. inline typename std::enable_if<
  578. std::is_convertible<T, boost::math::cstdfloat::detail::float_internal128_t>::value
  579. && !std::is_same<T, boost::math::cstdfloat::detail::float_internal128_t>::value, boost::math::cstdfloat::detail::float_internal128_t>::type
  580. fmax(boost::math::cstdfloat::detail::float_internal128_t x, T y) { return ::BOOST_CSTDFLOAT_FLOAT128_FMAX(x, y); }
  581. template <class T>
  582. inline typename std::enable_if<
  583. std::is_convertible<T, boost::math::cstdfloat::detail::float_internal128_t>::value
  584. && !std::is_same<T, boost::math::cstdfloat::detail::float_internal128_t>::value, boost::math::cstdfloat::detail::float_internal128_t>::type
  585. fmax(T x, boost::math::cstdfloat::detail::float_internal128_t y) { return ::BOOST_CSTDFLOAT_FLOAT128_FMAX(x, y); }
  586. inline boost::math::cstdfloat::detail::float_internal128_t fmin(boost::math::cstdfloat::detail::float_internal128_t x, boost::math::cstdfloat::detail::float_internal128_t y) { return ::BOOST_CSTDFLOAT_FLOAT128_FMIN(x, y); }
  587. template <class T>
  588. inline typename std::enable_if<
  589. std::is_convertible<T, boost::math::cstdfloat::detail::float_internal128_t>::value
  590. && !std::is_same<T, boost::math::cstdfloat::detail::float_internal128_t>::value, boost::math::cstdfloat::detail::float_internal128_t>::type
  591. fmin(boost::math::cstdfloat::detail::float_internal128_t x, T y) { return ::BOOST_CSTDFLOAT_FLOAT128_FMIN(x, y); }
  592. template <class T>
  593. inline typename std::enable_if<
  594. std::is_convertible<T, boost::math::cstdfloat::detail::float_internal128_t>::value
  595. && !std::is_same<T, boost::math::cstdfloat::detail::float_internal128_t>::value, boost::math::cstdfloat::detail::float_internal128_t>::type
  596. fmin(T x, boost::math::cstdfloat::detail::float_internal128_t y) { return ::BOOST_CSTDFLOAT_FLOAT128_FMIN(x, y); }
  597. inline boost::math::cstdfloat::detail::float_internal128_t fdim(boost::math::cstdfloat::detail::float_internal128_t x, boost::math::cstdfloat::detail::float_internal128_t y) { return ::BOOST_CSTDFLOAT_FLOAT128_FDIM(x, y); }
  598. inline boost::math::cstdfloat::detail::float_internal128_t nanq(const char* x) { return ::BOOST_CSTDFLOAT_FLOAT128_NAN(x); }
  599. inline boost::math::cstdfloat::detail::float_internal128_t exp2(boost::math::cstdfloat::detail::float_internal128_t x)
  600. {
  601. return ::BOOST_CSTDFLOAT_FLOAT128_POW(boost::math::cstdfloat::detail::float_internal128_t(2), x);
  602. }
  603. inline boost::math::cstdfloat::detail::float_internal128_t log2(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_LOG2(x); }
  604. inline boost::math::cstdfloat::detail::float_internal128_t log1p(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_LOG1P(x); }
  605. inline boost::math::cstdfloat::detail::float_internal128_t cbrt(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_CBRT(x); }
  606. inline boost::math::cstdfloat::detail::float_internal128_t hypot(boost::math::cstdfloat::detail::float_internal128_t x, boost::math::cstdfloat::detail::float_internal128_t y, boost::math::cstdfloat::detail::float_internal128_t z) { return ::BOOST_CSTDFLOAT_FLOAT128_SQRT(x*x + y * y + z * z); }
  607. inline boost::math::cstdfloat::detail::float_internal128_t hypot(boost::math::cstdfloat::detail::float_internal128_t x, boost::math::cstdfloat::detail::float_internal128_t y) { return ::BOOST_CSTDFLOAT_FLOAT128_HYPOT(x, y); }
  608. template <class T>
  609. inline typename std::enable_if<
  610. std::is_convertible<T, boost::math::cstdfloat::detail::float_internal128_t>::value
  611. && !std::is_same<T, boost::math::cstdfloat::detail::float_internal128_t>::value, boost::math::cstdfloat::detail::float_internal128_t>::type
  612. hypot(boost::math::cstdfloat::detail::float_internal128_t x, T y) { return ::BOOST_CSTDFLOAT_FLOAT128_HYPOT(x, y); }
  613. template <class T>
  614. inline typename std::enable_if<
  615. std::is_convertible<T, boost::math::cstdfloat::detail::float_internal128_t>::value
  616. && !std::is_same<T, boost::math::cstdfloat::detail::float_internal128_t>::value, boost::math::cstdfloat::detail::float_internal128_t>::type
  617. hypot(T x, boost::math::cstdfloat::detail::float_internal128_t y) { return ::BOOST_CSTDFLOAT_FLOAT128_HYPOT(x, y); }
  618. inline boost::math::cstdfloat::detail::float_internal128_t erf(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_ERF(x); }
  619. inline boost::math::cstdfloat::detail::float_internal128_t erfc(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_ERFC(x); }
  620. inline long long int llround(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_LLROUND(x); }
  621. inline long int lround(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_LROUND(x); }
  622. inline boost::math::cstdfloat::detail::float_internal128_t round(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_ROUND(x); }
  623. inline boost::math::cstdfloat::detail::float_internal128_t nearbyint(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_NEARBYINT(x); }
  624. inline long long int llrint(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_LLRINT(x); }
  625. inline long int lrint(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_LRINT(x); }
  626. inline boost::math::cstdfloat::detail::float_internal128_t rint(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_RINT(x); }
  627. inline boost::math::cstdfloat::detail::float_internal128_t modf(boost::math::cstdfloat::detail::float_internal128_t x, boost::math::cstdfloat::detail::float_internal128_t* y) { return ::BOOST_CSTDFLOAT_FLOAT128_MODF(x, y); }
  628. inline boost::math::cstdfloat::detail::float_internal128_t scalbln(boost::math::cstdfloat::detail::float_internal128_t x, long int y) { return ::BOOST_CSTDFLOAT_FLOAT128_SCALBLN(x, y); }
  629. inline boost::math::cstdfloat::detail::float_internal128_t scalbn(boost::math::cstdfloat::detail::float_internal128_t x, int y) { return ::BOOST_CSTDFLOAT_FLOAT128_SCALBN(x, y); }
  630. inline int ilogb(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_ILOGB(x); }
  631. inline boost::math::cstdfloat::detail::float_internal128_t logb(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_LOGB(x); }
  632. inline boost::math::cstdfloat::detail::float_internal128_t nextafter(boost::math::cstdfloat::detail::float_internal128_t x, boost::math::cstdfloat::detail::float_internal128_t y) { return ::BOOST_CSTDFLOAT_FLOAT128_NEXTAFTER(x, y); }
  633. inline boost::math::cstdfloat::detail::float_internal128_t nexttoward(boost::math::cstdfloat::detail::float_internal128_t x, boost::math::cstdfloat::detail::float_internal128_t y) { return -(::BOOST_CSTDFLOAT_FLOAT128_NEXTAFTER(-x, -y)); }
  634. inline boost::math::cstdfloat::detail::float_internal128_t copysign BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x, boost::math::cstdfloat::detail::float_internal128_t y) { return ::BOOST_CSTDFLOAT_FLOAT128_COPYSIGN(x, y); }
  635. inline bool signbit BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_SIGNBIT(x); }
  636. inline int fpclassify BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x)
  637. {
  638. if (::BOOST_CSTDFLOAT_FLOAT128_ISNAN(x))
  639. return FP_NAN;
  640. else if (::BOOST_CSTDFLOAT_FLOAT128_ISINF(x))
  641. return FP_INFINITE;
  642. else if (x == BOOST_FLOAT128_C(0.0))
  643. return FP_ZERO;
  644. if (::BOOST_CSTDFLOAT_FLOAT128_FABS(x) < BOOST_CSTDFLOAT_FLOAT128_MIN)
  645. return FP_SUBNORMAL;
  646. else
  647. return FP_NORMAL;
  648. }
  649. inline bool isfinite BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x)
  650. {
  651. return !::BOOST_CSTDFLOAT_FLOAT128_ISNAN(x) && !::BOOST_CSTDFLOAT_FLOAT128_ISINF(x);
  652. }
  653. inline bool isinf BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_ISINF(x); }
  654. inline bool isnan BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_ISNAN(x); }
  655. inline bool isnormal BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x) { return boost::math::cstdfloat::detail::fpclassify BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(x) == FP_NORMAL; }
  656. inline bool isgreater BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x, boost::math::cstdfloat::detail::float_internal128_t y)
  657. {
  658. if (isnan BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(x) || isnan BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(y))
  659. return false;
  660. return x > y;
  661. }
  662. template <class T>
  663. inline typename std::enable_if<
  664. std::is_convertible<T, boost::math::cstdfloat::detail::float_internal128_t>::value
  665. && !std::is_same<T, boost::math::cstdfloat::detail::float_internal128_t>::value, boost::math::cstdfloat::detail::float_internal128_t>::type
  666. isgreater BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x, T y) { return isgreater BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(x, (boost::math::cstdfloat::detail::float_internal128_t)y); }
  667. template <class T>
  668. inline typename std::enable_if<
  669. std::is_convertible<T, boost::math::cstdfloat::detail::float_internal128_t>::value
  670. && !std::is_same<T, boost::math::cstdfloat::detail::float_internal128_t>::value, boost::math::cstdfloat::detail::float_internal128_t>::type
  671. isgreater BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(T x, boost::math::cstdfloat::detail::float_internal128_t y) { return isgreater BOOST_MATH_PREVENT_MACRO_SUBSTITUTION((boost::math::cstdfloat::detail::float_internal128_t)x, y); }
  672. inline bool isgreaterequal BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x, boost::math::cstdfloat::detail::float_internal128_t y)
  673. {
  674. if (isnan BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(x) || isnan BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(y))
  675. return false;
  676. return x >= y;
  677. }
  678. template <class T>
  679. inline typename std::enable_if<
  680. std::is_convertible<T, boost::math::cstdfloat::detail::float_internal128_t>::value
  681. && !std::is_same<T, boost::math::cstdfloat::detail::float_internal128_t>::value, boost::math::cstdfloat::detail::float_internal128_t>::type
  682. isgreaterequal BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x, T y) { return isgreaterequal BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(x, (boost::math::cstdfloat::detail::float_internal128_t)y); }
  683. template <class T>
  684. inline typename std::enable_if<
  685. std::is_convertible<T, boost::math::cstdfloat::detail::float_internal128_t>::value
  686. && !std::is_same<T, boost::math::cstdfloat::detail::float_internal128_t>::value, boost::math::cstdfloat::detail::float_internal128_t>::type
  687. isgreaterequal BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(T x, boost::math::cstdfloat::detail::float_internal128_t y) { return isgreaterequal BOOST_MATH_PREVENT_MACRO_SUBSTITUTION((boost::math::cstdfloat::detail::float_internal128_t)x, y); }
  688. inline bool isless BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x, boost::math::cstdfloat::detail::float_internal128_t y)
  689. {
  690. if (isnan BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(x) || isnan BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(y))
  691. return false;
  692. return x < y;
  693. }
  694. template <class T>
  695. inline typename std::enable_if<
  696. std::is_convertible<T, boost::math::cstdfloat::detail::float_internal128_t>::value
  697. && !std::is_same<T, boost::math::cstdfloat::detail::float_internal128_t>::value, boost::math::cstdfloat::detail::float_internal128_t>::type
  698. isless BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x, T y) { return isless BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(x, (boost::math::cstdfloat::detail::float_internal128_t)y); }
  699. template <class T>
  700. inline typename std::enable_if<
  701. std::is_convertible<T, boost::math::cstdfloat::detail::float_internal128_t>::value
  702. && !std::is_same<T, boost::math::cstdfloat::detail::float_internal128_t>::value, boost::math::cstdfloat::detail::float_internal128_t>::type
  703. isless BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(T x, boost::math::cstdfloat::detail::float_internal128_t y) { return isless BOOST_MATH_PREVENT_MACRO_SUBSTITUTION((boost::math::cstdfloat::detail::float_internal128_t)x, y); }
  704. inline bool islessequal BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x, boost::math::cstdfloat::detail::float_internal128_t y)
  705. {
  706. if (isnan BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(x) || isnan BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(y))
  707. return false;
  708. return x <= y;
  709. }
  710. template <class T>
  711. inline typename std::enable_if<
  712. std::is_convertible<T, boost::math::cstdfloat::detail::float_internal128_t>::value
  713. && !std::is_same<T, boost::math::cstdfloat::detail::float_internal128_t>::value, boost::math::cstdfloat::detail::float_internal128_t>::type
  714. islessequal BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x, T y) { return islessequal BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(x, (boost::math::cstdfloat::detail::float_internal128_t)y); }
  715. template <class T>
  716. inline typename std::enable_if<
  717. std::is_convertible<T, boost::math::cstdfloat::detail::float_internal128_t>::value
  718. && !std::is_same<T, boost::math::cstdfloat::detail::float_internal128_t>::value, boost::math::cstdfloat::detail::float_internal128_t>::type
  719. islessequal BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(T x, boost::math::cstdfloat::detail::float_internal128_t y) { return islessequal BOOST_MATH_PREVENT_MACRO_SUBSTITUTION((boost::math::cstdfloat::detail::float_internal128_t)x, y); }
  720. inline bool islessgreater BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x, boost::math::cstdfloat::detail::float_internal128_t y)
  721. {
  722. if (isnan BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(x) || isnan BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(y))
  723. return false;
  724. return (x < y) || (x > y);
  725. }
  726. template <class T>
  727. inline typename std::enable_if<
  728. std::is_convertible<T, boost::math::cstdfloat::detail::float_internal128_t>::value
  729. && !std::is_same<T, boost::math::cstdfloat::detail::float_internal128_t>::value, boost::math::cstdfloat::detail::float_internal128_t>::type
  730. islessgreater BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x, T y) { return islessgreater BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(x, (boost::math::cstdfloat::detail::float_internal128_t)y); }
  731. template <class T>
  732. inline typename std::enable_if<
  733. std::is_convertible<T, boost::math::cstdfloat::detail::float_internal128_t>::value
  734. && !std::is_same<T, boost::math::cstdfloat::detail::float_internal128_t>::value, boost::math::cstdfloat::detail::float_internal128_t>::type
  735. islessgreater BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(T x, boost::math::cstdfloat::detail::float_internal128_t y) { return islessgreater BOOST_MATH_PREVENT_MACRO_SUBSTITUTION((boost::math::cstdfloat::detail::float_internal128_t)x, y); }
  736. inline bool isunordered BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x, boost::math::cstdfloat::detail::float_internal128_t y) { return ::BOOST_CSTDFLOAT_FLOAT128_ISNAN(x) || ::BOOST_CSTDFLOAT_FLOAT128_ISNAN(y); }
  737. template <class T>
  738. inline typename std::enable_if<
  739. std::is_convertible<T, boost::math::cstdfloat::detail::float_internal128_t>::value
  740. && !std::is_same<T, boost::math::cstdfloat::detail::float_internal128_t>::value, boost::math::cstdfloat::detail::float_internal128_t>::type
  741. isunordered BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x, T y) { return isunordered BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(x, (boost::math::cstdfloat::detail::float_internal128_t)y); }
  742. template <class T>
  743. inline typename std::enable_if<
  744. std::is_convertible<T, boost::math::cstdfloat::detail::float_internal128_t>::value
  745. && !std::is_same<T, boost::math::cstdfloat::detail::float_internal128_t>::value, boost::math::cstdfloat::detail::float_internal128_t>::type
  746. isunordered BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(T x, boost::math::cstdfloat::detail::float_internal128_t y) { return isunordered BOOST_MATH_PREVENT_MACRO_SUBSTITUTION((boost::math::cstdfloat::detail::float_internal128_t)x, y); }
  747. // end more functions
  748. }
  749. }
  750. }
  751. } // boost::math::cstdfloat::detail
  752. // We will now inject the quadruple-precision <cmath> functions
  753. // into the std namespace. This is done via *using* directive.
  754. namespace std
  755. {
  756. using boost::math::cstdfloat::detail::ldexp;
  757. using boost::math::cstdfloat::detail::frexp;
  758. using boost::math::cstdfloat::detail::fabs;
  759. #if !(defined(_GLIBCXX_USE_FLOAT128) && defined(__GNUC__) && (__GNUC__ >= 7))
  760. #if (defined(__clang__) && !(!defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128))) || (__GNUC__ <= 6 && !defined(__clang__))
  761. // workaround for clang using libstdc++ and old GCC
  762. using boost::math::cstdfloat::detail::abs;
  763. #endif
  764. #endif
  765. using boost::math::cstdfloat::detail::floor;
  766. using boost::math::cstdfloat::detail::ceil;
  767. using boost::math::cstdfloat::detail::sqrt;
  768. using boost::math::cstdfloat::detail::trunc;
  769. using boost::math::cstdfloat::detail::exp;
  770. using boost::math::cstdfloat::detail::expm1;
  771. using boost::math::cstdfloat::detail::pow;
  772. using boost::math::cstdfloat::detail::log;
  773. using boost::math::cstdfloat::detail::log10;
  774. using boost::math::cstdfloat::detail::sin;
  775. using boost::math::cstdfloat::detail::cos;
  776. using boost::math::cstdfloat::detail::tan;
  777. using boost::math::cstdfloat::detail::asin;
  778. using boost::math::cstdfloat::detail::acos;
  779. using boost::math::cstdfloat::detail::atan;
  780. using boost::math::cstdfloat::detail::sinh;
  781. using boost::math::cstdfloat::detail::cosh;
  782. using boost::math::cstdfloat::detail::tanh;
  783. using boost::math::cstdfloat::detail::asinh;
  784. using boost::math::cstdfloat::detail::acosh;
  785. using boost::math::cstdfloat::detail::atanh;
  786. using boost::math::cstdfloat::detail::fmod;
  787. using boost::math::cstdfloat::detail::atan2;
  788. using boost::math::cstdfloat::detail::lgamma;
  789. using boost::math::cstdfloat::detail::tgamma;
  790. // begin more functions
  791. using boost::math::cstdfloat::detail::remainder;
  792. using boost::math::cstdfloat::detail::remquo;
  793. using boost::math::cstdfloat::detail::fma;
  794. using boost::math::cstdfloat::detail::fmax;
  795. using boost::math::cstdfloat::detail::fmin;
  796. using boost::math::cstdfloat::detail::fdim;
  797. using boost::math::cstdfloat::detail::nanq;
  798. using boost::math::cstdfloat::detail::exp2;
  799. using boost::math::cstdfloat::detail::log2;
  800. using boost::math::cstdfloat::detail::log1p;
  801. using boost::math::cstdfloat::detail::cbrt;
  802. using boost::math::cstdfloat::detail::hypot;
  803. using boost::math::cstdfloat::detail::erf;
  804. using boost::math::cstdfloat::detail::erfc;
  805. using boost::math::cstdfloat::detail::llround;
  806. using boost::math::cstdfloat::detail::lround;
  807. using boost::math::cstdfloat::detail::round;
  808. using boost::math::cstdfloat::detail::nearbyint;
  809. using boost::math::cstdfloat::detail::llrint;
  810. using boost::math::cstdfloat::detail::lrint;
  811. using boost::math::cstdfloat::detail::rint;
  812. using boost::math::cstdfloat::detail::modf;
  813. using boost::math::cstdfloat::detail::scalbln;
  814. using boost::math::cstdfloat::detail::scalbn;
  815. using boost::math::cstdfloat::detail::ilogb;
  816. using boost::math::cstdfloat::detail::logb;
  817. using boost::math::cstdfloat::detail::nextafter;
  818. using boost::math::cstdfloat::detail::nexttoward;
  819. using boost::math::cstdfloat::detail::copysign;
  820. using boost::math::cstdfloat::detail::signbit;
  821. using boost::math::cstdfloat::detail::fpclassify;
  822. using boost::math::cstdfloat::detail::isfinite;
  823. using boost::math::cstdfloat::detail::isinf;
  824. using boost::math::cstdfloat::detail::isnan;
  825. using boost::math::cstdfloat::detail::isnormal;
  826. using boost::math::cstdfloat::detail::isgreater;
  827. using boost::math::cstdfloat::detail::isgreaterequal;
  828. using boost::math::cstdfloat::detail::isless;
  829. using boost::math::cstdfloat::detail::islessequal;
  830. using boost::math::cstdfloat::detail::islessgreater;
  831. using boost::math::cstdfloat::detail::isunordered;
  832. // end more functions
  833. } // namespace std
  834. // We will now remove the preprocessor symbols representing quadruple-precision <cmath>
  835. // functions from the preprocessor.
  836. #undef BOOST_CSTDFLOAT_FLOAT128_LDEXP
  837. #undef BOOST_CSTDFLOAT_FLOAT128_FREXP
  838. #undef BOOST_CSTDFLOAT_FLOAT128_FABS
  839. #undef BOOST_CSTDFLOAT_FLOAT128_FLOOR
  840. #undef BOOST_CSTDFLOAT_FLOAT128_CEIL
  841. #undef BOOST_CSTDFLOAT_FLOAT128_SQRT
  842. #undef BOOST_CSTDFLOAT_FLOAT128_TRUNC
  843. #undef BOOST_CSTDFLOAT_FLOAT128_EXP
  844. #undef BOOST_CSTDFLOAT_FLOAT128_EXPM1
  845. #undef BOOST_CSTDFLOAT_FLOAT128_POW
  846. #undef BOOST_CSTDFLOAT_FLOAT128_LOG
  847. #undef BOOST_CSTDFLOAT_FLOAT128_LOG10
  848. #undef BOOST_CSTDFLOAT_FLOAT128_SIN
  849. #undef BOOST_CSTDFLOAT_FLOAT128_COS
  850. #undef BOOST_CSTDFLOAT_FLOAT128_TAN
  851. #undef BOOST_CSTDFLOAT_FLOAT128_ASIN
  852. #undef BOOST_CSTDFLOAT_FLOAT128_ACOS
  853. #undef BOOST_CSTDFLOAT_FLOAT128_ATAN
  854. #undef BOOST_CSTDFLOAT_FLOAT128_SINH
  855. #undef BOOST_CSTDFLOAT_FLOAT128_COSH
  856. #undef BOOST_CSTDFLOAT_FLOAT128_TANH
  857. #undef BOOST_CSTDFLOAT_FLOAT128_ASINH
  858. #undef BOOST_CSTDFLOAT_FLOAT128_ACOSH
  859. #undef BOOST_CSTDFLOAT_FLOAT128_ATANH
  860. #undef BOOST_CSTDFLOAT_FLOAT128_FMOD
  861. #undef BOOST_CSTDFLOAT_FLOAT128_ATAN2
  862. #undef BOOST_CSTDFLOAT_FLOAT128_LGAMMA
  863. #undef BOOST_CSTDFLOAT_FLOAT128_TGAMMA
  864. // begin more functions
  865. #undef BOOST_CSTDFLOAT_FLOAT128_REMAINDER
  866. #undef BOOST_CSTDFLOAT_FLOAT128_REMQUO
  867. #undef BOOST_CSTDFLOAT_FLOAT128_FMA
  868. #undef BOOST_CSTDFLOAT_FLOAT128_FMAX
  869. #undef BOOST_CSTDFLOAT_FLOAT128_FMIN
  870. #undef BOOST_CSTDFLOAT_FLOAT128_FDIM
  871. #undef BOOST_CSTDFLOAT_FLOAT128_NAN
  872. #undef BOOST_CSTDFLOAT_FLOAT128_EXP2
  873. #undef BOOST_CSTDFLOAT_FLOAT128_LOG2
  874. #undef BOOST_CSTDFLOAT_FLOAT128_LOG1P
  875. #undef BOOST_CSTDFLOAT_FLOAT128_CBRT
  876. #undef BOOST_CSTDFLOAT_FLOAT128_HYPOT
  877. #undef BOOST_CSTDFLOAT_FLOAT128_ERF
  878. #undef BOOST_CSTDFLOAT_FLOAT128_ERFC
  879. #undef BOOST_CSTDFLOAT_FLOAT128_LLROUND
  880. #undef BOOST_CSTDFLOAT_FLOAT128_LROUND
  881. #undef BOOST_CSTDFLOAT_FLOAT128_ROUND
  882. #undef BOOST_CSTDFLOAT_FLOAT128_NEARBYINT
  883. #undef BOOST_CSTDFLOAT_FLOAT128_LLRINT
  884. #undef BOOST_CSTDFLOAT_FLOAT128_LRINT
  885. #undef BOOST_CSTDFLOAT_FLOAT128_RINT
  886. #undef BOOST_CSTDFLOAT_FLOAT128_MODF
  887. #undef BOOST_CSTDFLOAT_FLOAT128_SCALBLN
  888. #undef BOOST_CSTDFLOAT_FLOAT128_SCALBN
  889. #undef BOOST_CSTDFLOAT_FLOAT128_ILOGB
  890. #undef BOOST_CSTDFLOAT_FLOAT128_LOGB
  891. #undef BOOST_CSTDFLOAT_FLOAT128_NEXTAFTER
  892. #undef BOOST_CSTDFLOAT_FLOAT128_NEXTTOWARD
  893. #undef BOOST_CSTDFLOAT_FLOAT128_COPYSIGN
  894. #undef BOOST_CSTDFLOAT_FLOAT128_SIGNBIT
  895. #undef BOOST_CSTDFLOAT_FLOAT128_FPCLASSIFY
  896. #undef BOOST_CSTDFLOAT_FLOAT128_ISFINITE
  897. #undef BOOST_CSTDFLOAT_FLOAT128_ISINF
  898. #undef BOOST_CSTDFLOAT_FLOAT128_ISNAN
  899. #undef BOOST_CSTDFLOAT_FLOAT128_ISNORMAL
  900. #undef BOOST_CSTDFLOAT_FLOAT128_ISGREATER
  901. #undef BOOST_CSTDFLOAT_FLOAT128_ISGREATEREQUAL
  902. #undef BOOST_CSTDFLOAT_FLOAT128_ISLESS
  903. #undef BOOST_CSTDFLOAT_FLOAT128_ISLESSEQUAL
  904. #undef BOOST_CSTDFLOAT_FLOAT128_ISLESSGREATER
  905. #undef BOOST_CSTDFLOAT_FLOAT128_ISUNORDERED
  906. // end more functions
  907. #endif // Not BOOST_CSTDFLOAT_NO_LIBQUADMATH_SUPPORT (i.e., the user would like to have libquadmath support)
  908. #endif // BOOST_MATH_CSTDFLOAT_CMATH_2014_02_15_HPP_