math.h 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP_MATH_H
  10. #define _LIBCPP_MATH_H
  11. /*
  12. math.h synopsis
  13. Macros:
  14. HUGE_VAL
  15. HUGE_VALF // C99
  16. HUGE_VALL // C99
  17. INFINITY // C99
  18. NAN // C99
  19. FP_INFINITE // C99
  20. FP_NAN // C99
  21. FP_NORMAL // C99
  22. FP_SUBNORMAL // C99
  23. FP_ZERO // C99
  24. FP_FAST_FMA // C99
  25. FP_FAST_FMAF // C99
  26. FP_FAST_FMAL // C99
  27. FP_ILOGB0 // C99
  28. FP_ILOGBNAN // C99
  29. MATH_ERRNO // C99
  30. MATH_ERREXCEPT // C99
  31. math_errhandling // C99
  32. Types:
  33. float_t // C99
  34. double_t // C99
  35. // C90
  36. floating_point abs(floating_point x);
  37. floating_point acos (arithmetic x);
  38. float acosf(float x);
  39. long double acosl(long double x);
  40. floating_point asin (arithmetic x);
  41. float asinf(float x);
  42. long double asinl(long double x);
  43. floating_point atan (arithmetic x);
  44. float atanf(float x);
  45. long double atanl(long double x);
  46. floating_point atan2 (arithmetic y, arithmetic x);
  47. float atan2f(float y, float x);
  48. long double atan2l(long double y, long double x);
  49. floating_point ceil (arithmetic x);
  50. float ceilf(float x);
  51. long double ceill(long double x);
  52. floating_point cos (arithmetic x);
  53. float cosf(float x);
  54. long double cosl(long double x);
  55. floating_point cosh (arithmetic x);
  56. float coshf(float x);
  57. long double coshl(long double x);
  58. floating_point exp (arithmetic x);
  59. float expf(float x);
  60. long double expl(long double x);
  61. floating_point fabs (arithmetic x);
  62. float fabsf(float x);
  63. long double fabsl(long double x);
  64. floating_point floor (arithmetic x);
  65. float floorf(float x);
  66. long double floorl(long double x);
  67. floating_point fmod (arithmetic x, arithmetic y);
  68. float fmodf(float x, float y);
  69. long double fmodl(long double x, long double y);
  70. floating_point frexp (arithmetic value, int* exp);
  71. float frexpf(float value, int* exp);
  72. long double frexpl(long double value, int* exp);
  73. floating_point ldexp (arithmetic value, int exp);
  74. float ldexpf(float value, int exp);
  75. long double ldexpl(long double value, int exp);
  76. floating_point log (arithmetic x);
  77. float logf(float x);
  78. long double logl(long double x);
  79. floating_point log10 (arithmetic x);
  80. float log10f(float x);
  81. long double log10l(long double x);
  82. floating_point modf (floating_point value, floating_point* iptr);
  83. float modff(float value, float* iptr);
  84. long double modfl(long double value, long double* iptr);
  85. floating_point pow (arithmetic x, arithmetic y);
  86. float powf(float x, float y);
  87. long double powl(long double x, long double y);
  88. floating_point sin (arithmetic x);
  89. float sinf(float x);
  90. long double sinl(long double x);
  91. floating_point sinh (arithmetic x);
  92. float sinhf(float x);
  93. long double sinhl(long double x);
  94. floating_point sqrt (arithmetic x);
  95. float sqrtf(float x);
  96. long double sqrtl(long double x);
  97. floating_point tan (arithmetic x);
  98. float tanf(float x);
  99. long double tanl(long double x);
  100. floating_point tanh (arithmetic x);
  101. float tanhf(float x);
  102. long double tanhl(long double x);
  103. // C99
  104. bool signbit(arithmetic x);
  105. int fpclassify(arithmetic x);
  106. bool isfinite(arithmetic x);
  107. bool isinf(arithmetic x);
  108. bool isnan(arithmetic x);
  109. bool isnormal(arithmetic x);
  110. bool isgreater(arithmetic x, arithmetic y);
  111. bool isgreaterequal(arithmetic x, arithmetic y);
  112. bool isless(arithmetic x, arithmetic y);
  113. bool islessequal(arithmetic x, arithmetic y);
  114. bool islessgreater(arithmetic x, arithmetic y);
  115. bool isunordered(arithmetic x, arithmetic y);
  116. floating_point acosh (arithmetic x);
  117. float acoshf(float x);
  118. long double acoshl(long double x);
  119. floating_point asinh (arithmetic x);
  120. float asinhf(float x);
  121. long double asinhl(long double x);
  122. floating_point atanh (arithmetic x);
  123. float atanhf(float x);
  124. long double atanhl(long double x);
  125. floating_point cbrt (arithmetic x);
  126. float cbrtf(float x);
  127. long double cbrtl(long double x);
  128. floating_point copysign (arithmetic x, arithmetic y);
  129. float copysignf(float x, float y);
  130. long double copysignl(long double x, long double y);
  131. floating_point erf (arithmetic x);
  132. float erff(float x);
  133. long double erfl(long double x);
  134. floating_point erfc (arithmetic x);
  135. float erfcf(float x);
  136. long double erfcl(long double x);
  137. floating_point exp2 (arithmetic x);
  138. float exp2f(float x);
  139. long double exp2l(long double x);
  140. floating_point expm1 (arithmetic x);
  141. float expm1f(float x);
  142. long double expm1l(long double x);
  143. floating_point fdim (arithmetic x, arithmetic y);
  144. float fdimf(float x, float y);
  145. long double fdiml(long double x, long double y);
  146. floating_point fma (arithmetic x, arithmetic y, arithmetic z);
  147. float fmaf(float x, float y, float z);
  148. long double fmal(long double x, long double y, long double z);
  149. floating_point fmax (arithmetic x, arithmetic y);
  150. float fmaxf(float x, float y);
  151. long double fmaxl(long double x, long double y);
  152. floating_point fmin (arithmetic x, arithmetic y);
  153. float fminf(float x, float y);
  154. long double fminl(long double x, long double y);
  155. floating_point hypot (arithmetic x, arithmetic y);
  156. float hypotf(float x, float y);
  157. long double hypotl(long double x, long double y);
  158. int ilogb (arithmetic x);
  159. int ilogbf(float x);
  160. int ilogbl(long double x);
  161. floating_point lgamma (arithmetic x);
  162. float lgammaf(float x);
  163. long double lgammal(long double x);
  164. long long llrint (arithmetic x);
  165. long long llrintf(float x);
  166. long long llrintl(long double x);
  167. long long llround (arithmetic x);
  168. long long llroundf(float x);
  169. long long llroundl(long double x);
  170. floating_point log1p (arithmetic x);
  171. float log1pf(float x);
  172. long double log1pl(long double x);
  173. floating_point log2 (arithmetic x);
  174. float log2f(float x);
  175. long double log2l(long double x);
  176. floating_point logb (arithmetic x);
  177. float logbf(float x);
  178. long double logbl(long double x);
  179. long lrint (arithmetic x);
  180. long lrintf(float x);
  181. long lrintl(long double x);
  182. long lround (arithmetic x);
  183. long lroundf(float x);
  184. long lroundl(long double x);
  185. double nan (const char* str);
  186. float nanf(const char* str);
  187. long double nanl(const char* str);
  188. floating_point nearbyint (arithmetic x);
  189. float nearbyintf(float x);
  190. long double nearbyintl(long double x);
  191. floating_point nextafter (arithmetic x, arithmetic y);
  192. float nextafterf(float x, float y);
  193. long double nextafterl(long double x, long double y);
  194. floating_point nexttoward (arithmetic x, long double y);
  195. float nexttowardf(float x, long double y);
  196. long double nexttowardl(long double x, long double y);
  197. floating_point remainder (arithmetic x, arithmetic y);
  198. float remainderf(float x, float y);
  199. long double remainderl(long double x, long double y);
  200. floating_point remquo (arithmetic x, arithmetic y, int* pquo);
  201. float remquof(float x, float y, int* pquo);
  202. long double remquol(long double x, long double y, int* pquo);
  203. floating_point rint (arithmetic x);
  204. float rintf(float x);
  205. long double rintl(long double x);
  206. floating_point round (arithmetic x);
  207. float roundf(float x);
  208. long double roundl(long double x);
  209. floating_point scalbln (arithmetic x, long ex);
  210. float scalblnf(float x, long ex);
  211. long double scalblnl(long double x, long ex);
  212. floating_point scalbn (arithmetic x, int ex);
  213. float scalbnf(float x, int ex);
  214. long double scalbnl(long double x, int ex);
  215. floating_point tgamma (arithmetic x);
  216. float tgammaf(float x);
  217. long double tgammal(long double x);
  218. floating_point trunc (arithmetic x);
  219. float truncf(float x);
  220. long double truncl(long double x);
  221. */
  222. #include <__config>
  223. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  224. # pragma GCC system_header
  225. #endif
  226. # if __has_include_next(<math.h>)
  227. # include_next <math.h>
  228. # endif
  229. #ifdef __cplusplus
  230. // We support including .h headers inside 'extern "C"' contexts, so switch
  231. // back to C++ linkage before including these C++ headers.
  232. extern "C++" {
  233. #include <__type_traits/enable_if.h>
  234. #include <__type_traits/is_floating_point.h>
  235. #include <__type_traits/is_integral.h>
  236. #include <__type_traits/is_same.h>
  237. #include <__type_traits/promote.h>
  238. #include <limits>
  239. #include <stdlib.h>
  240. # ifdef fpclassify
  241. # undef fpclassify
  242. # endif
  243. # ifdef signbit
  244. # undef signbit
  245. # endif
  246. # ifdef isfinite
  247. # undef isfinite
  248. # endif
  249. # ifdef isinf
  250. # undef isinf
  251. # endif
  252. # if defined(isnan) && !defined(_LIBCPP_MSVCRT)
  253. # undef isnan
  254. # endif
  255. # ifdef isnormal
  256. # undef isnormal
  257. # endif
  258. # ifdef isgreater
  259. # undef isgreater
  260. # endif
  261. # ifdef isgreaterequal
  262. # undef isgreaterequal
  263. # endif
  264. # ifdef isless
  265. # undef isless
  266. # endif
  267. # ifdef islessequal
  268. # undef islessequal
  269. # endif
  270. # ifdef islessgreater
  271. # undef islessgreater
  272. # endif
  273. # ifdef isunordered
  274. # undef isunordered
  275. # endif
  276. // signbit
  277. template <class _A1, std::__enable_if_t<std::is_floating_point<_A1>::value, int> = 0>
  278. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI bool signbit(_A1 __x) _NOEXCEPT {
  279. return __builtin_signbit(__x);
  280. }
  281. template <class _A1, std::__enable_if_t<std::is_integral<_A1>::value && std::is_signed<_A1>::value, int> = 0>
  282. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI bool signbit(_A1 __x) _NOEXCEPT {
  283. return __x < 0;
  284. }
  285. template <class _A1, std::__enable_if_t<std::is_integral<_A1>::value && !std::is_signed<_A1>::value, int> = 0>
  286. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI bool signbit(_A1) _NOEXCEPT {
  287. return false;
  288. }
  289. // fpclassify
  290. template <class _A1, std::__enable_if_t<std::is_floating_point<_A1>::value, int> = 0>
  291. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI int fpclassify(_A1 __x) _NOEXCEPT {
  292. return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
  293. }
  294. template <class _A1, std::__enable_if_t<std::is_integral<_A1>::value, int> = 0>
  295. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI int fpclassify(_A1 __x) _NOEXCEPT {
  296. return __x == 0 ? FP_ZERO : FP_NORMAL;
  297. }
  298. // The MSVC runtime already provides these functions as templates
  299. #ifndef _LIBCPP_MSVCRT
  300. // isfinite
  301. template <class _A1,
  302. std::__enable_if_t<std::is_arithmetic<_A1>::value && std::numeric_limits<_A1>::has_infinity, int> = 0>
  303. _LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(_A1 __x) _NOEXCEPT {
  304. return __builtin_isfinite((typename std::__promote<_A1>::type)__x);
  305. }
  306. template <class _A1,
  307. std::__enable_if_t<std::is_arithmetic<_A1>::value && !std::numeric_limits<_A1>::has_infinity, int> = 0>
  308. _LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(_A1) _NOEXCEPT {
  309. return true;
  310. }
  311. // isinf
  312. template <class _A1,
  313. std::__enable_if_t<std::is_arithmetic<_A1>::value && std::numeric_limits<_A1>::has_infinity, int> = 0>
  314. _LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isinf(_A1 __x) _NOEXCEPT {
  315. return __builtin_isinf((typename std::__promote<_A1>::type)__x);
  316. }
  317. template <class _A1>
  318. _LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI
  319. typename std::enable_if< std::is_arithmetic<_A1>::value && !std::numeric_limits<_A1>::has_infinity, bool>::type
  320. isinf(_A1) _NOEXCEPT {
  321. return false;
  322. }
  323. #if defined(_LIBCPP_PREFERRED_OVERLOAD) && !defined(__CUDACC__)
  324. _LIBCPP_NODISCARD_EXT inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isinf(float __x) _NOEXCEPT {
  325. return __builtin_isinf(__x);
  326. }
  327. _LIBCPP_NODISCARD_EXT inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD bool isinf(double __x) _NOEXCEPT {
  328. return __builtin_isinf(__x);
  329. }
  330. _LIBCPP_NODISCARD_EXT inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isinf(long double __x) _NOEXCEPT {
  331. return __builtin_isinf(__x);
  332. }
  333. # endif
  334. // isnan
  335. template <class _A1, std::__enable_if_t<std::is_floating_point<_A1>::value, int> = 0>
  336. _LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnan(_A1 __x) _NOEXCEPT {
  337. return __builtin_isnan(__x);
  338. }
  339. template <class _A1, std::__enable_if_t<std::is_integral<_A1>::value, int> = 0>
  340. _LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnan(_A1) _NOEXCEPT {
  341. return false;
  342. }
  343. #if defined(_LIBCPP_PREFERRED_OVERLOAD) && !defined(__CUDACC__)
  344. _LIBCPP_NODISCARD_EXT inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnan(float __x) _NOEXCEPT {
  345. return __builtin_isnan(__x);
  346. }
  347. _LIBCPP_NODISCARD_EXT inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD bool isnan(double __x) _NOEXCEPT {
  348. return __builtin_isnan(__x);
  349. }
  350. _LIBCPP_NODISCARD_EXT inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnan(long double __x) _NOEXCEPT {
  351. return __builtin_isnan(__x);
  352. }
  353. # endif
  354. // isnormal
  355. template <class _A1, std::__enable_if_t<std::is_floating_point<_A1>::value, int> = 0>
  356. _LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnormal(_A1 __x) _NOEXCEPT {
  357. return __builtin_isnormal(__x);
  358. }
  359. template <class _A1, std::__enable_if_t<std::is_integral<_A1>::value, int> = 0>
  360. _LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnormal(_A1 __x) _NOEXCEPT {
  361. return __x != 0;
  362. }
  363. // isgreater
  364. template <class _A1,
  365. class _A2,
  366. std::__enable_if_t<std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, int> = 0>
  367. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI bool isgreater(_A1 __x, _A2 __y) _NOEXCEPT {
  368. typedef typename std::__promote<_A1, _A2>::type type;
  369. return __builtin_isgreater((type)__x, (type)__y);
  370. }
  371. // isgreaterequal
  372. template <class _A1,
  373. class _A2,
  374. std::__enable_if_t<std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, int> = 0>
  375. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI bool isgreaterequal(_A1 __x, _A2 __y) _NOEXCEPT {
  376. typedef typename std::__promote<_A1, _A2>::type type;
  377. return __builtin_isgreaterequal((type)__x, (type)__y);
  378. }
  379. // isless
  380. template <class _A1,
  381. class _A2,
  382. std::__enable_if_t<std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, int> = 0>
  383. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI bool isless(_A1 __x, _A2 __y) _NOEXCEPT {
  384. typedef typename std::__promote<_A1, _A2>::type type;
  385. return __builtin_isless((type)__x, (type)__y);
  386. }
  387. // islessequal
  388. template <class _A1,
  389. class _A2,
  390. std::__enable_if_t<std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, int> = 0>
  391. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI bool islessequal(_A1 __x, _A2 __y) _NOEXCEPT {
  392. typedef typename std::__promote<_A1, _A2>::type type;
  393. return __builtin_islessequal((type)__x, (type)__y);
  394. }
  395. // islessgreater
  396. template <class _A1,
  397. class _A2,
  398. std::__enable_if_t<std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, int> = 0>
  399. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI bool islessgreater(_A1 __x, _A2 __y) _NOEXCEPT {
  400. typedef typename std::__promote<_A1, _A2>::type type;
  401. return __builtin_islessgreater((type)__x, (type)__y);
  402. }
  403. // isunordered
  404. template <class _A1,
  405. class _A2,
  406. std::__enable_if_t<std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, int> = 0>
  407. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI bool isunordered(_A1 __x, _A2 __y) _NOEXCEPT {
  408. typedef typename std::__promote<_A1, _A2>::type type;
  409. return __builtin_isunordered((type)__x, (type)__y);
  410. }
  411. #endif // _LIBCPP_MSVCRT
  412. // abs
  413. //
  414. // handled in stdlib.h
  415. // div
  416. //
  417. // handled in stdlib.h
  418. // We have to provide double overloads for <math.h> to work on platforms that don't provide the full set of math
  419. // functions. To make the overload set work with multiple functions that take the same arguments, we make our overloads
  420. // templates. Functions are preferred over function templates during overload resolution, which means that our overload
  421. // will only be selected when the C library doesn't provide one.
  422. // acos
  423. # if !defined(__sun__)
  424. inline _LIBCPP_HIDE_FROM_ABI float acos(float __x) _NOEXCEPT {return __builtin_acosf(__x);}
  425. template <class = int>
  426. _LIBCPP_HIDE_FROM_ABI double acos(double __x) _NOEXCEPT {
  427. return __builtin_acos(__x);
  428. }
  429. inline _LIBCPP_HIDE_FROM_ABI long double acos(long double __x) _NOEXCEPT {return __builtin_acosl(__x);}
  430. # endif
  431. template <class _A1>
  432. inline _LIBCPP_HIDE_FROM_ABI
  433. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  434. acos(_A1 __x) _NOEXCEPT {return __builtin_acos((double)__x);}
  435. // asin
  436. # if !defined(__sun__)
  437. inline _LIBCPP_HIDE_FROM_ABI float asin(float __x) _NOEXCEPT {return __builtin_asinf(__x);}
  438. template <class = int>
  439. _LIBCPP_HIDE_FROM_ABI double asin(double __x) _NOEXCEPT {
  440. return __builtin_asin(__x);
  441. }
  442. inline _LIBCPP_HIDE_FROM_ABI long double asin(long double __x) _NOEXCEPT {return __builtin_asinl(__x);}
  443. # endif
  444. template <class _A1>
  445. inline _LIBCPP_HIDE_FROM_ABI
  446. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  447. asin(_A1 __x) _NOEXCEPT {return __builtin_asin((double)__x);}
  448. // atan
  449. # if !defined(__sun__)
  450. inline _LIBCPP_HIDE_FROM_ABI float atan(float __x) _NOEXCEPT {return __builtin_atanf(__x);}
  451. template <class = int>
  452. _LIBCPP_HIDE_FROM_ABI double atan(double __x) _NOEXCEPT {
  453. return __builtin_atan(__x);
  454. }
  455. inline _LIBCPP_HIDE_FROM_ABI long double atan(long double __x) _NOEXCEPT {return __builtin_atanl(__x);}
  456. # endif
  457. template <class _A1>
  458. inline _LIBCPP_HIDE_FROM_ABI
  459. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  460. atan(_A1 __x) _NOEXCEPT {return __builtin_atan((double)__x);}
  461. // atan2
  462. # if !defined(__sun__)
  463. inline _LIBCPP_HIDE_FROM_ABI float atan2(float __y, float __x) _NOEXCEPT {return __builtin_atan2f(__y, __x);}
  464. template <class = int>
  465. _LIBCPP_HIDE_FROM_ABI double atan2(double __x, double __y) _NOEXCEPT {
  466. return __builtin_atan2(__x, __y);
  467. }
  468. inline _LIBCPP_HIDE_FROM_ABI long double atan2(long double __y, long double __x) _NOEXCEPT {return __builtin_atan2l(__y, __x);}
  469. # endif
  470. template <class _A1, class _A2>
  471. inline _LIBCPP_HIDE_FROM_ABI
  472. typename std::__enable_if_t
  473. <
  474. std::is_arithmetic<_A1>::value &&
  475. std::is_arithmetic<_A2>::value,
  476. std::__promote<_A1, _A2>
  477. >::type
  478. atan2(_A1 __y, _A2 __x) _NOEXCEPT
  479. {
  480. typedef typename std::__promote<_A1, _A2>::type __result_type;
  481. static_assert((!(std::_IsSame<_A1, __result_type>::value &&
  482. std::_IsSame<_A2, __result_type>::value)), "");
  483. return ::atan2((__result_type)__y, (__result_type)__x);
  484. }
  485. // ceil
  486. # if !defined(__sun__)
  487. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI float ceil(float __x) _NOEXCEPT {return __builtin_ceilf(__x);}
  488. template <class = int>
  489. _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI double ceil(double __x) _NOEXCEPT {
  490. return __builtin_ceil(__x);
  491. }
  492. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI long double ceil(long double __x) _NOEXCEPT {return __builtin_ceill(__x);}
  493. # endif
  494. template <class _A1>
  495. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI
  496. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  497. ceil(_A1 __x) _NOEXCEPT {return __builtin_ceil((double)__x);}
  498. // cos
  499. # if !defined(__sun__)
  500. inline _LIBCPP_HIDE_FROM_ABI float cos(float __x) _NOEXCEPT {return __builtin_cosf(__x);}
  501. template <class = int>
  502. _LIBCPP_HIDE_FROM_ABI double cos(double __x) _NOEXCEPT {
  503. return __builtin_cos(__x);
  504. }
  505. inline _LIBCPP_HIDE_FROM_ABI long double cos(long double __x) _NOEXCEPT {return __builtin_cosl(__x);}
  506. # endif
  507. template <class _A1>
  508. inline _LIBCPP_HIDE_FROM_ABI
  509. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  510. cos(_A1 __x) _NOEXCEPT {return __builtin_cos((double)__x);}
  511. // cosh
  512. # if !defined(__sun__)
  513. inline _LIBCPP_HIDE_FROM_ABI float cosh(float __x) _NOEXCEPT {return __builtin_coshf(__x);}
  514. template <class = int>
  515. _LIBCPP_HIDE_FROM_ABI double cosh(double __x) _NOEXCEPT {
  516. return __builtin_cosh(__x);
  517. }
  518. inline _LIBCPP_HIDE_FROM_ABI long double cosh(long double __x) _NOEXCEPT {return __builtin_coshl(__x);}
  519. # endif
  520. template <class _A1>
  521. inline _LIBCPP_HIDE_FROM_ABI
  522. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  523. cosh(_A1 __x) _NOEXCEPT {return __builtin_cosh((double)__x);}
  524. // exp
  525. # if !defined(__sun__)
  526. inline _LIBCPP_HIDE_FROM_ABI float exp(float __x) _NOEXCEPT {return __builtin_expf(__x);}
  527. template <class = int>
  528. _LIBCPP_HIDE_FROM_ABI double exp(double __x) _NOEXCEPT {
  529. return __builtin_exp(__x);
  530. }
  531. inline _LIBCPP_HIDE_FROM_ABI long double exp(long double __x) _NOEXCEPT {return __builtin_expl(__x);}
  532. # endif
  533. template <class _A1>
  534. inline _LIBCPP_HIDE_FROM_ABI
  535. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  536. exp(_A1 __x) _NOEXCEPT {return __builtin_exp((double)__x);}
  537. // fabs
  538. # if !defined(__sun__)
  539. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI float fabs(float __x) _NOEXCEPT {return __builtin_fabsf(__x);}
  540. template <class = int>
  541. _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI double fabs(double __x) _NOEXCEPT {
  542. return __builtin_fabs(__x);
  543. }
  544. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI long double fabs(long double __x) _NOEXCEPT {return __builtin_fabsl(__x);}
  545. # endif
  546. template <class _A1>
  547. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI
  548. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  549. fabs(_A1 __x) _NOEXCEPT {return __builtin_fabs((double)__x);}
  550. // floor
  551. # if !defined(__sun__)
  552. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI float floor(float __x) _NOEXCEPT {return __builtin_floorf(__x);}
  553. template <class = int>
  554. _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI double floor(double __x) _NOEXCEPT {
  555. return __builtin_floor(__x);
  556. }
  557. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI long double floor(long double __x) _NOEXCEPT {return __builtin_floorl(__x);}
  558. # endif
  559. template <class _A1>
  560. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI
  561. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  562. floor(_A1 __x) _NOEXCEPT {return __builtin_floor((double)__x);}
  563. // fmod
  564. # if !defined(__sun__)
  565. inline _LIBCPP_HIDE_FROM_ABI float fmod(float __x, float __y) _NOEXCEPT {return __builtin_fmodf(__x, __y);}
  566. template <class = int>
  567. _LIBCPP_HIDE_FROM_ABI double fmod(double __x, double __y) _NOEXCEPT {
  568. return __builtin_fmod(__x, __y);
  569. }
  570. inline _LIBCPP_HIDE_FROM_ABI long double fmod(long double __x, long double __y) _NOEXCEPT {return __builtin_fmodl(__x, __y);}
  571. # endif
  572. template <class _A1, class _A2>
  573. inline _LIBCPP_HIDE_FROM_ABI
  574. typename std::__enable_if_t
  575. <
  576. std::is_arithmetic<_A1>::value &&
  577. std::is_arithmetic<_A2>::value,
  578. std::__promote<_A1, _A2>
  579. >::type
  580. fmod(_A1 __x, _A2 __y) _NOEXCEPT
  581. {
  582. typedef typename std::__promote<_A1, _A2>::type __result_type;
  583. static_assert((!(std::_IsSame<_A1, __result_type>::value &&
  584. std::_IsSame<_A2, __result_type>::value)), "");
  585. return ::fmod((__result_type)__x, (__result_type)__y);
  586. }
  587. // frexp
  588. # if !defined(__sun__)
  589. inline _LIBCPP_HIDE_FROM_ABI float frexp(float __x, int* __e) _NOEXCEPT {return __builtin_frexpf(__x, __e);}
  590. template <class = int>
  591. _LIBCPP_HIDE_FROM_ABI double frexp(double __x, int* __e) _NOEXCEPT {
  592. return __builtin_frexp(__x, __e);
  593. }
  594. inline _LIBCPP_HIDE_FROM_ABI long double frexp(long double __x, int* __e) _NOEXCEPT {return __builtin_frexpl(__x, __e);}
  595. # endif
  596. template <class _A1>
  597. inline _LIBCPP_HIDE_FROM_ABI
  598. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  599. frexp(_A1 __x, int* __e) _NOEXCEPT {return __builtin_frexp((double)__x, __e);}
  600. // ldexp
  601. # if !defined(__sun__)
  602. inline _LIBCPP_HIDE_FROM_ABI float ldexp(float __x, int __e) _NOEXCEPT {return __builtin_ldexpf(__x, __e);}
  603. template <class = int>
  604. _LIBCPP_HIDE_FROM_ABI double ldexp(double __x, int __e) _NOEXCEPT {
  605. return __builtin_ldexp(__x, __e);
  606. }
  607. inline _LIBCPP_HIDE_FROM_ABI long double ldexp(long double __x, int __e) _NOEXCEPT {return __builtin_ldexpl(__x, __e);}
  608. # endif
  609. template <class _A1>
  610. inline _LIBCPP_HIDE_FROM_ABI
  611. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  612. ldexp(_A1 __x, int __e) _NOEXCEPT {return __builtin_ldexp((double)__x, __e);}
  613. // log
  614. # if !defined(__sun__)
  615. inline _LIBCPP_HIDE_FROM_ABI float log(float __x) _NOEXCEPT {return __builtin_logf(__x);}
  616. template <class = int>
  617. _LIBCPP_HIDE_FROM_ABI double log(double __x) _NOEXCEPT {
  618. return __builtin_log(__x);
  619. }
  620. inline _LIBCPP_HIDE_FROM_ABI long double log(long double __x) _NOEXCEPT {return __builtin_logl(__x);}
  621. # endif
  622. template <class _A1>
  623. inline _LIBCPP_HIDE_FROM_ABI
  624. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  625. log(_A1 __x) _NOEXCEPT {return __builtin_log((double)__x);}
  626. // log10
  627. # if !defined(__sun__)
  628. inline _LIBCPP_HIDE_FROM_ABI float log10(float __x) _NOEXCEPT {return __builtin_log10f(__x);}
  629. template <class = int>
  630. _LIBCPP_HIDE_FROM_ABI double log10(double __x) _NOEXCEPT {
  631. return __builtin_log10(__x);
  632. }
  633. inline _LIBCPP_HIDE_FROM_ABI long double log10(long double __x) _NOEXCEPT {return __builtin_log10l(__x);}
  634. # endif
  635. template <class _A1>
  636. inline _LIBCPP_HIDE_FROM_ABI
  637. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  638. log10(_A1 __x) _NOEXCEPT {return __builtin_log10((double)__x);}
  639. // modf
  640. # if !defined(__sun__)
  641. inline _LIBCPP_HIDE_FROM_ABI float modf(float __x, float* __y) _NOEXCEPT {return __builtin_modff(__x, __y);}
  642. template <class = int>
  643. _LIBCPP_HIDE_FROM_ABI double modf(double __x, double* __y) _NOEXCEPT {
  644. return __builtin_modf(__x, __y);
  645. }
  646. inline _LIBCPP_HIDE_FROM_ABI long double modf(long double __x, long double* __y) _NOEXCEPT {return __builtin_modfl(__x, __y);}
  647. # endif
  648. // pow
  649. # if !defined(__sun__)
  650. inline _LIBCPP_HIDE_FROM_ABI float pow(float __x, float __y) _NOEXCEPT {return __builtin_powf(__x, __y);}
  651. template <class = int>
  652. _LIBCPP_HIDE_FROM_ABI double pow(double __x, double __y) _NOEXCEPT {
  653. return __builtin_pow(__x, __y);
  654. }
  655. inline _LIBCPP_HIDE_FROM_ABI long double pow(long double __x, long double __y) _NOEXCEPT {return __builtin_powl(__x, __y);}
  656. # endif
  657. template <class _A1, class _A2>
  658. inline _LIBCPP_HIDE_FROM_ABI
  659. typename std::__enable_if_t
  660. <
  661. std::is_arithmetic<_A1>::value &&
  662. std::is_arithmetic<_A2>::value,
  663. std::__promote<_A1, _A2>
  664. >::type
  665. pow(_A1 __x, _A2 __y) _NOEXCEPT
  666. {
  667. typedef typename std::__promote<_A1, _A2>::type __result_type;
  668. static_assert((!(std::_IsSame<_A1, __result_type>::value &&
  669. std::_IsSame<_A2, __result_type>::value)), "");
  670. return ::pow((__result_type)__x, (__result_type)__y);
  671. }
  672. // sin
  673. # if !defined(__sun__)
  674. inline _LIBCPP_HIDE_FROM_ABI float sin(float __x) _NOEXCEPT {return __builtin_sinf(__x);}
  675. template <class = int>
  676. _LIBCPP_HIDE_FROM_ABI double sin(double __x) _NOEXCEPT {
  677. return __builtin_sin(__x);
  678. }
  679. inline _LIBCPP_HIDE_FROM_ABI long double sin(long double __x) _NOEXCEPT {return __builtin_sinl(__x);}
  680. #endif
  681. template <class _A1>
  682. inline _LIBCPP_HIDE_FROM_ABI
  683. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  684. sin(_A1 __x) _NOEXCEPT {return __builtin_sin((double)__x);}
  685. // sinh
  686. # if !defined(__sun__)
  687. inline _LIBCPP_HIDE_FROM_ABI float sinh(float __x) _NOEXCEPT {return __builtin_sinhf(__x);}
  688. template <class = int>
  689. _LIBCPP_HIDE_FROM_ABI double sinh(double __x) _NOEXCEPT {
  690. return __builtin_sinh(__x);
  691. }
  692. inline _LIBCPP_HIDE_FROM_ABI long double sinh(long double __x) _NOEXCEPT {return __builtin_sinhl(__x);}
  693. # endif
  694. template <class _A1>
  695. inline _LIBCPP_HIDE_FROM_ABI
  696. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  697. sinh(_A1 __x) _NOEXCEPT {return __builtin_sinh((double)__x);}
  698. // sqrt
  699. # if !defined(__sun__)
  700. inline _LIBCPP_HIDE_FROM_ABI float sqrt(float __x) _NOEXCEPT {return __builtin_sqrtf(__x);}
  701. template <class = int>
  702. _LIBCPP_HIDE_FROM_ABI double sqrt(double __x) _NOEXCEPT {
  703. return __builtin_sqrt(__x);
  704. }
  705. inline _LIBCPP_HIDE_FROM_ABI long double sqrt(long double __x) _NOEXCEPT {return __builtin_sqrtl(__x);}
  706. # endif
  707. template <class _A1>
  708. inline _LIBCPP_HIDE_FROM_ABI
  709. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  710. sqrt(_A1 __x) _NOEXCEPT {return __builtin_sqrt((double)__x);}
  711. // tan
  712. # if !defined(__sun__)
  713. inline _LIBCPP_HIDE_FROM_ABI float tan(float __x) _NOEXCEPT {return __builtin_tanf(__x);}
  714. template <class = int>
  715. _LIBCPP_HIDE_FROM_ABI double tan(double __x) _NOEXCEPT {
  716. return __builtin_tan(__x);
  717. }
  718. inline _LIBCPP_HIDE_FROM_ABI long double tan(long double __x) _NOEXCEPT {return __builtin_tanl(__x);}
  719. # endif
  720. template <class _A1>
  721. inline _LIBCPP_HIDE_FROM_ABI
  722. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  723. tan(_A1 __x) _NOEXCEPT {return __builtin_tan((double)__x);}
  724. // tanh
  725. # if !defined(__sun__)
  726. inline _LIBCPP_HIDE_FROM_ABI float tanh(float __x) _NOEXCEPT {return __builtin_tanhf(__x);}
  727. template <class = int>
  728. _LIBCPP_HIDE_FROM_ABI double tanh(double __x) _NOEXCEPT {
  729. return __builtin_tanh(__x);
  730. }
  731. inline _LIBCPP_HIDE_FROM_ABI long double tanh(long double __x) _NOEXCEPT {return __builtin_tanhl(__x);}
  732. # endif
  733. template <class _A1>
  734. inline _LIBCPP_HIDE_FROM_ABI
  735. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  736. tanh(_A1 __x) _NOEXCEPT {return __builtin_tanh((double)__x);}
  737. // acosh
  738. inline _LIBCPP_HIDE_FROM_ABI float acosh(float __x) _NOEXCEPT {return __builtin_acoshf(__x);}
  739. template <class = int>
  740. _LIBCPP_HIDE_FROM_ABI double acosh(double __x) _NOEXCEPT {
  741. return __builtin_acosh(__x);
  742. }
  743. inline _LIBCPP_HIDE_FROM_ABI long double acosh(long double __x) _NOEXCEPT {return __builtin_acoshl(__x);}
  744. template <class _A1>
  745. inline _LIBCPP_HIDE_FROM_ABI
  746. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  747. acosh(_A1 __x) _NOEXCEPT {return __builtin_acosh((double)__x);}
  748. // asinh
  749. inline _LIBCPP_HIDE_FROM_ABI float asinh(float __x) _NOEXCEPT {return __builtin_asinhf(__x);}
  750. template <class = int>
  751. _LIBCPP_HIDE_FROM_ABI double asinh(double __x) _NOEXCEPT {
  752. return __builtin_asinh(__x);
  753. }
  754. inline _LIBCPP_HIDE_FROM_ABI long double asinh(long double __x) _NOEXCEPT {return __builtin_asinhl(__x);}
  755. template <class _A1>
  756. inline _LIBCPP_HIDE_FROM_ABI
  757. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  758. asinh(_A1 __x) _NOEXCEPT {return __builtin_asinh((double)__x);}
  759. // atanh
  760. inline _LIBCPP_HIDE_FROM_ABI float atanh(float __x) _NOEXCEPT {return __builtin_atanhf(__x);}
  761. template <class = int>
  762. _LIBCPP_HIDE_FROM_ABI double atanh(double __x) _NOEXCEPT {
  763. return __builtin_atanh(__x);
  764. }
  765. inline _LIBCPP_HIDE_FROM_ABI long double atanh(long double __x) _NOEXCEPT {return __builtin_atanhl(__x);}
  766. template <class _A1>
  767. inline _LIBCPP_HIDE_FROM_ABI
  768. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  769. atanh(_A1 __x) _NOEXCEPT {return __builtin_atanh((double)__x);}
  770. // cbrt
  771. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI float cbrt(float __x) _NOEXCEPT {return __builtin_cbrtf(__x);}
  772. template <class = int>
  773. _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI double cbrt(double __x) _NOEXCEPT {
  774. return __builtin_cbrt(__x);
  775. }
  776. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI long double cbrt(long double __x) _NOEXCEPT {return __builtin_cbrtl(__x);}
  777. template <class _A1>
  778. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI
  779. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  780. cbrt(_A1 __x) _NOEXCEPT {return __builtin_cbrt((double)__x);}
  781. // copysign
  782. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI float copysign(float __x, float __y) _NOEXCEPT {
  783. return ::__builtin_copysignf(__x, __y);
  784. }
  785. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI long double copysign(long double __x, long double __y) _NOEXCEPT {
  786. return ::__builtin_copysignl(__x, __y);
  787. }
  788. template <class _A1, class _A2>
  789. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI
  790. typename std::__enable_if_t
  791. <
  792. std::is_arithmetic<_A1>::value &&
  793. std::is_arithmetic<_A2>::value,
  794. std::__promote<_A1, _A2>
  795. >::type
  796. copysign(_A1 __x, _A2 __y) _NOEXCEPT {
  797. return ::__builtin_copysign(__x, __y);
  798. }
  799. // erf
  800. inline _LIBCPP_HIDE_FROM_ABI float erf(float __x) _NOEXCEPT {return __builtin_erff(__x);}
  801. template <class = int>
  802. _LIBCPP_HIDE_FROM_ABI double erf(double __x) _NOEXCEPT {
  803. return __builtin_erf(__x);
  804. }
  805. inline _LIBCPP_HIDE_FROM_ABI long double erf(long double __x) _NOEXCEPT {return __builtin_erfl(__x);}
  806. template <class _A1>
  807. inline _LIBCPP_HIDE_FROM_ABI
  808. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  809. erf(_A1 __x) _NOEXCEPT {return __builtin_erf((double)__x);}
  810. // erfc
  811. inline _LIBCPP_HIDE_FROM_ABI float erfc(float __x) _NOEXCEPT {return __builtin_erfcf(__x);}
  812. template <class = int>
  813. _LIBCPP_HIDE_FROM_ABI double erfc(double __x) _NOEXCEPT {
  814. return __builtin_erfc(__x);
  815. }
  816. inline _LIBCPP_HIDE_FROM_ABI long double erfc(long double __x) _NOEXCEPT {return __builtin_erfcl(__x);}
  817. template <class _A1>
  818. inline _LIBCPP_HIDE_FROM_ABI
  819. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  820. erfc(_A1 __x) _NOEXCEPT {return __builtin_erfc((double)__x);}
  821. // exp2
  822. inline _LIBCPP_HIDE_FROM_ABI float exp2(float __x) _NOEXCEPT {return __builtin_exp2f(__x);}
  823. template <class = int>
  824. _LIBCPP_HIDE_FROM_ABI double exp2(double __x) _NOEXCEPT {
  825. return __builtin_exp2(__x);
  826. }
  827. inline _LIBCPP_HIDE_FROM_ABI long double exp2(long double __x) _NOEXCEPT {return __builtin_exp2l(__x);}
  828. template <class _A1>
  829. inline _LIBCPP_HIDE_FROM_ABI
  830. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  831. exp2(_A1 __x) _NOEXCEPT {return __builtin_exp2((double)__x);}
  832. // expm1
  833. inline _LIBCPP_HIDE_FROM_ABI float expm1(float __x) _NOEXCEPT {return __builtin_expm1f(__x);}
  834. template <class = int>
  835. _LIBCPP_HIDE_FROM_ABI double expm1(double __x) _NOEXCEPT {
  836. return __builtin_expm1(__x);
  837. }
  838. inline _LIBCPP_HIDE_FROM_ABI long double expm1(long double __x) _NOEXCEPT {return __builtin_expm1l(__x);}
  839. template <class _A1>
  840. inline _LIBCPP_HIDE_FROM_ABI
  841. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  842. expm1(_A1 __x) _NOEXCEPT {return __builtin_expm1((double)__x);}
  843. // fdim
  844. inline _LIBCPP_HIDE_FROM_ABI float fdim(float __x, float __y) _NOEXCEPT {return __builtin_fdimf(__x, __y);}
  845. template <class = int>
  846. _LIBCPP_HIDE_FROM_ABI double fdim(double __x, double __y) _NOEXCEPT {
  847. return __builtin_fdim(__x, __y);
  848. }
  849. inline _LIBCPP_HIDE_FROM_ABI long double fdim(long double __x, long double __y) _NOEXCEPT {return __builtin_fdiml(__x, __y);}
  850. template <class _A1, class _A2>
  851. inline _LIBCPP_HIDE_FROM_ABI
  852. typename std::__enable_if_t
  853. <
  854. std::is_arithmetic<_A1>::value &&
  855. std::is_arithmetic<_A2>::value,
  856. std::__promote<_A1, _A2>
  857. >::type
  858. fdim(_A1 __x, _A2 __y) _NOEXCEPT
  859. {
  860. typedef typename std::__promote<_A1, _A2>::type __result_type;
  861. static_assert((!(std::_IsSame<_A1, __result_type>::value &&
  862. std::_IsSame<_A2, __result_type>::value)), "");
  863. return ::fdim((__result_type)__x, (__result_type)__y);
  864. }
  865. // fma
  866. inline _LIBCPP_HIDE_FROM_ABI float fma(float __x, float __y, float __z) _NOEXCEPT
  867. {
  868. return __builtin_fmaf(__x, __y, __z);
  869. }
  870. template <class = int>
  871. _LIBCPP_HIDE_FROM_ABI double fma(double __x, double __y, double __z) _NOEXCEPT {
  872. return __builtin_fma(__x, __y, __z);
  873. }
  874. inline _LIBCPP_HIDE_FROM_ABI long double fma(long double __x, long double __y, long double __z) _NOEXCEPT
  875. {
  876. return __builtin_fmal(__x, __y, __z);
  877. }
  878. template <class _A1, class _A2, class _A3>
  879. inline _LIBCPP_HIDE_FROM_ABI
  880. typename std::__enable_if_t
  881. <
  882. std::is_arithmetic<_A1>::value &&
  883. std::is_arithmetic<_A2>::value &&
  884. std::is_arithmetic<_A3>::value,
  885. std::__promote<_A1, _A2, _A3>
  886. >::type
  887. fma(_A1 __x, _A2 __y, _A3 __z) _NOEXCEPT
  888. {
  889. typedef typename std::__promote<_A1, _A2, _A3>::type __result_type;
  890. static_assert((!(std::_IsSame<_A1, __result_type>::value &&
  891. std::_IsSame<_A2, __result_type>::value &&
  892. std::_IsSame<_A3, __result_type>::value)), "");
  893. return __builtin_fma((__result_type)__x, (__result_type)__y, (__result_type)__z);
  894. }
  895. // fmax
  896. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI float fmax(float __x, float __y) _NOEXCEPT {return __builtin_fmaxf(__x, __y);}
  897. template <class = int>
  898. _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI double fmax(double __x, double __y) _NOEXCEPT {
  899. return __builtin_fmax(__x, __y);
  900. }
  901. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI long double fmax(long double __x, long double __y) _NOEXCEPT {return __builtin_fmaxl(__x, __y);}
  902. template <class _A1, class _A2>
  903. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI
  904. typename std::__enable_if_t
  905. <
  906. std::is_arithmetic<_A1>::value &&
  907. std::is_arithmetic<_A2>::value,
  908. std::__promote<_A1, _A2>
  909. >::type
  910. fmax(_A1 __x, _A2 __y) _NOEXCEPT
  911. {
  912. typedef typename std::__promote<_A1, _A2>::type __result_type;
  913. static_assert((!(std::_IsSame<_A1, __result_type>::value &&
  914. std::_IsSame<_A2, __result_type>::value)), "");
  915. return ::fmax((__result_type)__x, (__result_type)__y);
  916. }
  917. // fmin
  918. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI float fmin(float __x, float __y) _NOEXCEPT {return __builtin_fminf(__x, __y);}
  919. template <class = int>
  920. _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI double fmin(double __x, double __y) _NOEXCEPT {
  921. return __builtin_fmin(__x, __y);
  922. }
  923. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI long double fmin(long double __x, long double __y) _NOEXCEPT {return __builtin_fminl(__x, __y);}
  924. template <class _A1, class _A2>
  925. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI
  926. typename std::__enable_if_t
  927. <
  928. std::is_arithmetic<_A1>::value &&
  929. std::is_arithmetic<_A2>::value,
  930. std::__promote<_A1, _A2>
  931. >::type
  932. fmin(_A1 __x, _A2 __y) _NOEXCEPT
  933. {
  934. typedef typename std::__promote<_A1, _A2>::type __result_type;
  935. static_assert((!(std::_IsSame<_A1, __result_type>::value &&
  936. std::_IsSame<_A2, __result_type>::value)), "");
  937. return ::fmin((__result_type)__x, (__result_type)__y);
  938. }
  939. // hypot
  940. inline _LIBCPP_HIDE_FROM_ABI float hypot(float __x, float __y) _NOEXCEPT {return __builtin_hypotf(__x, __y);}
  941. template <class = int>
  942. _LIBCPP_HIDE_FROM_ABI double hypot(double __x, double __y) _NOEXCEPT {
  943. return __builtin_hypot(__x, __y);
  944. }
  945. inline _LIBCPP_HIDE_FROM_ABI long double hypot(long double __x, long double __y) _NOEXCEPT {return __builtin_hypotl(__x, __y);}
  946. template <class _A1, class _A2>
  947. inline _LIBCPP_HIDE_FROM_ABI
  948. typename std::__enable_if_t
  949. <
  950. std::is_arithmetic<_A1>::value &&
  951. std::is_arithmetic<_A2>::value,
  952. std::__promote<_A1, _A2>
  953. >::type
  954. hypot(_A1 __x, _A2 __y) _NOEXCEPT
  955. {
  956. typedef typename std::__promote<_A1, _A2>::type __result_type;
  957. static_assert((!(std::_IsSame<_A1, __result_type>::value &&
  958. std::_IsSame<_A2, __result_type>::value)), "");
  959. return ::hypot((__result_type)__x, (__result_type)__y);
  960. }
  961. // ilogb
  962. inline _LIBCPP_HIDE_FROM_ABI int ilogb(float __x) _NOEXCEPT {return __builtin_ilogbf(__x);}
  963. template <class = int>
  964. _LIBCPP_HIDE_FROM_ABI double ilogb(double __x) _NOEXCEPT {
  965. return __builtin_ilogb(__x);
  966. }
  967. inline _LIBCPP_HIDE_FROM_ABI int ilogb(long double __x) _NOEXCEPT {return __builtin_ilogbl(__x);}
  968. template <class _A1>
  969. inline _LIBCPP_HIDE_FROM_ABI
  970. typename std::enable_if<std::is_integral<_A1>::value, int>::type
  971. ilogb(_A1 __x) _NOEXCEPT {return __builtin_ilogb((double)__x);}
  972. // lgamma
  973. inline _LIBCPP_HIDE_FROM_ABI float lgamma(float __x) _NOEXCEPT {return __builtin_lgammaf(__x);}
  974. template <class = int>
  975. _LIBCPP_HIDE_FROM_ABI double lgamma(double __x) _NOEXCEPT {
  976. return __builtin_lgamma(__x);
  977. }
  978. inline _LIBCPP_HIDE_FROM_ABI long double lgamma(long double __x) _NOEXCEPT {return __builtin_lgammal(__x);}
  979. template <class _A1>
  980. inline _LIBCPP_HIDE_FROM_ABI
  981. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  982. lgamma(_A1 __x) _NOEXCEPT {return __builtin_lgamma((double)__x);}
  983. // llrint
  984. inline _LIBCPP_HIDE_FROM_ABI long long llrint(float __x) _NOEXCEPT
  985. {
  986. return __builtin_llrintf(__x);
  987. }
  988. template <class = int>
  989. _LIBCPP_HIDE_FROM_ABI long long llrint(double __x) _NOEXCEPT {
  990. return __builtin_llrint(__x);
  991. }
  992. inline _LIBCPP_HIDE_FROM_ABI long long llrint(long double __x) _NOEXCEPT
  993. {
  994. return __builtin_llrintl(__x);
  995. }
  996. template <class _A1>
  997. inline _LIBCPP_HIDE_FROM_ABI
  998. typename std::enable_if<std::is_integral<_A1>::value, long long>::type
  999. llrint(_A1 __x) _NOEXCEPT
  1000. {
  1001. return __builtin_llrint((double)__x);
  1002. }
  1003. // llround
  1004. inline _LIBCPP_HIDE_FROM_ABI long long llround(float __x) _NOEXCEPT
  1005. {
  1006. return __builtin_llroundf(__x);
  1007. }
  1008. template <class = int>
  1009. _LIBCPP_HIDE_FROM_ABI long long llround(double __x) _NOEXCEPT {
  1010. return __builtin_llround(__x);
  1011. }
  1012. inline _LIBCPP_HIDE_FROM_ABI long long llround(long double __x) _NOEXCEPT
  1013. {
  1014. return __builtin_llroundl(__x);
  1015. }
  1016. template <class _A1>
  1017. inline _LIBCPP_HIDE_FROM_ABI
  1018. typename std::enable_if<std::is_integral<_A1>::value, long long>::type
  1019. llround(_A1 __x) _NOEXCEPT
  1020. {
  1021. return __builtin_llround((double)__x);
  1022. }
  1023. // log1p
  1024. inline _LIBCPP_HIDE_FROM_ABI float log1p(float __x) _NOEXCEPT {return __builtin_log1pf(__x);}
  1025. template <class = int>
  1026. _LIBCPP_HIDE_FROM_ABI double log1p(double __x) _NOEXCEPT {
  1027. return __builtin_log1p(__x);
  1028. }
  1029. inline _LIBCPP_HIDE_FROM_ABI long double log1p(long double __x) _NOEXCEPT {return __builtin_log1pl(__x);}
  1030. template <class _A1>
  1031. inline _LIBCPP_HIDE_FROM_ABI
  1032. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  1033. log1p(_A1 __x) _NOEXCEPT {return __builtin_log1p((double)__x);}
  1034. // log2
  1035. inline _LIBCPP_HIDE_FROM_ABI float log2(float __x) _NOEXCEPT {return __builtin_log2f(__x);}
  1036. template <class = int>
  1037. _LIBCPP_HIDE_FROM_ABI double log2(double __x) _NOEXCEPT {
  1038. return __builtin_log2(__x);
  1039. }
  1040. inline _LIBCPP_HIDE_FROM_ABI long double log2(long double __x) _NOEXCEPT {return __builtin_log2l(__x);}
  1041. template <class _A1>
  1042. inline _LIBCPP_HIDE_FROM_ABI
  1043. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  1044. log2(_A1 __x) _NOEXCEPT {return __builtin_log2((double)__x);}
  1045. // logb
  1046. inline _LIBCPP_HIDE_FROM_ABI float logb(float __x) _NOEXCEPT {return __builtin_logbf(__x);}
  1047. template <class = int>
  1048. _LIBCPP_HIDE_FROM_ABI double logb(double __x) _NOEXCEPT {
  1049. return __builtin_logb(__x);
  1050. }
  1051. inline _LIBCPP_HIDE_FROM_ABI long double logb(long double __x) _NOEXCEPT {return __builtin_logbl(__x);}
  1052. template <class _A1>
  1053. inline _LIBCPP_HIDE_FROM_ABI
  1054. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  1055. logb(_A1 __x) _NOEXCEPT {return __builtin_logb((double)__x);}
  1056. // lrint
  1057. inline _LIBCPP_HIDE_FROM_ABI long lrint(float __x) _NOEXCEPT
  1058. {
  1059. return __builtin_lrintf(__x);
  1060. }
  1061. template <class = int>
  1062. _LIBCPP_HIDE_FROM_ABI long lrint(double __x) _NOEXCEPT {
  1063. return __builtin_lrint(__x);
  1064. }
  1065. inline _LIBCPP_HIDE_FROM_ABI long lrint(long double __x) _NOEXCEPT
  1066. {
  1067. return __builtin_lrintl(__x);
  1068. }
  1069. template <class _A1>
  1070. inline _LIBCPP_HIDE_FROM_ABI
  1071. typename std::enable_if<std::is_integral<_A1>::value, long>::type
  1072. lrint(_A1 __x) _NOEXCEPT
  1073. {
  1074. return __builtin_lrint((double)__x);
  1075. }
  1076. // lround
  1077. inline _LIBCPP_HIDE_FROM_ABI long lround(float __x) _NOEXCEPT
  1078. {
  1079. return __builtin_lroundf(__x);
  1080. }
  1081. template <class = int>
  1082. _LIBCPP_HIDE_FROM_ABI long lround(double __x) _NOEXCEPT {
  1083. return __builtin_lround(__x);
  1084. }
  1085. inline _LIBCPP_HIDE_FROM_ABI long lround(long double __x) _NOEXCEPT
  1086. {
  1087. return __builtin_lroundl(__x);
  1088. }
  1089. template <class _A1>
  1090. inline _LIBCPP_HIDE_FROM_ABI
  1091. typename std::enable_if<std::is_integral<_A1>::value, long>::type
  1092. lround(_A1 __x) _NOEXCEPT
  1093. {
  1094. return __builtin_lround((double)__x);
  1095. }
  1096. // nan
  1097. // nearbyint
  1098. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI float nearbyint(float __x) _NOEXCEPT {return __builtin_nearbyintf(__x);}
  1099. template <class = int>
  1100. _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI double nearbyint(double __x) _NOEXCEPT {
  1101. return __builtin_nearbyint(__x);
  1102. }
  1103. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI long double nearbyint(long double __x) _NOEXCEPT {return __builtin_nearbyintl(__x);}
  1104. template <class _A1>
  1105. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI
  1106. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  1107. nearbyint(_A1 __x) _NOEXCEPT {return __builtin_nearbyint((double)__x);}
  1108. // nextafter
  1109. inline _LIBCPP_HIDE_FROM_ABI float nextafter(float __x, float __y) _NOEXCEPT {return __builtin_nextafterf(__x, __y);}
  1110. template <class = int>
  1111. _LIBCPP_HIDE_FROM_ABI double nextafter(double __x, double __y) _NOEXCEPT {
  1112. return __builtin_nextafter(__x, __y);
  1113. }
  1114. inline _LIBCPP_HIDE_FROM_ABI long double nextafter(long double __x, long double __y) _NOEXCEPT {return __builtin_nextafterl(__x, __y);}
  1115. template <class _A1, class _A2>
  1116. inline _LIBCPP_HIDE_FROM_ABI
  1117. typename std::__enable_if_t
  1118. <
  1119. std::is_arithmetic<_A1>::value &&
  1120. std::is_arithmetic<_A2>::value,
  1121. std::__promote<_A1, _A2>
  1122. >::type
  1123. nextafter(_A1 __x, _A2 __y) _NOEXCEPT
  1124. {
  1125. typedef typename std::__promote<_A1, _A2>::type __result_type;
  1126. static_assert((!(std::_IsSame<_A1, __result_type>::value &&
  1127. std::_IsSame<_A2, __result_type>::value)), "");
  1128. return ::nextafter((__result_type)__x, (__result_type)__y);
  1129. }
  1130. // nexttoward
  1131. inline _LIBCPP_HIDE_FROM_ABI float nexttoward(float __x, long double __y) _NOEXCEPT {return __builtin_nexttowardf(__x, __y);}
  1132. template <class = int>
  1133. _LIBCPP_HIDE_FROM_ABI double nexttoward(double __x, long double __y) _NOEXCEPT {
  1134. return __builtin_nexttoward(__x, __y);
  1135. }
  1136. inline _LIBCPP_HIDE_FROM_ABI long double nexttoward(long double __x, long double __y) _NOEXCEPT {return __builtin_nexttowardl(__x, __y);}
  1137. template <class _A1>
  1138. inline _LIBCPP_HIDE_FROM_ABI
  1139. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  1140. nexttoward(_A1 __x, long double __y) _NOEXCEPT {return __builtin_nexttoward((double)__x, __y);}
  1141. // remainder
  1142. inline _LIBCPP_HIDE_FROM_ABI float remainder(float __x, float __y) _NOEXCEPT {return __builtin_remainderf(__x, __y);}
  1143. template <class = int>
  1144. _LIBCPP_HIDE_FROM_ABI double remainder(double __x, double __y) _NOEXCEPT {
  1145. return __builtin_remainder(__x, __y);
  1146. }
  1147. inline _LIBCPP_HIDE_FROM_ABI long double remainder(long double __x, long double __y) _NOEXCEPT {return __builtin_remainderl(__x, __y);}
  1148. template <class _A1, class _A2>
  1149. inline _LIBCPP_HIDE_FROM_ABI
  1150. typename std::__enable_if_t
  1151. <
  1152. std::is_arithmetic<_A1>::value &&
  1153. std::is_arithmetic<_A2>::value,
  1154. std::__promote<_A1, _A2>
  1155. >::type
  1156. remainder(_A1 __x, _A2 __y) _NOEXCEPT
  1157. {
  1158. typedef typename std::__promote<_A1, _A2>::type __result_type;
  1159. static_assert((!(std::_IsSame<_A1, __result_type>::value &&
  1160. std::_IsSame<_A2, __result_type>::value)), "");
  1161. return ::remainder((__result_type)__x, (__result_type)__y);
  1162. }
  1163. // remquo
  1164. inline _LIBCPP_HIDE_FROM_ABI float remquo(float __x, float __y, int* __z) _NOEXCEPT {return __builtin_remquof(__x, __y, __z);}
  1165. template <class = int>
  1166. _LIBCPP_HIDE_FROM_ABI double remquo(double __x, double __y, int* __z) _NOEXCEPT {
  1167. return __builtin_remquo(__x, __y, __z);
  1168. }
  1169. inline _LIBCPP_HIDE_FROM_ABI long double remquo(long double __x, long double __y, int* __z) _NOEXCEPT {return __builtin_remquol(__x, __y, __z);}
  1170. template <class _A1, class _A2>
  1171. inline _LIBCPP_HIDE_FROM_ABI
  1172. typename std::__enable_if_t
  1173. <
  1174. std::is_arithmetic<_A1>::value &&
  1175. std::is_arithmetic<_A2>::value,
  1176. std::__promote<_A1, _A2>
  1177. >::type
  1178. remquo(_A1 __x, _A2 __y, int* __z) _NOEXCEPT
  1179. {
  1180. typedef typename std::__promote<_A1, _A2>::type __result_type;
  1181. static_assert((!(std::_IsSame<_A1, __result_type>::value &&
  1182. std::_IsSame<_A2, __result_type>::value)), "");
  1183. return ::remquo((__result_type)__x, (__result_type)__y, __z);
  1184. }
  1185. // rint
  1186. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI float rint(float __x) _NOEXCEPT
  1187. {
  1188. return __builtin_rintf(__x);
  1189. }
  1190. template <class = int>
  1191. _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI double rint(double __x) _NOEXCEPT {
  1192. return __builtin_rint(__x);
  1193. }
  1194. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI long double rint(long double __x) _NOEXCEPT
  1195. {
  1196. return __builtin_rintl(__x);
  1197. }
  1198. template <class _A1>
  1199. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI
  1200. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  1201. rint(_A1 __x) _NOEXCEPT
  1202. {
  1203. return __builtin_rint((double)__x);
  1204. }
  1205. // round
  1206. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI float round(float __x) _NOEXCEPT
  1207. {
  1208. return __builtin_roundf(__x);
  1209. }
  1210. template <class = int>
  1211. _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI double round(double __x) _NOEXCEPT {
  1212. return __builtin_round(__x);
  1213. }
  1214. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI long double round(long double __x) _NOEXCEPT
  1215. {
  1216. return __builtin_roundl(__x);
  1217. }
  1218. template <class _A1>
  1219. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI
  1220. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  1221. round(_A1 __x) _NOEXCEPT
  1222. {
  1223. return __builtin_round((double)__x);
  1224. }
  1225. // scalbln
  1226. inline _LIBCPP_HIDE_FROM_ABI float scalbln(float __x, long __y) _NOEXCEPT {return __builtin_scalblnf(__x, __y);}
  1227. template <class = int>
  1228. _LIBCPP_HIDE_FROM_ABI double scalbln(double __x, long __y) _NOEXCEPT {
  1229. return __builtin_scalbln(__x, __y);
  1230. }
  1231. inline _LIBCPP_HIDE_FROM_ABI long double scalbln(long double __x, long __y) _NOEXCEPT {return __builtin_scalblnl(__x, __y);}
  1232. template <class _A1>
  1233. inline _LIBCPP_HIDE_FROM_ABI
  1234. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  1235. scalbln(_A1 __x, long __y) _NOEXCEPT {return __builtin_scalbln((double)__x, __y);}
  1236. // scalbn
  1237. inline _LIBCPP_HIDE_FROM_ABI float scalbn(float __x, int __y) _NOEXCEPT {return __builtin_scalbnf(__x, __y);}
  1238. template <class = int>
  1239. _LIBCPP_HIDE_FROM_ABI double scalbn(double __x, int __y) _NOEXCEPT {
  1240. return __builtin_scalbn(__x, __y);
  1241. }
  1242. inline _LIBCPP_HIDE_FROM_ABI long double scalbn(long double __x, int __y) _NOEXCEPT {return __builtin_scalbnl(__x, __y);}
  1243. template <class _A1>
  1244. inline _LIBCPP_HIDE_FROM_ABI
  1245. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  1246. scalbn(_A1 __x, int __y) _NOEXCEPT {return __builtin_scalbn((double)__x, __y);}
  1247. // tgamma
  1248. inline _LIBCPP_HIDE_FROM_ABI float tgamma(float __x) _NOEXCEPT {return __builtin_tgammaf(__x);}
  1249. template <class = int>
  1250. _LIBCPP_HIDE_FROM_ABI double tgamma(double __x) _NOEXCEPT {
  1251. return __builtin_tgamma(__x);
  1252. }
  1253. inline _LIBCPP_HIDE_FROM_ABI long double tgamma(long double __x) _NOEXCEPT {return __builtin_tgammal(__x);}
  1254. template <class _A1>
  1255. inline _LIBCPP_HIDE_FROM_ABI
  1256. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  1257. tgamma(_A1 __x) _NOEXCEPT {return __builtin_tgamma((double)__x);}
  1258. // trunc
  1259. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI float trunc(float __x) _NOEXCEPT
  1260. {
  1261. return __builtin_truncf(__x);
  1262. }
  1263. template <class = int>
  1264. _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI double trunc(double __x) _NOEXCEPT {
  1265. return __builtin_trunc(__x);
  1266. }
  1267. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI long double trunc(long double __x) _NOEXCEPT
  1268. {
  1269. return __builtin_truncl(__x);
  1270. }
  1271. template <class _A1>
  1272. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI
  1273. typename std::enable_if<std::is_integral<_A1>::value, double>::type
  1274. trunc(_A1 __x) _NOEXCEPT
  1275. {
  1276. return __builtin_trunc((double)__x);
  1277. }
  1278. } // extern "C++"
  1279. #endif // __cplusplus
  1280. #else // _LIBCPP_MATH_H
  1281. // This include lives outside the header guard in order to support an MSVC
  1282. // extension which allows users to do:
  1283. //
  1284. // #define _USE_MATH_DEFINES
  1285. // #include <math.h>
  1286. //
  1287. // and receive the definitions of mathematical constants, even if <math.h>
  1288. // has previously been included.
  1289. #if defined(_LIBCPP_MSVCRT) && defined(_USE_MATH_DEFINES)
  1290. #include_next <math.h>
  1291. #endif
  1292. #endif // _LIBCPP_MATH_H