cmath 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  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_CMATH
  10. #define _LIBCPP_CMATH
  11. /*
  12. cmath 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. namespace std
  33. {
  34. Types:
  35. float_t // C99
  36. double_t // C99
  37. // C90
  38. floating_point abs(floating_point x);
  39. floating_point acos (arithmetic x);
  40. float acosf(float x);
  41. long double acosl(long double x);
  42. floating_point asin (arithmetic x);
  43. float asinf(float x);
  44. long double asinl(long double x);
  45. floating_point atan (arithmetic x);
  46. float atanf(float x);
  47. long double atanl(long double x);
  48. floating_point atan2 (arithmetic y, arithmetic x);
  49. float atan2f(float y, float x);
  50. long double atan2l(long double y, long double x);
  51. floating_point ceil (arithmetic x);
  52. float ceilf(float x);
  53. long double ceill(long double x);
  54. floating_point cos (arithmetic x);
  55. float cosf(float x);
  56. long double cosl(long double x);
  57. floating_point cosh (arithmetic x);
  58. float coshf(float x);
  59. long double coshl(long double x);
  60. floating_point exp (arithmetic x);
  61. float expf(float x);
  62. long double expl(long double x);
  63. floating_point fabs (arithmetic x);
  64. float fabsf(float x);
  65. long double fabsl(long double x);
  66. floating_point floor (arithmetic x);
  67. float floorf(float x);
  68. long double floorl(long double x);
  69. floating_point fmod (arithmetic x, arithmetic y);
  70. float fmodf(float x, float y);
  71. long double fmodl(long double x, long double y);
  72. floating_point frexp (arithmetic value, int* exp);
  73. float frexpf(float value, int* exp);
  74. long double frexpl(long double value, int* exp);
  75. floating_point ldexp (arithmetic value, int exp);
  76. float ldexpf(float value, int exp);
  77. long double ldexpl(long double value, int exp);
  78. floating_point log (arithmetic x);
  79. float logf(float x);
  80. long double logl(long double x);
  81. floating_point log10 (arithmetic x);
  82. float log10f(float x);
  83. long double log10l(long double x);
  84. floating_point modf (floating_point value, floating_point* iptr);
  85. float modff(float value, float* iptr);
  86. long double modfl(long double value, long double* iptr);
  87. floating_point pow (arithmetic x, arithmetic y);
  88. float powf(float x, float y);
  89. long double powl(long double x, long double y);
  90. floating_point sin (arithmetic x);
  91. float sinf(float x);
  92. long double sinl(long double x);
  93. floating_point sinh (arithmetic x);
  94. float sinhf(float x);
  95. long double sinhl(long double x);
  96. floating_point sqrt (arithmetic x);
  97. float sqrtf(float x);
  98. long double sqrtl(long double x);
  99. floating_point tan (arithmetic x);
  100. float tanf(float x);
  101. long double tanl(long double x);
  102. floating_point tanh (arithmetic x);
  103. float tanhf(float x);
  104. long double tanhl(long double x);
  105. // C99
  106. bool signbit(arithmetic x);
  107. int fpclassify(arithmetic x);
  108. bool isfinite(arithmetic x);
  109. bool isinf(arithmetic x);
  110. bool isnan(arithmetic x);
  111. bool isnormal(arithmetic x);
  112. bool isgreater(arithmetic x, arithmetic y);
  113. bool isgreaterequal(arithmetic x, arithmetic y);
  114. bool isless(arithmetic x, arithmetic y);
  115. bool islessequal(arithmetic x, arithmetic y);
  116. bool islessgreater(arithmetic x, arithmetic y);
  117. bool isunordered(arithmetic x, arithmetic y);
  118. floating_point acosh (arithmetic x);
  119. float acoshf(float x);
  120. long double acoshl(long double x);
  121. floating_point asinh (arithmetic x);
  122. float asinhf(float x);
  123. long double asinhl(long double x);
  124. floating_point atanh (arithmetic x);
  125. float atanhf(float x);
  126. long double atanhl(long double x);
  127. floating_point cbrt (arithmetic x);
  128. float cbrtf(float x);
  129. long double cbrtl(long double x);
  130. floating_point copysign (arithmetic x, arithmetic y);
  131. float copysignf(float x, float y);
  132. long double copysignl(long double x, long double y);
  133. floating_point erf (arithmetic x);
  134. float erff(float x);
  135. long double erfl(long double x);
  136. floating_point erfc (arithmetic x);
  137. float erfcf(float x);
  138. long double erfcl(long double x);
  139. floating_point exp2 (arithmetic x);
  140. float exp2f(float x);
  141. long double exp2l(long double x);
  142. floating_point expm1 (arithmetic x);
  143. float expm1f(float x);
  144. long double expm1l(long double x);
  145. floating_point fdim (arithmetic x, arithmetic y);
  146. float fdimf(float x, float y);
  147. long double fdiml(long double x, long double y);
  148. floating_point fma (arithmetic x, arithmetic y, arithmetic z);
  149. float fmaf(float x, float y, float z);
  150. long double fmal(long double x, long double y, long double z);
  151. floating_point fmax (arithmetic x, arithmetic y);
  152. float fmaxf(float x, float y);
  153. long double fmaxl(long double x, long double y);
  154. floating_point fmin (arithmetic x, arithmetic y);
  155. float fminf(float x, float y);
  156. long double fminl(long double x, long double y);
  157. floating_point hypot (arithmetic x, arithmetic y);
  158. float hypotf(float x, float y);
  159. long double hypotl(long double x, long double y);
  160. double hypot(double x, double y, double z); // C++17
  161. float hypot(float x, float y, float z); // C++17
  162. long double hypot(long double x, long double y, long double z); // C++17
  163. int ilogb (arithmetic x);
  164. int ilogbf(float x);
  165. int ilogbl(long double x);
  166. floating_point lgamma (arithmetic x);
  167. float lgammaf(float x);
  168. long double lgammal(long double x);
  169. long long llrint (arithmetic x);
  170. long long llrintf(float x);
  171. long long llrintl(long double x);
  172. long long llround (arithmetic x);
  173. long long llroundf(float x);
  174. long long llroundl(long double x);
  175. floating_point log1p (arithmetic x);
  176. float log1pf(float x);
  177. long double log1pl(long double x);
  178. floating_point log2 (arithmetic x);
  179. float log2f(float x);
  180. long double log2l(long double x);
  181. floating_point logb (arithmetic x);
  182. float logbf(float x);
  183. long double logbl(long double x);
  184. long lrint (arithmetic x);
  185. long lrintf(float x);
  186. long lrintl(long double x);
  187. long lround (arithmetic x);
  188. long lroundf(float x);
  189. long lroundl(long double x);
  190. double nan (const char* str);
  191. float nanf(const char* str);
  192. long double nanl(const char* str);
  193. floating_point nearbyint (arithmetic x);
  194. float nearbyintf(float x);
  195. long double nearbyintl(long double x);
  196. floating_point nextafter (arithmetic x, arithmetic y);
  197. float nextafterf(float x, float y);
  198. long double nextafterl(long double x, long double y);
  199. floating_point nexttoward (arithmetic x, long double y);
  200. float nexttowardf(float x, long double y);
  201. long double nexttowardl(long double x, long double y);
  202. floating_point remainder (arithmetic x, arithmetic y);
  203. float remainderf(float x, float y);
  204. long double remainderl(long double x, long double y);
  205. floating_point remquo (arithmetic x, arithmetic y, int* pquo);
  206. float remquof(float x, float y, int* pquo);
  207. long double remquol(long double x, long double y, int* pquo);
  208. floating_point rint (arithmetic x);
  209. float rintf(float x);
  210. long double rintl(long double x);
  211. floating_point round (arithmetic x);
  212. float roundf(float x);
  213. long double roundl(long double x);
  214. floating_point scalbln (arithmetic x, long ex);
  215. float scalblnf(float x, long ex);
  216. long double scalblnl(long double x, long ex);
  217. floating_point scalbn (arithmetic x, int ex);
  218. float scalbnf(float x, int ex);
  219. long double scalbnl(long double x, int ex);
  220. floating_point tgamma (arithmetic x);
  221. float tgammaf(float x);
  222. long double tgammal(long double x);
  223. floating_point trunc (arithmetic x);
  224. float truncf(float x);
  225. long double truncl(long double x);
  226. constexpr float lerp(float a, float b, float t) noexcept; // C++20
  227. constexpr double lerp(double a, double b, double t) noexcept; // C++20
  228. constexpr long double lerp(long double a, long double b, long double t) noexcept; // C++20
  229. } // std
  230. */
  231. #include <__config>
  232. #include <math.h>
  233. #include <type_traits>
  234. #include <version>
  235. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  236. # pragma GCC system_header
  237. #endif
  238. _LIBCPP_PUSH_MACROS
  239. #include <__undef_macros>
  240. _LIBCPP_BEGIN_NAMESPACE_STD
  241. using ::signbit _LIBCPP_USING_IF_EXISTS;
  242. using ::fpclassify _LIBCPP_USING_IF_EXISTS;
  243. using ::isfinite _LIBCPP_USING_IF_EXISTS;
  244. using ::isinf _LIBCPP_USING_IF_EXISTS;
  245. using ::isnan _LIBCPP_USING_IF_EXISTS;
  246. using ::isnormal _LIBCPP_USING_IF_EXISTS;
  247. using ::isgreater _LIBCPP_USING_IF_EXISTS;
  248. using ::isgreaterequal _LIBCPP_USING_IF_EXISTS;
  249. using ::isless _LIBCPP_USING_IF_EXISTS;
  250. using ::islessequal _LIBCPP_USING_IF_EXISTS;
  251. using ::islessgreater _LIBCPP_USING_IF_EXISTS;
  252. using ::isunordered _LIBCPP_USING_IF_EXISTS;
  253. using ::isunordered _LIBCPP_USING_IF_EXISTS;
  254. using ::float_t _LIBCPP_USING_IF_EXISTS;
  255. using ::double_t _LIBCPP_USING_IF_EXISTS;
  256. using ::abs _LIBCPP_USING_IF_EXISTS;
  257. using ::acos _LIBCPP_USING_IF_EXISTS;
  258. using ::acosf _LIBCPP_USING_IF_EXISTS;
  259. using ::asin _LIBCPP_USING_IF_EXISTS;
  260. using ::asinf _LIBCPP_USING_IF_EXISTS;
  261. using ::atan _LIBCPP_USING_IF_EXISTS;
  262. using ::atanf _LIBCPP_USING_IF_EXISTS;
  263. using ::atan2 _LIBCPP_USING_IF_EXISTS;
  264. using ::atan2f _LIBCPP_USING_IF_EXISTS;
  265. using ::ceil _LIBCPP_USING_IF_EXISTS;
  266. using ::ceilf _LIBCPP_USING_IF_EXISTS;
  267. using ::cos _LIBCPP_USING_IF_EXISTS;
  268. using ::cosf _LIBCPP_USING_IF_EXISTS;
  269. using ::cosh _LIBCPP_USING_IF_EXISTS;
  270. using ::coshf _LIBCPP_USING_IF_EXISTS;
  271. using ::exp _LIBCPP_USING_IF_EXISTS;
  272. using ::expf _LIBCPP_USING_IF_EXISTS;
  273. using ::fabs _LIBCPP_USING_IF_EXISTS;
  274. using ::fabsf _LIBCPP_USING_IF_EXISTS;
  275. using ::floor _LIBCPP_USING_IF_EXISTS;
  276. using ::floorf _LIBCPP_USING_IF_EXISTS;
  277. using ::fmod _LIBCPP_USING_IF_EXISTS;
  278. using ::fmodf _LIBCPP_USING_IF_EXISTS;
  279. using ::frexp _LIBCPP_USING_IF_EXISTS;
  280. using ::frexpf _LIBCPP_USING_IF_EXISTS;
  281. using ::ldexp _LIBCPP_USING_IF_EXISTS;
  282. using ::ldexpf _LIBCPP_USING_IF_EXISTS;
  283. using ::log _LIBCPP_USING_IF_EXISTS;
  284. using ::logf _LIBCPP_USING_IF_EXISTS;
  285. using ::log10 _LIBCPP_USING_IF_EXISTS;
  286. using ::log10f _LIBCPP_USING_IF_EXISTS;
  287. using ::modf _LIBCPP_USING_IF_EXISTS;
  288. using ::modff _LIBCPP_USING_IF_EXISTS;
  289. using ::pow _LIBCPP_USING_IF_EXISTS;
  290. using ::powf _LIBCPP_USING_IF_EXISTS;
  291. using ::sin _LIBCPP_USING_IF_EXISTS;
  292. using ::sinf _LIBCPP_USING_IF_EXISTS;
  293. using ::sinh _LIBCPP_USING_IF_EXISTS;
  294. using ::sinhf _LIBCPP_USING_IF_EXISTS;
  295. using ::sqrt _LIBCPP_USING_IF_EXISTS;
  296. using ::sqrtf _LIBCPP_USING_IF_EXISTS;
  297. using ::tan _LIBCPP_USING_IF_EXISTS;
  298. using ::tanf _LIBCPP_USING_IF_EXISTS;
  299. using ::tanh _LIBCPP_USING_IF_EXISTS;
  300. using ::tanhf _LIBCPP_USING_IF_EXISTS;
  301. using ::acosh _LIBCPP_USING_IF_EXISTS;
  302. using ::acoshf _LIBCPP_USING_IF_EXISTS;
  303. using ::asinh _LIBCPP_USING_IF_EXISTS;
  304. using ::asinhf _LIBCPP_USING_IF_EXISTS;
  305. using ::atanh _LIBCPP_USING_IF_EXISTS;
  306. using ::atanhf _LIBCPP_USING_IF_EXISTS;
  307. using ::cbrt _LIBCPP_USING_IF_EXISTS;
  308. using ::cbrtf _LIBCPP_USING_IF_EXISTS;
  309. using ::copysign _LIBCPP_USING_IF_EXISTS;
  310. using ::copysignf _LIBCPP_USING_IF_EXISTS;
  311. using ::erf _LIBCPP_USING_IF_EXISTS;
  312. using ::erff _LIBCPP_USING_IF_EXISTS;
  313. using ::erfc _LIBCPP_USING_IF_EXISTS;
  314. using ::erfcf _LIBCPP_USING_IF_EXISTS;
  315. using ::exp2 _LIBCPP_USING_IF_EXISTS;
  316. using ::exp2f _LIBCPP_USING_IF_EXISTS;
  317. using ::expm1 _LIBCPP_USING_IF_EXISTS;
  318. using ::expm1f _LIBCPP_USING_IF_EXISTS;
  319. using ::fdim _LIBCPP_USING_IF_EXISTS;
  320. using ::fdimf _LIBCPP_USING_IF_EXISTS;
  321. using ::fmaf _LIBCPP_USING_IF_EXISTS;
  322. using ::fma _LIBCPP_USING_IF_EXISTS;
  323. using ::fmax _LIBCPP_USING_IF_EXISTS;
  324. using ::fmaxf _LIBCPP_USING_IF_EXISTS;
  325. using ::fmin _LIBCPP_USING_IF_EXISTS;
  326. using ::fminf _LIBCPP_USING_IF_EXISTS;
  327. using ::hypot _LIBCPP_USING_IF_EXISTS;
  328. using ::hypotf _LIBCPP_USING_IF_EXISTS;
  329. using ::ilogb _LIBCPP_USING_IF_EXISTS;
  330. using ::ilogbf _LIBCPP_USING_IF_EXISTS;
  331. using ::lgamma _LIBCPP_USING_IF_EXISTS;
  332. using ::lgammaf _LIBCPP_USING_IF_EXISTS;
  333. using ::llrint _LIBCPP_USING_IF_EXISTS;
  334. using ::llrintf _LIBCPP_USING_IF_EXISTS;
  335. using ::llround _LIBCPP_USING_IF_EXISTS;
  336. using ::llroundf _LIBCPP_USING_IF_EXISTS;
  337. using ::log1p _LIBCPP_USING_IF_EXISTS;
  338. using ::log1pf _LIBCPP_USING_IF_EXISTS;
  339. using ::log2 _LIBCPP_USING_IF_EXISTS;
  340. using ::log2f _LIBCPP_USING_IF_EXISTS;
  341. using ::logb _LIBCPP_USING_IF_EXISTS;
  342. using ::logbf _LIBCPP_USING_IF_EXISTS;
  343. using ::lrint _LIBCPP_USING_IF_EXISTS;
  344. using ::lrintf _LIBCPP_USING_IF_EXISTS;
  345. using ::lround _LIBCPP_USING_IF_EXISTS;
  346. using ::lroundf _LIBCPP_USING_IF_EXISTS;
  347. using ::nan _LIBCPP_USING_IF_EXISTS;
  348. using ::nanf _LIBCPP_USING_IF_EXISTS;
  349. using ::nearbyint _LIBCPP_USING_IF_EXISTS;
  350. using ::nearbyintf _LIBCPP_USING_IF_EXISTS;
  351. using ::nextafter _LIBCPP_USING_IF_EXISTS;
  352. using ::nextafterf _LIBCPP_USING_IF_EXISTS;
  353. using ::nexttoward _LIBCPP_USING_IF_EXISTS;
  354. using ::nexttowardf _LIBCPP_USING_IF_EXISTS;
  355. using ::remainder _LIBCPP_USING_IF_EXISTS;
  356. using ::remainderf _LIBCPP_USING_IF_EXISTS;
  357. using ::remquo _LIBCPP_USING_IF_EXISTS;
  358. using ::remquof _LIBCPP_USING_IF_EXISTS;
  359. using ::rint _LIBCPP_USING_IF_EXISTS;
  360. using ::rintf _LIBCPP_USING_IF_EXISTS;
  361. using ::round _LIBCPP_USING_IF_EXISTS;
  362. using ::roundf _LIBCPP_USING_IF_EXISTS;
  363. using ::scalbln _LIBCPP_USING_IF_EXISTS;
  364. using ::scalblnf _LIBCPP_USING_IF_EXISTS;
  365. using ::scalbn _LIBCPP_USING_IF_EXISTS;
  366. using ::scalbnf _LIBCPP_USING_IF_EXISTS;
  367. using ::tgamma _LIBCPP_USING_IF_EXISTS;
  368. using ::tgammaf _LIBCPP_USING_IF_EXISTS;
  369. using ::trunc _LIBCPP_USING_IF_EXISTS;
  370. using ::truncf _LIBCPP_USING_IF_EXISTS;
  371. using ::acosl _LIBCPP_USING_IF_EXISTS;
  372. using ::asinl _LIBCPP_USING_IF_EXISTS;
  373. using ::atanl _LIBCPP_USING_IF_EXISTS;
  374. using ::atan2l _LIBCPP_USING_IF_EXISTS;
  375. using ::ceill _LIBCPP_USING_IF_EXISTS;
  376. using ::cosl _LIBCPP_USING_IF_EXISTS;
  377. using ::coshl _LIBCPP_USING_IF_EXISTS;
  378. using ::expl _LIBCPP_USING_IF_EXISTS;
  379. using ::fabsl _LIBCPP_USING_IF_EXISTS;
  380. using ::floorl _LIBCPP_USING_IF_EXISTS;
  381. using ::fmodl _LIBCPP_USING_IF_EXISTS;
  382. using ::frexpl _LIBCPP_USING_IF_EXISTS;
  383. using ::ldexpl _LIBCPP_USING_IF_EXISTS;
  384. using ::logl _LIBCPP_USING_IF_EXISTS;
  385. using ::log10l _LIBCPP_USING_IF_EXISTS;
  386. using ::modfl _LIBCPP_USING_IF_EXISTS;
  387. using ::powl _LIBCPP_USING_IF_EXISTS;
  388. using ::sinl _LIBCPP_USING_IF_EXISTS;
  389. using ::sinhl _LIBCPP_USING_IF_EXISTS;
  390. using ::sqrtl _LIBCPP_USING_IF_EXISTS;
  391. using ::tanl _LIBCPP_USING_IF_EXISTS;
  392. using ::tanhl _LIBCPP_USING_IF_EXISTS;
  393. using ::acoshl _LIBCPP_USING_IF_EXISTS;
  394. using ::asinhl _LIBCPP_USING_IF_EXISTS;
  395. using ::atanhl _LIBCPP_USING_IF_EXISTS;
  396. using ::cbrtl _LIBCPP_USING_IF_EXISTS;
  397. using ::copysignl _LIBCPP_USING_IF_EXISTS;
  398. using ::erfl _LIBCPP_USING_IF_EXISTS;
  399. using ::erfcl _LIBCPP_USING_IF_EXISTS;
  400. using ::exp2l _LIBCPP_USING_IF_EXISTS;
  401. using ::expm1l _LIBCPP_USING_IF_EXISTS;
  402. using ::fdiml _LIBCPP_USING_IF_EXISTS;
  403. using ::fmal _LIBCPP_USING_IF_EXISTS;
  404. using ::fmaxl _LIBCPP_USING_IF_EXISTS;
  405. using ::fminl _LIBCPP_USING_IF_EXISTS;
  406. using ::hypotl _LIBCPP_USING_IF_EXISTS;
  407. using ::ilogbl _LIBCPP_USING_IF_EXISTS;
  408. using ::lgammal _LIBCPP_USING_IF_EXISTS;
  409. using ::llrintl _LIBCPP_USING_IF_EXISTS;
  410. using ::llroundl _LIBCPP_USING_IF_EXISTS;
  411. using ::log1pl _LIBCPP_USING_IF_EXISTS;
  412. using ::log2l _LIBCPP_USING_IF_EXISTS;
  413. using ::logbl _LIBCPP_USING_IF_EXISTS;
  414. using ::lrintl _LIBCPP_USING_IF_EXISTS;
  415. using ::lroundl _LIBCPP_USING_IF_EXISTS;
  416. using ::nanl _LIBCPP_USING_IF_EXISTS;
  417. using ::nearbyintl _LIBCPP_USING_IF_EXISTS;
  418. using ::nextafterl _LIBCPP_USING_IF_EXISTS;
  419. using ::nexttowardl _LIBCPP_USING_IF_EXISTS;
  420. using ::remainderl _LIBCPP_USING_IF_EXISTS;
  421. using ::remquol _LIBCPP_USING_IF_EXISTS;
  422. using ::rintl _LIBCPP_USING_IF_EXISTS;
  423. using ::roundl _LIBCPP_USING_IF_EXISTS;
  424. using ::scalblnl _LIBCPP_USING_IF_EXISTS;
  425. using ::scalbnl _LIBCPP_USING_IF_EXISTS;
  426. using ::tgammal _LIBCPP_USING_IF_EXISTS;
  427. using ::truncl _LIBCPP_USING_IF_EXISTS;
  428. #if _LIBCPP_STD_VER > 14
  429. inline _LIBCPP_INLINE_VISIBILITY float hypot( float x, float y, float z ) { return sqrt(x*x + y*y + z*z); }
  430. inline _LIBCPP_INLINE_VISIBILITY double hypot( double x, double y, double z ) { return sqrt(x*x + y*y + z*z); }
  431. inline _LIBCPP_INLINE_VISIBILITY long double hypot( long double x, long double y, long double z ) { return sqrt(x*x + y*y + z*z); }
  432. template <class _A1, class _A2, class _A3>
  433. inline _LIBCPP_INLINE_VISIBILITY
  434. typename enable_if_t
  435. <
  436. is_arithmetic<_A1>::value &&
  437. is_arithmetic<_A2>::value &&
  438. is_arithmetic<_A3>::value,
  439. __promote<_A1, _A2, _A3>
  440. >::type
  441. hypot(_A1 __lcpp_x, _A2 __lcpp_y, _A3 __lcpp_z) _NOEXCEPT
  442. {
  443. typedef typename __promote<_A1, _A2, _A3>::type __result_type;
  444. static_assert((!(is_same<_A1, __result_type>::value &&
  445. is_same<_A2, __result_type>::value &&
  446. is_same<_A3, __result_type>::value)), "");
  447. return hypot((__result_type)__lcpp_x, (__result_type)__lcpp_y, (__result_type)__lcpp_z);
  448. }
  449. #endif
  450. template <class _A1>
  451. _LIBCPP_INLINE_VISIBILITY
  452. _LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type
  453. __libcpp_isnan_or_builtin(_A1 __lcpp_x) _NOEXCEPT
  454. {
  455. #if __has_builtin(__builtin_isnan)
  456. return __builtin_isnan(__lcpp_x);
  457. #else
  458. return isnan(__lcpp_x);
  459. #endif
  460. }
  461. template <class _A1>
  462. _LIBCPP_INLINE_VISIBILITY
  463. _LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type
  464. __libcpp_isnan_or_builtin(_A1 __lcpp_x) _NOEXCEPT
  465. {
  466. return isnan(__lcpp_x);
  467. }
  468. template <class _A1>
  469. _LIBCPP_INLINE_VISIBILITY
  470. _LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type
  471. __libcpp_isinf_or_builtin(_A1 __lcpp_x) _NOEXCEPT
  472. {
  473. #if __has_builtin(__builtin_isinf)
  474. return __builtin_isinf(__lcpp_x);
  475. #else
  476. return isinf(__lcpp_x);
  477. #endif
  478. }
  479. template <class _A1>
  480. _LIBCPP_INLINE_VISIBILITY
  481. _LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type
  482. __libcpp_isinf_or_builtin(_A1 __lcpp_x) _NOEXCEPT
  483. {
  484. return isinf(__lcpp_x);
  485. }
  486. template <class _A1>
  487. _LIBCPP_INLINE_VISIBILITY
  488. _LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type
  489. __libcpp_isfinite_or_builtin(_A1 __lcpp_x) _NOEXCEPT
  490. {
  491. #if __has_builtin(__builtin_isfinite)
  492. return __builtin_isfinite(__lcpp_x);
  493. #else
  494. return isfinite(__lcpp_x);
  495. #endif
  496. }
  497. template <class _A1>
  498. _LIBCPP_INLINE_VISIBILITY
  499. _LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type
  500. __libcpp_isfinite_or_builtin(_A1 __lcpp_x) _NOEXCEPT
  501. {
  502. return isfinite(__lcpp_x);
  503. }
  504. #if _LIBCPP_STD_VER > 17
  505. template <typename _Fp>
  506. constexpr
  507. _Fp __lerp(_Fp __a, _Fp __b, _Fp __t) noexcept {
  508. if ((__a <= 0 && __b >= 0) || (__a >= 0 && __b <= 0))
  509. return __t * __b + (1 - __t) * __a;
  510. if (__t == 1) return __b;
  511. const _Fp __x = __a + __t * (__b - __a);
  512. if ((__t > 1) == (__b > __a))
  513. return __b < __x ? __x : __b;
  514. else
  515. return __x < __b ? __x : __b;
  516. }
  517. constexpr float
  518. lerp(float __a, float __b, float __t) _NOEXCEPT { return __lerp(__a, __b, __t); }
  519. constexpr double
  520. lerp(double __a, double __b, double __t) _NOEXCEPT { return __lerp(__a, __b, __t); }
  521. constexpr long double
  522. lerp(long double __a, long double __b, long double __t) _NOEXCEPT { return __lerp(__a, __b, __t); }
  523. template <class _A1, class _A2, class _A3>
  524. inline _LIBCPP_HIDE_FROM_ABI
  525. constexpr typename enable_if_t
  526. <
  527. is_arithmetic<_A1>::value &&
  528. is_arithmetic<_A2>::value &&
  529. is_arithmetic<_A3>::value,
  530. __promote<_A1, _A2, _A3>
  531. >::type
  532. lerp(_A1 __a, _A2 __b, _A3 __t) noexcept
  533. {
  534. typedef typename __promote<_A1, _A2, _A3>::type __result_type;
  535. static_assert(!(_IsSame<_A1, __result_type>::value &&
  536. _IsSame<_A2, __result_type>::value &&
  537. _IsSame<_A3, __result_type>::value));
  538. return __lerp((__result_type)__a, (__result_type)__b, (__result_type)__t);
  539. }
  540. #endif // _LIBCPP_STD_VER > 17
  541. _LIBCPP_END_NAMESPACE_STD
  542. _LIBCPP_POP_MACROS
  543. #endif // _LIBCPP_CMATH