cstdfloat_cmath.hpp 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058
  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_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_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_SIGNBIT(x); }
  636. inline int fpclassify BOOST_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_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_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_ISINF(x); }
  654. inline bool isnan BOOST_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x) { return ::BOOST_CSTDFLOAT_FLOAT128_ISNAN(x); }
  655. inline bool isnormal BOOST_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x) { return boost::math::cstdfloat::detail::fpclassify BOOST_PREVENT_MACRO_SUBSTITUTION(x) == FP_NORMAL; }
  656. inline bool isgreater BOOST_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x, boost::math::cstdfloat::detail::float_internal128_t y)
  657. {
  658. if (isnan BOOST_PREVENT_MACRO_SUBSTITUTION(x) || isnan BOOST_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_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x, T y) { return isgreater BOOST_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_PREVENT_MACRO_SUBSTITUTION(T x, boost::math::cstdfloat::detail::float_internal128_t y) { return isgreater BOOST_PREVENT_MACRO_SUBSTITUTION((boost::math::cstdfloat::detail::float_internal128_t)x, y); }
  672. inline bool isgreaterequal BOOST_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x, boost::math::cstdfloat::detail::float_internal128_t y)
  673. {
  674. if (isnan BOOST_PREVENT_MACRO_SUBSTITUTION(x) || isnan BOOST_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_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x, T y) { return isgreaterequal BOOST_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_PREVENT_MACRO_SUBSTITUTION(T x, boost::math::cstdfloat::detail::float_internal128_t y) { return isgreaterequal BOOST_PREVENT_MACRO_SUBSTITUTION((boost::math::cstdfloat::detail::float_internal128_t)x, y); }
  688. inline bool isless BOOST_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x, boost::math::cstdfloat::detail::float_internal128_t y)
  689. {
  690. if (isnan BOOST_PREVENT_MACRO_SUBSTITUTION(x) || isnan BOOST_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_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x, T y) { return isless BOOST_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_PREVENT_MACRO_SUBSTITUTION(T x, boost::math::cstdfloat::detail::float_internal128_t y) { return isless BOOST_PREVENT_MACRO_SUBSTITUTION((boost::math::cstdfloat::detail::float_internal128_t)x, y); }
  704. inline bool islessequal BOOST_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x, boost::math::cstdfloat::detail::float_internal128_t y)
  705. {
  706. if (isnan BOOST_PREVENT_MACRO_SUBSTITUTION(x) || isnan BOOST_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_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x, T y) { return islessequal BOOST_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_PREVENT_MACRO_SUBSTITUTION(T x, boost::math::cstdfloat::detail::float_internal128_t y) { return islessequal BOOST_PREVENT_MACRO_SUBSTITUTION((boost::math::cstdfloat::detail::float_internal128_t)x, y); }
  720. inline bool islessgreater BOOST_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x, boost::math::cstdfloat::detail::float_internal128_t y)
  721. {
  722. if (isnan BOOST_PREVENT_MACRO_SUBSTITUTION(x) || isnan BOOST_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_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x, T y) { return islessgreater BOOST_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_PREVENT_MACRO_SUBSTITUTION(T x, boost::math::cstdfloat::detail::float_internal128_t y) { return islessgreater BOOST_PREVENT_MACRO_SUBSTITUTION((boost::math::cstdfloat::detail::float_internal128_t)x, y); }
  736. inline bool isunordered BOOST_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_PREVENT_MACRO_SUBSTITUTION(boost::math::cstdfloat::detail::float_internal128_t x, T y) { return isunordered BOOST_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_PREVENT_MACRO_SUBSTITUTION(T x, boost::math::cstdfloat::detail::float_internal128_t y) { return isunordered BOOST_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. //
  834. // Very basic iostream operator:
  835. //
  836. inline std::ostream& operator << (std::ostream& os, __float128 m_value)
  837. {
  838. std::streamsize digits = os.precision();
  839. std::ios_base::fmtflags f = os.flags();
  840. std::string s;
  841. char buf[100];
  842. std::unique_ptr<char[]> buf2;
  843. std::string format = "%";
  844. if (f & std::ios_base::showpos)
  845. format += "+";
  846. if (f & std::ios_base::showpoint)
  847. format += "#";
  848. format += ".*";
  849. if (digits == 0)
  850. digits = 36;
  851. format += "Q";
  852. if (f & std::ios_base::scientific)
  853. format += "e";
  854. else if (f & std::ios_base::fixed)
  855. format += "f";
  856. else
  857. format += "g";
  858. int v = quadmath_snprintf(buf, 100, format.c_str(), digits, m_value);
  859. if ((v < 0) || (v >= 99))
  860. {
  861. int v_max = v;
  862. buf2.reset(new char[v + 3]);
  863. v = quadmath_snprintf(&buf2[0], v_max + 3, format.c_str(), digits, m_value);
  864. if (v >= v_max + 3)
  865. {
  866. BOOST_MATH_THROW_EXCEPTION(std::runtime_error("Formatting of float128_type failed."));
  867. }
  868. s = &buf2[0];
  869. }
  870. else
  871. s = buf;
  872. std::streamsize ss = os.width();
  873. if (ss > static_cast<std::streamsize>(s.size()))
  874. {
  875. char fill = os.fill();
  876. if ((os.flags() & std::ios_base::left) == std::ios_base::left)
  877. s.append(static_cast<std::string::size_type>(ss - s.size()), fill);
  878. else
  879. s.insert(static_cast<std::string::size_type>(0), static_cast<std::string::size_type>(ss - s.size()), fill);
  880. }
  881. return os << s;
  882. }
  883. } // namespace std
  884. // We will now remove the preprocessor symbols representing quadruple-precision <cmath>
  885. // functions from the preprocessor.
  886. #undef BOOST_CSTDFLOAT_FLOAT128_LDEXP
  887. #undef BOOST_CSTDFLOAT_FLOAT128_FREXP
  888. #undef BOOST_CSTDFLOAT_FLOAT128_FABS
  889. #undef BOOST_CSTDFLOAT_FLOAT128_FLOOR
  890. #undef BOOST_CSTDFLOAT_FLOAT128_CEIL
  891. #undef BOOST_CSTDFLOAT_FLOAT128_SQRT
  892. #undef BOOST_CSTDFLOAT_FLOAT128_TRUNC
  893. #undef BOOST_CSTDFLOAT_FLOAT128_EXP
  894. #undef BOOST_CSTDFLOAT_FLOAT128_EXPM1
  895. #undef BOOST_CSTDFLOAT_FLOAT128_POW
  896. #undef BOOST_CSTDFLOAT_FLOAT128_LOG
  897. #undef BOOST_CSTDFLOAT_FLOAT128_LOG10
  898. #undef BOOST_CSTDFLOAT_FLOAT128_SIN
  899. #undef BOOST_CSTDFLOAT_FLOAT128_COS
  900. #undef BOOST_CSTDFLOAT_FLOAT128_TAN
  901. #undef BOOST_CSTDFLOAT_FLOAT128_ASIN
  902. #undef BOOST_CSTDFLOAT_FLOAT128_ACOS
  903. #undef BOOST_CSTDFLOAT_FLOAT128_ATAN
  904. #undef BOOST_CSTDFLOAT_FLOAT128_SINH
  905. #undef BOOST_CSTDFLOAT_FLOAT128_COSH
  906. #undef BOOST_CSTDFLOAT_FLOAT128_TANH
  907. #undef BOOST_CSTDFLOAT_FLOAT128_ASINH
  908. #undef BOOST_CSTDFLOAT_FLOAT128_ACOSH
  909. #undef BOOST_CSTDFLOAT_FLOAT128_ATANH
  910. #undef BOOST_CSTDFLOAT_FLOAT128_FMOD
  911. #undef BOOST_CSTDFLOAT_FLOAT128_ATAN2
  912. #undef BOOST_CSTDFLOAT_FLOAT128_LGAMMA
  913. #undef BOOST_CSTDFLOAT_FLOAT128_TGAMMA
  914. // begin more functions
  915. #undef BOOST_CSTDFLOAT_FLOAT128_REMAINDER
  916. #undef BOOST_CSTDFLOAT_FLOAT128_REMQUO
  917. #undef BOOST_CSTDFLOAT_FLOAT128_FMA
  918. #undef BOOST_CSTDFLOAT_FLOAT128_FMAX
  919. #undef BOOST_CSTDFLOAT_FLOAT128_FMIN
  920. #undef BOOST_CSTDFLOAT_FLOAT128_FDIM
  921. #undef BOOST_CSTDFLOAT_FLOAT128_NAN
  922. #undef BOOST_CSTDFLOAT_FLOAT128_EXP2
  923. #undef BOOST_CSTDFLOAT_FLOAT128_LOG2
  924. #undef BOOST_CSTDFLOAT_FLOAT128_LOG1P
  925. #undef BOOST_CSTDFLOAT_FLOAT128_CBRT
  926. #undef BOOST_CSTDFLOAT_FLOAT128_HYPOT
  927. #undef BOOST_CSTDFLOAT_FLOAT128_ERF
  928. #undef BOOST_CSTDFLOAT_FLOAT128_ERFC
  929. #undef BOOST_CSTDFLOAT_FLOAT128_LLROUND
  930. #undef BOOST_CSTDFLOAT_FLOAT128_LROUND
  931. #undef BOOST_CSTDFLOAT_FLOAT128_ROUND
  932. #undef BOOST_CSTDFLOAT_FLOAT128_NEARBYINT
  933. #undef BOOST_CSTDFLOAT_FLOAT128_LLRINT
  934. #undef BOOST_CSTDFLOAT_FLOAT128_LRINT
  935. #undef BOOST_CSTDFLOAT_FLOAT128_RINT
  936. #undef BOOST_CSTDFLOAT_FLOAT128_MODF
  937. #undef BOOST_CSTDFLOAT_FLOAT128_SCALBLN
  938. #undef BOOST_CSTDFLOAT_FLOAT128_SCALBN
  939. #undef BOOST_CSTDFLOAT_FLOAT128_ILOGB
  940. #undef BOOST_CSTDFLOAT_FLOAT128_LOGB
  941. #undef BOOST_CSTDFLOAT_FLOAT128_NEXTAFTER
  942. #undef BOOST_CSTDFLOAT_FLOAT128_NEXTTOWARD
  943. #undef BOOST_CSTDFLOAT_FLOAT128_COPYSIGN
  944. #undef BOOST_CSTDFLOAT_FLOAT128_SIGNBIT
  945. #undef BOOST_CSTDFLOAT_FLOAT128_FPCLASSIFY
  946. #undef BOOST_CSTDFLOAT_FLOAT128_ISFINITE
  947. #undef BOOST_CSTDFLOAT_FLOAT128_ISINF
  948. #undef BOOST_CSTDFLOAT_FLOAT128_ISNAN
  949. #undef BOOST_CSTDFLOAT_FLOAT128_ISNORMAL
  950. #undef BOOST_CSTDFLOAT_FLOAT128_ISGREATER
  951. #undef BOOST_CSTDFLOAT_FLOAT128_ISGREATEREQUAL
  952. #undef BOOST_CSTDFLOAT_FLOAT128_ISLESS
  953. #undef BOOST_CSTDFLOAT_FLOAT128_ISLESSEQUAL
  954. #undef BOOST_CSTDFLOAT_FLOAT128_ISLESSGREATER
  955. #undef BOOST_CSTDFLOAT_FLOAT128_ISUNORDERED
  956. // end more functions
  957. #endif // Not BOOST_CSTDFLOAT_NO_LIBQUADMATH_SUPPORT (i.e., the user would like to have libquadmath support)
  958. #endif // BOOST_MATH_CSTDFLOAT_CMATH_2014_02_15_HPP_