cmath 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  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 <__assert> // all public C++ headers provide the assertion handler
  232. #include <__config>
  233. #include <__type_traits/enable_if.h>
  234. #include <__type_traits/is_arithmetic.h>
  235. #include <__type_traits/is_constant_evaluated.h>
  236. #include <__type_traits/is_floating_point.h>
  237. #include <__type_traits/is_same.h>
  238. #include <__type_traits/promote.h>
  239. #include <__type_traits/remove_cv.h>
  240. #include <limits>
  241. #include <version>
  242. #include <math.h>
  243. #ifndef _LIBCPP_MATH_H
  244. # error <cmath> tried including <math.h> but didn't find libc++'s <math.h> header. \
  245. This usually means that your header search paths are not configured properly. \
  246. The header search paths should contain the C++ Standard Library headers before \
  247. any C Standard Library, and you are probably using compiler flags that make that \
  248. not be the case.
  249. #endif
  250. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  251. # pragma GCC system_header
  252. #endif
  253. _LIBCPP_PUSH_MACROS
  254. #include <__undef_macros>
  255. _LIBCPP_BEGIN_NAMESPACE_STD
  256. using ::signbit _LIBCPP_USING_IF_EXISTS;
  257. using ::fpclassify _LIBCPP_USING_IF_EXISTS;
  258. using ::isfinite _LIBCPP_USING_IF_EXISTS;
  259. using ::isinf _LIBCPP_USING_IF_EXISTS;
  260. using ::isnan _LIBCPP_USING_IF_EXISTS;
  261. using ::isnormal _LIBCPP_USING_IF_EXISTS;
  262. using ::isgreater _LIBCPP_USING_IF_EXISTS;
  263. using ::isgreaterequal _LIBCPP_USING_IF_EXISTS;
  264. using ::isless _LIBCPP_USING_IF_EXISTS;
  265. using ::islessequal _LIBCPP_USING_IF_EXISTS;
  266. using ::islessgreater _LIBCPP_USING_IF_EXISTS;
  267. using ::isunordered _LIBCPP_USING_IF_EXISTS;
  268. using ::isunordered _LIBCPP_USING_IF_EXISTS;
  269. using ::float_t _LIBCPP_USING_IF_EXISTS;
  270. using ::double_t _LIBCPP_USING_IF_EXISTS;
  271. using ::abs _LIBCPP_USING_IF_EXISTS;
  272. using ::acos _LIBCPP_USING_IF_EXISTS;
  273. using ::acosf _LIBCPP_USING_IF_EXISTS;
  274. using ::asin _LIBCPP_USING_IF_EXISTS;
  275. using ::asinf _LIBCPP_USING_IF_EXISTS;
  276. using ::atan _LIBCPP_USING_IF_EXISTS;
  277. using ::atanf _LIBCPP_USING_IF_EXISTS;
  278. using ::atan2 _LIBCPP_USING_IF_EXISTS;
  279. using ::atan2f _LIBCPP_USING_IF_EXISTS;
  280. using ::ceil _LIBCPP_USING_IF_EXISTS;
  281. using ::ceilf _LIBCPP_USING_IF_EXISTS;
  282. using ::cos _LIBCPP_USING_IF_EXISTS;
  283. using ::cosf _LIBCPP_USING_IF_EXISTS;
  284. using ::cosh _LIBCPP_USING_IF_EXISTS;
  285. using ::coshf _LIBCPP_USING_IF_EXISTS;
  286. using ::exp _LIBCPP_USING_IF_EXISTS;
  287. using ::expf _LIBCPP_USING_IF_EXISTS;
  288. using ::fabs _LIBCPP_USING_IF_EXISTS;
  289. using ::fabsf _LIBCPP_USING_IF_EXISTS;
  290. using ::floor _LIBCPP_USING_IF_EXISTS;
  291. using ::floorf _LIBCPP_USING_IF_EXISTS;
  292. using ::fmod _LIBCPP_USING_IF_EXISTS;
  293. using ::fmodf _LIBCPP_USING_IF_EXISTS;
  294. using ::frexp _LIBCPP_USING_IF_EXISTS;
  295. using ::frexpf _LIBCPP_USING_IF_EXISTS;
  296. using ::ldexp _LIBCPP_USING_IF_EXISTS;
  297. using ::ldexpf _LIBCPP_USING_IF_EXISTS;
  298. using ::log _LIBCPP_USING_IF_EXISTS;
  299. using ::logf _LIBCPP_USING_IF_EXISTS;
  300. using ::log10 _LIBCPP_USING_IF_EXISTS;
  301. using ::log10f _LIBCPP_USING_IF_EXISTS;
  302. using ::modf _LIBCPP_USING_IF_EXISTS;
  303. using ::modff _LIBCPP_USING_IF_EXISTS;
  304. using ::pow _LIBCPP_USING_IF_EXISTS;
  305. using ::powf _LIBCPP_USING_IF_EXISTS;
  306. using ::sin _LIBCPP_USING_IF_EXISTS;
  307. using ::sinf _LIBCPP_USING_IF_EXISTS;
  308. using ::sinh _LIBCPP_USING_IF_EXISTS;
  309. using ::sinhf _LIBCPP_USING_IF_EXISTS;
  310. using ::sqrt _LIBCPP_USING_IF_EXISTS;
  311. using ::sqrtf _LIBCPP_USING_IF_EXISTS;
  312. using ::tan _LIBCPP_USING_IF_EXISTS;
  313. using ::tanf _LIBCPP_USING_IF_EXISTS;
  314. using ::tanh _LIBCPP_USING_IF_EXISTS;
  315. using ::tanhf _LIBCPP_USING_IF_EXISTS;
  316. using ::acosh _LIBCPP_USING_IF_EXISTS;
  317. using ::acoshf _LIBCPP_USING_IF_EXISTS;
  318. using ::asinh _LIBCPP_USING_IF_EXISTS;
  319. using ::asinhf _LIBCPP_USING_IF_EXISTS;
  320. using ::atanh _LIBCPP_USING_IF_EXISTS;
  321. using ::atanhf _LIBCPP_USING_IF_EXISTS;
  322. using ::cbrt _LIBCPP_USING_IF_EXISTS;
  323. using ::cbrtf _LIBCPP_USING_IF_EXISTS;
  324. using ::copysign _LIBCPP_USING_IF_EXISTS;
  325. using ::copysignf _LIBCPP_USING_IF_EXISTS;
  326. using ::erf _LIBCPP_USING_IF_EXISTS;
  327. using ::erff _LIBCPP_USING_IF_EXISTS;
  328. using ::erfc _LIBCPP_USING_IF_EXISTS;
  329. using ::erfcf _LIBCPP_USING_IF_EXISTS;
  330. using ::exp2 _LIBCPP_USING_IF_EXISTS;
  331. using ::exp2f _LIBCPP_USING_IF_EXISTS;
  332. using ::expm1 _LIBCPP_USING_IF_EXISTS;
  333. using ::expm1f _LIBCPP_USING_IF_EXISTS;
  334. using ::fdim _LIBCPP_USING_IF_EXISTS;
  335. using ::fdimf _LIBCPP_USING_IF_EXISTS;
  336. using ::fmaf _LIBCPP_USING_IF_EXISTS;
  337. using ::fma _LIBCPP_USING_IF_EXISTS;
  338. using ::fmax _LIBCPP_USING_IF_EXISTS;
  339. using ::fmaxf _LIBCPP_USING_IF_EXISTS;
  340. using ::fmin _LIBCPP_USING_IF_EXISTS;
  341. using ::fminf _LIBCPP_USING_IF_EXISTS;
  342. using ::hypot _LIBCPP_USING_IF_EXISTS;
  343. using ::hypotf _LIBCPP_USING_IF_EXISTS;
  344. using ::ilogb _LIBCPP_USING_IF_EXISTS;
  345. using ::ilogbf _LIBCPP_USING_IF_EXISTS;
  346. using ::lgamma _LIBCPP_USING_IF_EXISTS;
  347. using ::lgammaf _LIBCPP_USING_IF_EXISTS;
  348. using ::llrint _LIBCPP_USING_IF_EXISTS;
  349. using ::llrintf _LIBCPP_USING_IF_EXISTS;
  350. using ::llround _LIBCPP_USING_IF_EXISTS;
  351. using ::llroundf _LIBCPP_USING_IF_EXISTS;
  352. using ::log1p _LIBCPP_USING_IF_EXISTS;
  353. using ::log1pf _LIBCPP_USING_IF_EXISTS;
  354. using ::log2 _LIBCPP_USING_IF_EXISTS;
  355. using ::log2f _LIBCPP_USING_IF_EXISTS;
  356. using ::logb _LIBCPP_USING_IF_EXISTS;
  357. using ::logbf _LIBCPP_USING_IF_EXISTS;
  358. using ::lrint _LIBCPP_USING_IF_EXISTS;
  359. using ::lrintf _LIBCPP_USING_IF_EXISTS;
  360. using ::lround _LIBCPP_USING_IF_EXISTS;
  361. using ::lroundf _LIBCPP_USING_IF_EXISTS;
  362. using ::nan _LIBCPP_USING_IF_EXISTS;
  363. using ::nanf _LIBCPP_USING_IF_EXISTS;
  364. using ::nearbyint _LIBCPP_USING_IF_EXISTS;
  365. using ::nearbyintf _LIBCPP_USING_IF_EXISTS;
  366. using ::nextafter _LIBCPP_USING_IF_EXISTS;
  367. using ::nextafterf _LIBCPP_USING_IF_EXISTS;
  368. using ::nexttoward _LIBCPP_USING_IF_EXISTS;
  369. using ::nexttowardf _LIBCPP_USING_IF_EXISTS;
  370. using ::remainder _LIBCPP_USING_IF_EXISTS;
  371. using ::remainderf _LIBCPP_USING_IF_EXISTS;
  372. using ::remquo _LIBCPP_USING_IF_EXISTS;
  373. using ::remquof _LIBCPP_USING_IF_EXISTS;
  374. using ::rint _LIBCPP_USING_IF_EXISTS;
  375. using ::rintf _LIBCPP_USING_IF_EXISTS;
  376. using ::round _LIBCPP_USING_IF_EXISTS;
  377. using ::roundf _LIBCPP_USING_IF_EXISTS;
  378. using ::scalbln _LIBCPP_USING_IF_EXISTS;
  379. using ::scalblnf _LIBCPP_USING_IF_EXISTS;
  380. using ::scalbn _LIBCPP_USING_IF_EXISTS;
  381. using ::scalbnf _LIBCPP_USING_IF_EXISTS;
  382. using ::tgamma _LIBCPP_USING_IF_EXISTS;
  383. using ::tgammaf _LIBCPP_USING_IF_EXISTS;
  384. using ::trunc _LIBCPP_USING_IF_EXISTS;
  385. using ::truncf _LIBCPP_USING_IF_EXISTS;
  386. using ::acosl _LIBCPP_USING_IF_EXISTS;
  387. using ::asinl _LIBCPP_USING_IF_EXISTS;
  388. using ::atanl _LIBCPP_USING_IF_EXISTS;
  389. using ::atan2l _LIBCPP_USING_IF_EXISTS;
  390. using ::ceill _LIBCPP_USING_IF_EXISTS;
  391. using ::cosl _LIBCPP_USING_IF_EXISTS;
  392. using ::coshl _LIBCPP_USING_IF_EXISTS;
  393. using ::expl _LIBCPP_USING_IF_EXISTS;
  394. using ::fabsl _LIBCPP_USING_IF_EXISTS;
  395. using ::floorl _LIBCPP_USING_IF_EXISTS;
  396. using ::fmodl _LIBCPP_USING_IF_EXISTS;
  397. using ::frexpl _LIBCPP_USING_IF_EXISTS;
  398. using ::ldexpl _LIBCPP_USING_IF_EXISTS;
  399. using ::logl _LIBCPP_USING_IF_EXISTS;
  400. using ::log10l _LIBCPP_USING_IF_EXISTS;
  401. using ::modfl _LIBCPP_USING_IF_EXISTS;
  402. using ::powl _LIBCPP_USING_IF_EXISTS;
  403. using ::sinl _LIBCPP_USING_IF_EXISTS;
  404. using ::sinhl _LIBCPP_USING_IF_EXISTS;
  405. using ::sqrtl _LIBCPP_USING_IF_EXISTS;
  406. using ::tanl _LIBCPP_USING_IF_EXISTS;
  407. using ::tanhl _LIBCPP_USING_IF_EXISTS;
  408. using ::acoshl _LIBCPP_USING_IF_EXISTS;
  409. using ::asinhl _LIBCPP_USING_IF_EXISTS;
  410. using ::atanhl _LIBCPP_USING_IF_EXISTS;
  411. using ::cbrtl _LIBCPP_USING_IF_EXISTS;
  412. using ::copysignl _LIBCPP_USING_IF_EXISTS;
  413. using ::erfl _LIBCPP_USING_IF_EXISTS;
  414. using ::erfcl _LIBCPP_USING_IF_EXISTS;
  415. using ::exp2l _LIBCPP_USING_IF_EXISTS;
  416. using ::expm1l _LIBCPP_USING_IF_EXISTS;
  417. using ::fdiml _LIBCPP_USING_IF_EXISTS;
  418. using ::fmal _LIBCPP_USING_IF_EXISTS;
  419. using ::fmaxl _LIBCPP_USING_IF_EXISTS;
  420. using ::fminl _LIBCPP_USING_IF_EXISTS;
  421. using ::hypotl _LIBCPP_USING_IF_EXISTS;
  422. using ::ilogbl _LIBCPP_USING_IF_EXISTS;
  423. using ::lgammal _LIBCPP_USING_IF_EXISTS;
  424. using ::llrintl _LIBCPP_USING_IF_EXISTS;
  425. using ::llroundl _LIBCPP_USING_IF_EXISTS;
  426. using ::log1pl _LIBCPP_USING_IF_EXISTS;
  427. using ::log2l _LIBCPP_USING_IF_EXISTS;
  428. using ::logbl _LIBCPP_USING_IF_EXISTS;
  429. using ::lrintl _LIBCPP_USING_IF_EXISTS;
  430. using ::lroundl _LIBCPP_USING_IF_EXISTS;
  431. using ::nanl _LIBCPP_USING_IF_EXISTS;
  432. using ::nearbyintl _LIBCPP_USING_IF_EXISTS;
  433. using ::nextafterl _LIBCPP_USING_IF_EXISTS;
  434. using ::nexttowardl _LIBCPP_USING_IF_EXISTS;
  435. using ::remainderl _LIBCPP_USING_IF_EXISTS;
  436. using ::remquol _LIBCPP_USING_IF_EXISTS;
  437. using ::rintl _LIBCPP_USING_IF_EXISTS;
  438. using ::roundl _LIBCPP_USING_IF_EXISTS;
  439. using ::scalblnl _LIBCPP_USING_IF_EXISTS;
  440. using ::scalbnl _LIBCPP_USING_IF_EXISTS;
  441. using ::tgammal _LIBCPP_USING_IF_EXISTS;
  442. using ::truncl _LIBCPP_USING_IF_EXISTS;
  443. #if _LIBCPP_STD_VER >= 17
  444. inline _LIBCPP_INLINE_VISIBILITY float hypot( float __x, float __y, float __z ) { return sqrt(__x*__x + __y*__y + __z*__z); }
  445. inline _LIBCPP_INLINE_VISIBILITY double hypot( double __x, double __y, double __z ) { return sqrt(__x*__x + __y*__y + __z*__z); }
  446. inline _LIBCPP_INLINE_VISIBILITY long double hypot( long double __x, long double __y, long double __z ) { return sqrt(__x*__x + __y*__y + __z*__z); }
  447. template <class _A1, class _A2, class _A3>
  448. inline _LIBCPP_INLINE_VISIBILITY
  449. typename enable_if_t
  450. <
  451. is_arithmetic<_A1>::value &&
  452. is_arithmetic<_A2>::value &&
  453. is_arithmetic<_A3>::value,
  454. __promote<_A1, _A2, _A3>
  455. >::type
  456. hypot(_A1 __lcpp_x, _A2 __lcpp_y, _A3 __lcpp_z) _NOEXCEPT
  457. {
  458. typedef typename __promote<_A1, _A2, _A3>::type __result_type;
  459. static_assert((!(is_same<_A1, __result_type>::value &&
  460. is_same<_A2, __result_type>::value &&
  461. is_same<_A3, __result_type>::value)), "");
  462. return std::hypot((__result_type)__lcpp_x, (__result_type)__lcpp_y, (__result_type)__lcpp_z);
  463. }
  464. #endif
  465. template <class _A1, __enable_if_t<is_floating_point<_A1>::value, int> = 0>
  466. _LIBCPP_INLINE_VISIBILITY
  467. _LIBCPP_CONSTEXPR bool
  468. __constexpr_isnan(_A1 __lcpp_x) _NOEXCEPT
  469. {
  470. #if __has_builtin(__builtin_isnan)
  471. return __builtin_isnan(__lcpp_x);
  472. #else
  473. return isnan(__lcpp_x);
  474. #endif
  475. }
  476. template <class _A1, __enable_if_t<!is_floating_point<_A1>::value, int> = 0>
  477. _LIBCPP_INLINE_VISIBILITY
  478. _LIBCPP_CONSTEXPR bool
  479. __constexpr_isnan(_A1 __lcpp_x) _NOEXCEPT
  480. {
  481. return std::isnan(__lcpp_x);
  482. }
  483. template <class _A1, __enable_if_t<is_floating_point<_A1>::value, int> = 0>
  484. _LIBCPP_INLINE_VISIBILITY
  485. _LIBCPP_CONSTEXPR bool
  486. __constexpr_isinf(_A1 __lcpp_x) _NOEXCEPT
  487. {
  488. #if __has_builtin(__builtin_isinf)
  489. return __builtin_isinf(__lcpp_x);
  490. #else
  491. return isinf(__lcpp_x);
  492. #endif
  493. }
  494. template <class _A1, __enable_if_t<!is_floating_point<_A1>::value, int> = 0>
  495. _LIBCPP_INLINE_VISIBILITY
  496. _LIBCPP_CONSTEXPR bool
  497. __constexpr_isinf(_A1 __lcpp_x) _NOEXCEPT
  498. {
  499. return std::isinf(__lcpp_x);
  500. }
  501. template <class _A1, __enable_if_t<is_floating_point<_A1>::value, int> = 0>
  502. _LIBCPP_INLINE_VISIBILITY
  503. _LIBCPP_CONSTEXPR bool
  504. __constexpr_isfinite(_A1 __lcpp_x) _NOEXCEPT
  505. {
  506. #if __has_builtin(__builtin_isfinite)
  507. return __builtin_isfinite(__lcpp_x);
  508. #else
  509. return isfinite(__lcpp_x);
  510. #endif
  511. }
  512. template <class _A1, __enable_if_t<!is_floating_point<_A1>::value, int> = 0>
  513. _LIBCPP_INLINE_VISIBILITY
  514. _LIBCPP_CONSTEXPR bool
  515. __constexpr_isfinite(_A1 __lcpp_x) _NOEXCEPT
  516. {
  517. return __builtin_isfinite(__lcpp_x);
  518. }
  519. _LIBCPP_CONSTEXPR inline _LIBCPP_HIDE_FROM_ABI float __constexpr_copysign(float __x, float __y) _NOEXCEPT {
  520. return __builtin_copysignf(__x, __y);
  521. }
  522. _LIBCPP_CONSTEXPR inline _LIBCPP_HIDE_FROM_ABI double __constexpr_copysign(double __x, double __y) _NOEXCEPT {
  523. return __builtin_copysign(__x, __y);
  524. }
  525. _LIBCPP_CONSTEXPR inline _LIBCPP_HIDE_FROM_ABI long double
  526. __constexpr_copysign(long double __x, long double __y) _NOEXCEPT {
  527. return __builtin_copysignl(__x, __y);
  528. }
  529. template <class _A1, class _A2, __enable_if_t<std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, int> = 0>
  530. _LIBCPP_CONSTEXPR inline _LIBCPP_HIDE_FROM_ABI
  531. typename __promote<_A1, _A2>::type
  532. __constexpr_copysign(_A1 __x, _A2 __y) _NOEXCEPT {
  533. typedef typename std::__promote<_A1, _A2>::type __result_type;
  534. static_assert((!(std::_IsSame<_A1, __result_type>::value && std::_IsSame<_A2, __result_type>::value)), "");
  535. return __builtin_copysign((__result_type)__x, (__result_type)__y);
  536. }
  537. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR float __constexpr_fabs(float __x) _NOEXCEPT {
  538. return __builtin_fabsf(__x);
  539. }
  540. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR double __constexpr_fabs(double __x) _NOEXCEPT {
  541. return __builtin_fabs(__x);
  542. }
  543. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR long double __constexpr_fabs(long double __x) _NOEXCEPT {
  544. return __builtin_fabsl(__x);
  545. }
  546. template <class _Tp, __enable_if_t<is_integral<_Tp>::value, int> = 0>
  547. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR double __constexpr_fabs(_Tp __x) _NOEXCEPT {
  548. return __builtin_fabs(static_cast<double>(__x));
  549. }
  550. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 float __constexpr_fmax(float __x, float __y) _NOEXCEPT {
  551. #if !__has_constexpr_builtin(__builtin_fmaxf)
  552. if (__libcpp_is_constant_evaluated()) {
  553. if (std::__constexpr_isnan(__x))
  554. return __y;
  555. if (std::__constexpr_isnan(__y))
  556. return __x;
  557. return __x < __y ? __y : __x;
  558. }
  559. #endif
  560. return __builtin_fmaxf(__x, __y);
  561. }
  562. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 double __constexpr_fmax(double __x, double __y) _NOEXCEPT {
  563. #if !__has_constexpr_builtin(__builtin_fmax)
  564. if (__libcpp_is_constant_evaluated()) {
  565. if (std::__constexpr_isnan(__x))
  566. return __y;
  567. if (std::__constexpr_isnan(__y))
  568. return __x;
  569. return __x < __y ? __y : __x;
  570. }
  571. #endif
  572. return __builtin_fmax(__x, __y);
  573. }
  574. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 long double
  575. __constexpr_fmax(long double __x, long double __y) _NOEXCEPT {
  576. #if !__has_constexpr_builtin(__builtin_fmaxl)
  577. if (__libcpp_is_constant_evaluated()) {
  578. if (std::__constexpr_isnan(__x))
  579. return __y;
  580. if (std::__constexpr_isnan(__y))
  581. return __x;
  582. return __x < __y ? __y : __x;
  583. }
  584. #endif
  585. return __builtin_fmaxl(__x, __y);
  586. }
  587. template <class _Tp, class _Up, __enable_if_t<is_arithmetic<_Tp>::value && is_arithmetic<_Up>::value, int> = 0>
  588. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename __promote<_Tp, _Up>::type
  589. __constexpr_fmax(_Tp __x, _Up __y) _NOEXCEPT {
  590. using __result_type = typename __promote<_Tp, _Up>::type;
  591. return std::__constexpr_fmax(static_cast<__result_type>(__x), static_cast<__result_type>(__y));
  592. }
  593. template <class _Tp>
  594. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp __constexpr_logb(_Tp __x) {
  595. #if !__has_constexpr_builtin(__builtin_logb)
  596. if (__libcpp_is_constant_evaluated()) {
  597. if (__x == _Tp(0)) {
  598. // raise FE_DIVBYZERO
  599. return -numeric_limits<_Tp>::infinity();
  600. }
  601. if (std::__constexpr_isinf(__x))
  602. return numeric_limits<_Tp>::infinity();
  603. if (std::__constexpr_isnan(__x))
  604. return numeric_limits<_Tp>::quiet_NaN();
  605. __x = std::__constexpr_fabs(__x);
  606. unsigned long long __exp = 0;
  607. while (__x >= numeric_limits<_Tp>::radix) {
  608. __x /= numeric_limits<_Tp>::radix;
  609. __exp += 1;
  610. }
  611. return _Tp(__exp);
  612. }
  613. #endif // !__has_constexpr_builtin(__builtin_logb)
  614. return __builtin_logb(__x);
  615. }
  616. template <class _Tp>
  617. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp __constexpr_scalbn(_Tp __x, int __exp) {
  618. #if !__has_constexpr_builtin(__builtin_scalbln)
  619. if (__libcpp_is_constant_evaluated()) {
  620. if (__x == _Tp(0))
  621. return __x;
  622. if (std::__constexpr_isinf(__x))
  623. return __x;
  624. if (__exp == _Tp(0))
  625. return __x;
  626. if (std::__constexpr_isnan(__x))
  627. return numeric_limits<_Tp>::quiet_NaN();
  628. _Tp __mult(1);
  629. if (__exp > 0) {
  630. __mult = numeric_limits<_Tp>::radix;
  631. --__exp;
  632. } else {
  633. ++__exp;
  634. __exp = -__exp;
  635. __mult /= numeric_limits<_Tp>::radix;
  636. }
  637. while (__exp > 0) {
  638. if (!(__exp & 1)) {
  639. __mult *= __mult;
  640. __exp >>= 1;
  641. } else {
  642. __x *= __mult;
  643. --__exp;
  644. }
  645. }
  646. return __x;
  647. }
  648. #endif // !__has_constexpr_builtin(__builtin_scalbln)
  649. return __builtin_scalbn(__x, __exp);
  650. }
  651. #if _LIBCPP_STD_VER >= 20
  652. template <typename _Fp>
  653. _LIBCPP_HIDE_FROM_ABI constexpr
  654. _Fp __lerp(_Fp __a, _Fp __b, _Fp __t) noexcept {
  655. if ((__a <= 0 && __b >= 0) || (__a >= 0 && __b <= 0))
  656. return __t * __b + (1 - __t) * __a;
  657. if (__t == 1) return __b;
  658. const _Fp __x = __a + __t * (__b - __a);
  659. if ((__t > 1) == (__b > __a))
  660. return __b < __x ? __x : __b;
  661. else
  662. return __x < __b ? __x : __b;
  663. }
  664. _LIBCPP_HIDE_FROM_ABI constexpr float
  665. lerp(float __a, float __b, float __t) _NOEXCEPT { return __lerp(__a, __b, __t); }
  666. _LIBCPP_HIDE_FROM_ABI constexpr double
  667. lerp(double __a, double __b, double __t) _NOEXCEPT { return __lerp(__a, __b, __t); }
  668. _LIBCPP_HIDE_FROM_ABI constexpr long double
  669. lerp(long double __a, long double __b, long double __t) _NOEXCEPT { return __lerp(__a, __b, __t); }
  670. template <class _A1, class _A2, class _A3>
  671. inline _LIBCPP_HIDE_FROM_ABI
  672. constexpr typename enable_if_t
  673. <
  674. is_arithmetic<_A1>::value &&
  675. is_arithmetic<_A2>::value &&
  676. is_arithmetic<_A3>::value,
  677. __promote<_A1, _A2, _A3>
  678. >::type
  679. lerp(_A1 __a, _A2 __b, _A3 __t) noexcept
  680. {
  681. typedef typename __promote<_A1, _A2, _A3>::type __result_type;
  682. static_assert(!(_IsSame<_A1, __result_type>::value &&
  683. _IsSame<_A2, __result_type>::value &&
  684. _IsSame<_A3, __result_type>::value));
  685. return std::__lerp((__result_type)__a, (__result_type)__b, (__result_type)__t);
  686. }
  687. #endif // _LIBCPP_STD_VER >= 20
  688. _LIBCPP_END_NAMESPACE_STD
  689. _LIBCPP_POP_MACROS
  690. #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
  691. # include <type_traits>
  692. #endif
  693. #endif // _LIBCPP_CMATH