tgmath.h 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384
  1. /*===---- tgmath.h - Standard header for type generic math ----------------===*\
  2. *
  3. * Copyright (c) 2009 Howard Hinnant
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. * THE SOFTWARE.
  22. *
  23. \*===----------------------------------------------------------------------===*/
  24. #ifndef __CLANG_TGMATH_H
  25. #define __CLANG_TGMATH_H
  26. /* C99 7.22 Type-generic math <tgmath.h>. */
  27. #include <math.h>
  28. /*
  29. * Allow additional definitions and implementation-defined values on Apple
  30. * platforms. This is done after #include <math.h> to avoid depcycle conflicts
  31. * between libcxx and darwin in C++ modules builds.
  32. */
  33. #if defined(__APPLE__) && __STDC_HOSTED__ && __has_include_next(<tgmath.h>)
  34. # include_next <tgmath.h>
  35. #else
  36. /* C++ handles type genericity with overloading in math.h. */
  37. #ifndef __cplusplus
  38. #include <complex.h>
  39. #define _TG_ATTRSp __attribute__((__overloadable__))
  40. #define _TG_ATTRS __attribute__((__overloadable__, __always_inline__))
  41. // promotion
  42. typedef void _Argument_type_is_not_arithmetic;
  43. static _Argument_type_is_not_arithmetic __tg_promote(...)
  44. __attribute__((__unavailable__,__overloadable__));
  45. static double _TG_ATTRSp __tg_promote(int);
  46. static double _TG_ATTRSp __tg_promote(unsigned int);
  47. static double _TG_ATTRSp __tg_promote(long);
  48. static double _TG_ATTRSp __tg_promote(unsigned long);
  49. static double _TG_ATTRSp __tg_promote(long long);
  50. static double _TG_ATTRSp __tg_promote(unsigned long long);
  51. static float _TG_ATTRSp __tg_promote(float);
  52. static double _TG_ATTRSp __tg_promote(double);
  53. static long double _TG_ATTRSp __tg_promote(long double);
  54. static float _Complex _TG_ATTRSp __tg_promote(float _Complex);
  55. static double _Complex _TG_ATTRSp __tg_promote(double _Complex);
  56. static long double _Complex _TG_ATTRSp __tg_promote(long double _Complex);
  57. #define __tg_promote1(__x) (__typeof__(__tg_promote(__x)))
  58. #define __tg_promote2(__x, __y) (__typeof__(__tg_promote(__x) + \
  59. __tg_promote(__y)))
  60. #define __tg_promote3(__x, __y, __z) (__typeof__(__tg_promote(__x) + \
  61. __tg_promote(__y) + \
  62. __tg_promote(__z)))
  63. // acos
  64. static float
  65. _TG_ATTRS
  66. __tg_acos(float __x) {return acosf(__x);}
  67. static double
  68. _TG_ATTRS
  69. __tg_acos(double __x) {return acos(__x);}
  70. static long double
  71. _TG_ATTRS
  72. __tg_acos(long double __x) {return acosl(__x);}
  73. static float _Complex
  74. _TG_ATTRS
  75. __tg_acos(float _Complex __x) {return cacosf(__x);}
  76. static double _Complex
  77. _TG_ATTRS
  78. __tg_acos(double _Complex __x) {return cacos(__x);}
  79. static long double _Complex
  80. _TG_ATTRS
  81. __tg_acos(long double _Complex __x) {return cacosl(__x);}
  82. #undef acos
  83. #define acos(__x) __tg_acos(__tg_promote1((__x))(__x))
  84. // asin
  85. static float
  86. _TG_ATTRS
  87. __tg_asin(float __x) {return asinf(__x);}
  88. static double
  89. _TG_ATTRS
  90. __tg_asin(double __x) {return asin(__x);}
  91. static long double
  92. _TG_ATTRS
  93. __tg_asin(long double __x) {return asinl(__x);}
  94. static float _Complex
  95. _TG_ATTRS
  96. __tg_asin(float _Complex __x) {return casinf(__x);}
  97. static double _Complex
  98. _TG_ATTRS
  99. __tg_asin(double _Complex __x) {return casin(__x);}
  100. static long double _Complex
  101. _TG_ATTRS
  102. __tg_asin(long double _Complex __x) {return casinl(__x);}
  103. #undef asin
  104. #define asin(__x) __tg_asin(__tg_promote1((__x))(__x))
  105. // atan
  106. static float
  107. _TG_ATTRS
  108. __tg_atan(float __x) {return atanf(__x);}
  109. static double
  110. _TG_ATTRS
  111. __tg_atan(double __x) {return atan(__x);}
  112. static long double
  113. _TG_ATTRS
  114. __tg_atan(long double __x) {return atanl(__x);}
  115. static float _Complex
  116. _TG_ATTRS
  117. __tg_atan(float _Complex __x) {return catanf(__x);}
  118. static double _Complex
  119. _TG_ATTRS
  120. __tg_atan(double _Complex __x) {return catan(__x);}
  121. static long double _Complex
  122. _TG_ATTRS
  123. __tg_atan(long double _Complex __x) {return catanl(__x);}
  124. #undef atan
  125. #define atan(__x) __tg_atan(__tg_promote1((__x))(__x))
  126. // acosh
  127. static float
  128. _TG_ATTRS
  129. __tg_acosh(float __x) {return acoshf(__x);}
  130. static double
  131. _TG_ATTRS
  132. __tg_acosh(double __x) {return acosh(__x);}
  133. static long double
  134. _TG_ATTRS
  135. __tg_acosh(long double __x) {return acoshl(__x);}
  136. static float _Complex
  137. _TG_ATTRS
  138. __tg_acosh(float _Complex __x) {return cacoshf(__x);}
  139. static double _Complex
  140. _TG_ATTRS
  141. __tg_acosh(double _Complex __x) {return cacosh(__x);}
  142. static long double _Complex
  143. _TG_ATTRS
  144. __tg_acosh(long double _Complex __x) {return cacoshl(__x);}
  145. #undef acosh
  146. #define acosh(__x) __tg_acosh(__tg_promote1((__x))(__x))
  147. // asinh
  148. static float
  149. _TG_ATTRS
  150. __tg_asinh(float __x) {return asinhf(__x);}
  151. static double
  152. _TG_ATTRS
  153. __tg_asinh(double __x) {return asinh(__x);}
  154. static long double
  155. _TG_ATTRS
  156. __tg_asinh(long double __x) {return asinhl(__x);}
  157. static float _Complex
  158. _TG_ATTRS
  159. __tg_asinh(float _Complex __x) {return casinhf(__x);}
  160. static double _Complex
  161. _TG_ATTRS
  162. __tg_asinh(double _Complex __x) {return casinh(__x);}
  163. static long double _Complex
  164. _TG_ATTRS
  165. __tg_asinh(long double _Complex __x) {return casinhl(__x);}
  166. #undef asinh
  167. #define asinh(__x) __tg_asinh(__tg_promote1((__x))(__x))
  168. // atanh
  169. static float
  170. _TG_ATTRS
  171. __tg_atanh(float __x) {return atanhf(__x);}
  172. static double
  173. _TG_ATTRS
  174. __tg_atanh(double __x) {return atanh(__x);}
  175. static long double
  176. _TG_ATTRS
  177. __tg_atanh(long double __x) {return atanhl(__x);}
  178. static float _Complex
  179. _TG_ATTRS
  180. __tg_atanh(float _Complex __x) {return catanhf(__x);}
  181. static double _Complex
  182. _TG_ATTRS
  183. __tg_atanh(double _Complex __x) {return catanh(__x);}
  184. static long double _Complex
  185. _TG_ATTRS
  186. __tg_atanh(long double _Complex __x) {return catanhl(__x);}
  187. #undef atanh
  188. #define atanh(__x) __tg_atanh(__tg_promote1((__x))(__x))
  189. // cos
  190. static float
  191. _TG_ATTRS
  192. __tg_cos(float __x) {return cosf(__x);}
  193. static double
  194. _TG_ATTRS
  195. __tg_cos(double __x) {return cos(__x);}
  196. static long double
  197. _TG_ATTRS
  198. __tg_cos(long double __x) {return cosl(__x);}
  199. static float _Complex
  200. _TG_ATTRS
  201. __tg_cos(float _Complex __x) {return ccosf(__x);}
  202. static double _Complex
  203. _TG_ATTRS
  204. __tg_cos(double _Complex __x) {return ccos(__x);}
  205. static long double _Complex
  206. _TG_ATTRS
  207. __tg_cos(long double _Complex __x) {return ccosl(__x);}
  208. #undef cos
  209. #define cos(__x) __tg_cos(__tg_promote1((__x))(__x))
  210. // sin
  211. static float
  212. _TG_ATTRS
  213. __tg_sin(float __x) {return sinf(__x);}
  214. static double
  215. _TG_ATTRS
  216. __tg_sin(double __x) {return sin(__x);}
  217. static long double
  218. _TG_ATTRS
  219. __tg_sin(long double __x) {return sinl(__x);}
  220. static float _Complex
  221. _TG_ATTRS
  222. __tg_sin(float _Complex __x) {return csinf(__x);}
  223. static double _Complex
  224. _TG_ATTRS
  225. __tg_sin(double _Complex __x) {return csin(__x);}
  226. static long double _Complex
  227. _TG_ATTRS
  228. __tg_sin(long double _Complex __x) {return csinl(__x);}
  229. #undef sin
  230. #define sin(__x) __tg_sin(__tg_promote1((__x))(__x))
  231. // tan
  232. static float
  233. _TG_ATTRS
  234. __tg_tan(float __x) {return tanf(__x);}
  235. static double
  236. _TG_ATTRS
  237. __tg_tan(double __x) {return tan(__x);}
  238. static long double
  239. _TG_ATTRS
  240. __tg_tan(long double __x) {return tanl(__x);}
  241. static float _Complex
  242. _TG_ATTRS
  243. __tg_tan(float _Complex __x) {return ctanf(__x);}
  244. static double _Complex
  245. _TG_ATTRS
  246. __tg_tan(double _Complex __x) {return ctan(__x);}
  247. static long double _Complex
  248. _TG_ATTRS
  249. __tg_tan(long double _Complex __x) {return ctanl(__x);}
  250. #undef tan
  251. #define tan(__x) __tg_tan(__tg_promote1((__x))(__x))
  252. // cosh
  253. static float
  254. _TG_ATTRS
  255. __tg_cosh(float __x) {return coshf(__x);}
  256. static double
  257. _TG_ATTRS
  258. __tg_cosh(double __x) {return cosh(__x);}
  259. static long double
  260. _TG_ATTRS
  261. __tg_cosh(long double __x) {return coshl(__x);}
  262. static float _Complex
  263. _TG_ATTRS
  264. __tg_cosh(float _Complex __x) {return ccoshf(__x);}
  265. static double _Complex
  266. _TG_ATTRS
  267. __tg_cosh(double _Complex __x) {return ccosh(__x);}
  268. static long double _Complex
  269. _TG_ATTRS
  270. __tg_cosh(long double _Complex __x) {return ccoshl(__x);}
  271. #undef cosh
  272. #define cosh(__x) __tg_cosh(__tg_promote1((__x))(__x))
  273. // sinh
  274. static float
  275. _TG_ATTRS
  276. __tg_sinh(float __x) {return sinhf(__x);}
  277. static double
  278. _TG_ATTRS
  279. __tg_sinh(double __x) {return sinh(__x);}
  280. static long double
  281. _TG_ATTRS
  282. __tg_sinh(long double __x) {return sinhl(__x);}
  283. static float _Complex
  284. _TG_ATTRS
  285. __tg_sinh(float _Complex __x) {return csinhf(__x);}
  286. static double _Complex
  287. _TG_ATTRS
  288. __tg_sinh(double _Complex __x) {return csinh(__x);}
  289. static long double _Complex
  290. _TG_ATTRS
  291. __tg_sinh(long double _Complex __x) {return csinhl(__x);}
  292. #undef sinh
  293. #define sinh(__x) __tg_sinh(__tg_promote1((__x))(__x))
  294. // tanh
  295. static float
  296. _TG_ATTRS
  297. __tg_tanh(float __x) {return tanhf(__x);}
  298. static double
  299. _TG_ATTRS
  300. __tg_tanh(double __x) {return tanh(__x);}
  301. static long double
  302. _TG_ATTRS
  303. __tg_tanh(long double __x) {return tanhl(__x);}
  304. static float _Complex
  305. _TG_ATTRS
  306. __tg_tanh(float _Complex __x) {return ctanhf(__x);}
  307. static double _Complex
  308. _TG_ATTRS
  309. __tg_tanh(double _Complex __x) {return ctanh(__x);}
  310. static long double _Complex
  311. _TG_ATTRS
  312. __tg_tanh(long double _Complex __x) {return ctanhl(__x);}
  313. #undef tanh
  314. #define tanh(__x) __tg_tanh(__tg_promote1((__x))(__x))
  315. // exp
  316. static float
  317. _TG_ATTRS
  318. __tg_exp(float __x) {return expf(__x);}
  319. static double
  320. _TG_ATTRS
  321. __tg_exp(double __x) {return exp(__x);}
  322. static long double
  323. _TG_ATTRS
  324. __tg_exp(long double __x) {return expl(__x);}
  325. static float _Complex
  326. _TG_ATTRS
  327. __tg_exp(float _Complex __x) {return cexpf(__x);}
  328. static double _Complex
  329. _TG_ATTRS
  330. __tg_exp(double _Complex __x) {return cexp(__x);}
  331. static long double _Complex
  332. _TG_ATTRS
  333. __tg_exp(long double _Complex __x) {return cexpl(__x);}
  334. #undef exp
  335. #define exp(__x) __tg_exp(__tg_promote1((__x))(__x))
  336. // log
  337. static float
  338. _TG_ATTRS
  339. __tg_log(float __x) {return logf(__x);}
  340. static double
  341. _TG_ATTRS
  342. __tg_log(double __x) {return log(__x);}
  343. static long double
  344. _TG_ATTRS
  345. __tg_log(long double __x) {return logl(__x);}
  346. static float _Complex
  347. _TG_ATTRS
  348. __tg_log(float _Complex __x) {return clogf(__x);}
  349. static double _Complex
  350. _TG_ATTRS
  351. __tg_log(double _Complex __x) {return clog(__x);}
  352. static long double _Complex
  353. _TG_ATTRS
  354. __tg_log(long double _Complex __x) {return clogl(__x);}
  355. #undef log
  356. #define log(__x) __tg_log(__tg_promote1((__x))(__x))
  357. // pow
  358. static float
  359. _TG_ATTRS
  360. __tg_pow(float __x, float __y) {return powf(__x, __y);}
  361. static double
  362. _TG_ATTRS
  363. __tg_pow(double __x, double __y) {return pow(__x, __y);}
  364. static long double
  365. _TG_ATTRS
  366. __tg_pow(long double __x, long double __y) {return powl(__x, __y);}
  367. static float _Complex
  368. _TG_ATTRS
  369. __tg_pow(float _Complex __x, float _Complex __y) {return cpowf(__x, __y);}
  370. static double _Complex
  371. _TG_ATTRS
  372. __tg_pow(double _Complex __x, double _Complex __y) {return cpow(__x, __y);}
  373. static long double _Complex
  374. _TG_ATTRS
  375. __tg_pow(long double _Complex __x, long double _Complex __y)
  376. {return cpowl(__x, __y);}
  377. #undef pow
  378. #define pow(__x, __y) __tg_pow(__tg_promote2((__x), (__y))(__x), \
  379. __tg_promote2((__x), (__y))(__y))
  380. // sqrt
  381. static float
  382. _TG_ATTRS
  383. __tg_sqrt(float __x) {return sqrtf(__x);}
  384. static double
  385. _TG_ATTRS
  386. __tg_sqrt(double __x) {return sqrt(__x);}
  387. static long double
  388. _TG_ATTRS
  389. __tg_sqrt(long double __x) {return sqrtl(__x);}
  390. static float _Complex
  391. _TG_ATTRS
  392. __tg_sqrt(float _Complex __x) {return csqrtf(__x);}
  393. static double _Complex
  394. _TG_ATTRS
  395. __tg_sqrt(double _Complex __x) {return csqrt(__x);}
  396. static long double _Complex
  397. _TG_ATTRS
  398. __tg_sqrt(long double _Complex __x) {return csqrtl(__x);}
  399. #undef sqrt
  400. #define sqrt(__x) __tg_sqrt(__tg_promote1((__x))(__x))
  401. // fabs
  402. static float
  403. _TG_ATTRS
  404. __tg_fabs(float __x) {return fabsf(__x);}
  405. static double
  406. _TG_ATTRS
  407. __tg_fabs(double __x) {return fabs(__x);}
  408. static long double
  409. _TG_ATTRS
  410. __tg_fabs(long double __x) {return fabsl(__x);}
  411. static float
  412. _TG_ATTRS
  413. __tg_fabs(float _Complex __x) {return cabsf(__x);}
  414. static double
  415. _TG_ATTRS
  416. __tg_fabs(double _Complex __x) {return cabs(__x);}
  417. static long double
  418. _TG_ATTRS
  419. __tg_fabs(long double _Complex __x) {return cabsl(__x);}
  420. #undef fabs
  421. #define fabs(__x) __tg_fabs(__tg_promote1((__x))(__x))
  422. // atan2
  423. static float
  424. _TG_ATTRS
  425. __tg_atan2(float __x, float __y) {return atan2f(__x, __y);}
  426. static double
  427. _TG_ATTRS
  428. __tg_atan2(double __x, double __y) {return atan2(__x, __y);}
  429. static long double
  430. _TG_ATTRS
  431. __tg_atan2(long double __x, long double __y) {return atan2l(__x, __y);}
  432. #undef atan2
  433. #define atan2(__x, __y) __tg_atan2(__tg_promote2((__x), (__y))(__x), \
  434. __tg_promote2((__x), (__y))(__y))
  435. // cbrt
  436. static float
  437. _TG_ATTRS
  438. __tg_cbrt(float __x) {return cbrtf(__x);}
  439. static double
  440. _TG_ATTRS
  441. __tg_cbrt(double __x) {return cbrt(__x);}
  442. static long double
  443. _TG_ATTRS
  444. __tg_cbrt(long double __x) {return cbrtl(__x);}
  445. #undef cbrt
  446. #define cbrt(__x) __tg_cbrt(__tg_promote1((__x))(__x))
  447. // ceil
  448. static float
  449. _TG_ATTRS
  450. __tg_ceil(float __x) {return ceilf(__x);}
  451. static double
  452. _TG_ATTRS
  453. __tg_ceil(double __x) {return ceil(__x);}
  454. static long double
  455. _TG_ATTRS
  456. __tg_ceil(long double __x) {return ceill(__x);}
  457. #undef ceil
  458. #define ceil(__x) __tg_ceil(__tg_promote1((__x))(__x))
  459. // copysign
  460. static float
  461. _TG_ATTRS
  462. __tg_copysign(float __x, float __y) {return copysignf(__x, __y);}
  463. static double
  464. _TG_ATTRS
  465. __tg_copysign(double __x, double __y) {return copysign(__x, __y);}
  466. static long double
  467. _TG_ATTRS
  468. __tg_copysign(long double __x, long double __y) {return copysignl(__x, __y);}
  469. #undef copysign
  470. #define copysign(__x, __y) __tg_copysign(__tg_promote2((__x), (__y))(__x), \
  471. __tg_promote2((__x), (__y))(__y))
  472. // erf
  473. static float
  474. _TG_ATTRS
  475. __tg_erf(float __x) {return erff(__x);}
  476. static double
  477. _TG_ATTRS
  478. __tg_erf(double __x) {return erf(__x);}
  479. static long double
  480. _TG_ATTRS
  481. __tg_erf(long double __x) {return erfl(__x);}
  482. #undef erf
  483. #define erf(__x) __tg_erf(__tg_promote1((__x))(__x))
  484. // erfc
  485. static float
  486. _TG_ATTRS
  487. __tg_erfc(float __x) {return erfcf(__x);}
  488. static double
  489. _TG_ATTRS
  490. __tg_erfc(double __x) {return erfc(__x);}
  491. static long double
  492. _TG_ATTRS
  493. __tg_erfc(long double __x) {return erfcl(__x);}
  494. #undef erfc
  495. #define erfc(__x) __tg_erfc(__tg_promote1((__x))(__x))
  496. // exp2
  497. static float
  498. _TG_ATTRS
  499. __tg_exp2(float __x) {return exp2f(__x);}
  500. static double
  501. _TG_ATTRS
  502. __tg_exp2(double __x) {return exp2(__x);}
  503. static long double
  504. _TG_ATTRS
  505. __tg_exp2(long double __x) {return exp2l(__x);}
  506. #undef exp2
  507. #define exp2(__x) __tg_exp2(__tg_promote1((__x))(__x))
  508. // expm1
  509. static float
  510. _TG_ATTRS
  511. __tg_expm1(float __x) {return expm1f(__x);}
  512. static double
  513. _TG_ATTRS
  514. __tg_expm1(double __x) {return expm1(__x);}
  515. static long double
  516. _TG_ATTRS
  517. __tg_expm1(long double __x) {return expm1l(__x);}
  518. #undef expm1
  519. #define expm1(__x) __tg_expm1(__tg_promote1((__x))(__x))
  520. // fdim
  521. static float
  522. _TG_ATTRS
  523. __tg_fdim(float __x, float __y) {return fdimf(__x, __y);}
  524. static double
  525. _TG_ATTRS
  526. __tg_fdim(double __x, double __y) {return fdim(__x, __y);}
  527. static long double
  528. _TG_ATTRS
  529. __tg_fdim(long double __x, long double __y) {return fdiml(__x, __y);}
  530. #undef fdim
  531. #define fdim(__x, __y) __tg_fdim(__tg_promote2((__x), (__y))(__x), \
  532. __tg_promote2((__x), (__y))(__y))
  533. // floor
  534. static float
  535. _TG_ATTRS
  536. __tg_floor(float __x) {return floorf(__x);}
  537. static double
  538. _TG_ATTRS
  539. __tg_floor(double __x) {return floor(__x);}
  540. static long double
  541. _TG_ATTRS
  542. __tg_floor(long double __x) {return floorl(__x);}
  543. #undef floor
  544. #define floor(__x) __tg_floor(__tg_promote1((__x))(__x))
  545. // fma
  546. static float
  547. _TG_ATTRS
  548. __tg_fma(float __x, float __y, float __z)
  549. {return fmaf(__x, __y, __z);}
  550. static double
  551. _TG_ATTRS
  552. __tg_fma(double __x, double __y, double __z)
  553. {return fma(__x, __y, __z);}
  554. static long double
  555. _TG_ATTRS
  556. __tg_fma(long double __x,long double __y, long double __z)
  557. {return fmal(__x, __y, __z);}
  558. #undef fma
  559. #define fma(__x, __y, __z) \
  560. __tg_fma(__tg_promote3((__x), (__y), (__z))(__x), \
  561. __tg_promote3((__x), (__y), (__z))(__y), \
  562. __tg_promote3((__x), (__y), (__z))(__z))
  563. // fmax
  564. static float
  565. _TG_ATTRS
  566. __tg_fmax(float __x, float __y) {return fmaxf(__x, __y);}
  567. static double
  568. _TG_ATTRS
  569. __tg_fmax(double __x, double __y) {return fmax(__x, __y);}
  570. static long double
  571. _TG_ATTRS
  572. __tg_fmax(long double __x, long double __y) {return fmaxl(__x, __y);}
  573. #undef fmax
  574. #define fmax(__x, __y) __tg_fmax(__tg_promote2((__x), (__y))(__x), \
  575. __tg_promote2((__x), (__y))(__y))
  576. // fmin
  577. static float
  578. _TG_ATTRS
  579. __tg_fmin(float __x, float __y) {return fminf(__x, __y);}
  580. static double
  581. _TG_ATTRS
  582. __tg_fmin(double __x, double __y) {return fmin(__x, __y);}
  583. static long double
  584. _TG_ATTRS
  585. __tg_fmin(long double __x, long double __y) {return fminl(__x, __y);}
  586. #undef fmin
  587. #define fmin(__x, __y) __tg_fmin(__tg_promote2((__x), (__y))(__x), \
  588. __tg_promote2((__x), (__y))(__y))
  589. // fmod
  590. static float
  591. _TG_ATTRS
  592. __tg_fmod(float __x, float __y) {return fmodf(__x, __y);}
  593. static double
  594. _TG_ATTRS
  595. __tg_fmod(double __x, double __y) {return fmod(__x, __y);}
  596. static long double
  597. _TG_ATTRS
  598. __tg_fmod(long double __x, long double __y) {return fmodl(__x, __y);}
  599. #undef fmod
  600. #define fmod(__x, __y) __tg_fmod(__tg_promote2((__x), (__y))(__x), \
  601. __tg_promote2((__x), (__y))(__y))
  602. // frexp
  603. static float
  604. _TG_ATTRS
  605. __tg_frexp(float __x, int* __y) {return frexpf(__x, __y);}
  606. static double
  607. _TG_ATTRS
  608. __tg_frexp(double __x, int* __y) {return frexp(__x, __y);}
  609. static long double
  610. _TG_ATTRS
  611. __tg_frexp(long double __x, int* __y) {return frexpl(__x, __y);}
  612. #undef frexp
  613. #define frexp(__x, __y) __tg_frexp(__tg_promote1((__x))(__x), __y)
  614. // hypot
  615. static float
  616. _TG_ATTRS
  617. __tg_hypot(float __x, float __y) {return hypotf(__x, __y);}
  618. static double
  619. _TG_ATTRS
  620. __tg_hypot(double __x, double __y) {return hypot(__x, __y);}
  621. static long double
  622. _TG_ATTRS
  623. __tg_hypot(long double __x, long double __y) {return hypotl(__x, __y);}
  624. #undef hypot
  625. #define hypot(__x, __y) __tg_hypot(__tg_promote2((__x), (__y))(__x), \
  626. __tg_promote2((__x), (__y))(__y))
  627. // ilogb
  628. static int
  629. _TG_ATTRS
  630. __tg_ilogb(float __x) {return ilogbf(__x);}
  631. static int
  632. _TG_ATTRS
  633. __tg_ilogb(double __x) {return ilogb(__x);}
  634. static int
  635. _TG_ATTRS
  636. __tg_ilogb(long double __x) {return ilogbl(__x);}
  637. #undef ilogb
  638. #define ilogb(__x) __tg_ilogb(__tg_promote1((__x))(__x))
  639. // ldexp
  640. static float
  641. _TG_ATTRS
  642. __tg_ldexp(float __x, int __y) {return ldexpf(__x, __y);}
  643. static double
  644. _TG_ATTRS
  645. __tg_ldexp(double __x, int __y) {return ldexp(__x, __y);}
  646. static long double
  647. _TG_ATTRS
  648. __tg_ldexp(long double __x, int __y) {return ldexpl(__x, __y);}
  649. #undef ldexp
  650. #define ldexp(__x, __y) __tg_ldexp(__tg_promote1((__x))(__x), __y)
  651. // lgamma
  652. static float
  653. _TG_ATTRS
  654. __tg_lgamma(float __x) {return lgammaf(__x);}
  655. static double
  656. _TG_ATTRS
  657. __tg_lgamma(double __x) {return lgamma(__x);}
  658. static long double
  659. _TG_ATTRS
  660. __tg_lgamma(long double __x) {return lgammal(__x);}
  661. #undef lgamma
  662. #define lgamma(__x) __tg_lgamma(__tg_promote1((__x))(__x))
  663. // llrint
  664. static long long
  665. _TG_ATTRS
  666. __tg_llrint(float __x) {return llrintf(__x);}
  667. static long long
  668. _TG_ATTRS
  669. __tg_llrint(double __x) {return llrint(__x);}
  670. static long long
  671. _TG_ATTRS
  672. __tg_llrint(long double __x) {return llrintl(__x);}
  673. #undef llrint
  674. #define llrint(__x) __tg_llrint(__tg_promote1((__x))(__x))
  675. // llround
  676. static long long
  677. _TG_ATTRS
  678. __tg_llround(float __x) {return llroundf(__x);}
  679. static long long
  680. _TG_ATTRS
  681. __tg_llround(double __x) {return llround(__x);}
  682. static long long
  683. _TG_ATTRS
  684. __tg_llround(long double __x) {return llroundl(__x);}
  685. #undef llround
  686. #define llround(__x) __tg_llround(__tg_promote1((__x))(__x))
  687. // log10
  688. static float
  689. _TG_ATTRS
  690. __tg_log10(float __x) {return log10f(__x);}
  691. static double
  692. _TG_ATTRS
  693. __tg_log10(double __x) {return log10(__x);}
  694. static long double
  695. _TG_ATTRS
  696. __tg_log10(long double __x) {return log10l(__x);}
  697. #undef log10
  698. #define log10(__x) __tg_log10(__tg_promote1((__x))(__x))
  699. // log1p
  700. static float
  701. _TG_ATTRS
  702. __tg_log1p(float __x) {return log1pf(__x);}
  703. static double
  704. _TG_ATTRS
  705. __tg_log1p(double __x) {return log1p(__x);}
  706. static long double
  707. _TG_ATTRS
  708. __tg_log1p(long double __x) {return log1pl(__x);}
  709. #undef log1p
  710. #define log1p(__x) __tg_log1p(__tg_promote1((__x))(__x))
  711. // log2
  712. static float
  713. _TG_ATTRS
  714. __tg_log2(float __x) {return log2f(__x);}
  715. static double
  716. _TG_ATTRS
  717. __tg_log2(double __x) {return log2(__x);}
  718. static long double
  719. _TG_ATTRS
  720. __tg_log2(long double __x) {return log2l(__x);}
  721. #undef log2
  722. #define log2(__x) __tg_log2(__tg_promote1((__x))(__x))
  723. // logb
  724. static float
  725. _TG_ATTRS
  726. __tg_logb(float __x) {return logbf(__x);}
  727. static double
  728. _TG_ATTRS
  729. __tg_logb(double __x) {return logb(__x);}
  730. static long double
  731. _TG_ATTRS
  732. __tg_logb(long double __x) {return logbl(__x);}
  733. #undef logb
  734. #define logb(__x) __tg_logb(__tg_promote1((__x))(__x))
  735. // lrint
  736. static long
  737. _TG_ATTRS
  738. __tg_lrint(float __x) {return lrintf(__x);}
  739. static long
  740. _TG_ATTRS
  741. __tg_lrint(double __x) {return lrint(__x);}
  742. static long
  743. _TG_ATTRS
  744. __tg_lrint(long double __x) {return lrintl(__x);}
  745. #undef lrint
  746. #define lrint(__x) __tg_lrint(__tg_promote1((__x))(__x))
  747. // lround
  748. static long
  749. _TG_ATTRS
  750. __tg_lround(float __x) {return lroundf(__x);}
  751. static long
  752. _TG_ATTRS
  753. __tg_lround(double __x) {return lround(__x);}
  754. static long
  755. _TG_ATTRS
  756. __tg_lround(long double __x) {return lroundl(__x);}
  757. #undef lround
  758. #define lround(__x) __tg_lround(__tg_promote1((__x))(__x))
  759. // nearbyint
  760. static float
  761. _TG_ATTRS
  762. __tg_nearbyint(float __x) {return nearbyintf(__x);}
  763. static double
  764. _TG_ATTRS
  765. __tg_nearbyint(double __x) {return nearbyint(__x);}
  766. static long double
  767. _TG_ATTRS
  768. __tg_nearbyint(long double __x) {return nearbyintl(__x);}
  769. #undef nearbyint
  770. #define nearbyint(__x) __tg_nearbyint(__tg_promote1((__x))(__x))
  771. // nextafter
  772. static float
  773. _TG_ATTRS
  774. __tg_nextafter(float __x, float __y) {return nextafterf(__x, __y);}
  775. static double
  776. _TG_ATTRS
  777. __tg_nextafter(double __x, double __y) {return nextafter(__x, __y);}
  778. static long double
  779. _TG_ATTRS
  780. __tg_nextafter(long double __x, long double __y) {return nextafterl(__x, __y);}
  781. #undef nextafter
  782. #define nextafter(__x, __y) __tg_nextafter(__tg_promote2((__x), (__y))(__x), \
  783. __tg_promote2((__x), (__y))(__y))
  784. // nexttoward
  785. static float
  786. _TG_ATTRS
  787. __tg_nexttoward(float __x, long double __y) {return nexttowardf(__x, __y);}
  788. static double
  789. _TG_ATTRS
  790. __tg_nexttoward(double __x, long double __y) {return nexttoward(__x, __y);}
  791. static long double
  792. _TG_ATTRS
  793. __tg_nexttoward(long double __x, long double __y) {return nexttowardl(__x, __y);}
  794. #undef nexttoward
  795. #define nexttoward(__x, __y) __tg_nexttoward(__tg_promote1((__x))(__x), (__y))
  796. // remainder
  797. static float
  798. _TG_ATTRS
  799. __tg_remainder(float __x, float __y) {return remainderf(__x, __y);}
  800. static double
  801. _TG_ATTRS
  802. __tg_remainder(double __x, double __y) {return remainder(__x, __y);}
  803. static long double
  804. _TG_ATTRS
  805. __tg_remainder(long double __x, long double __y) {return remainderl(__x, __y);}
  806. #undef remainder
  807. #define remainder(__x, __y) __tg_remainder(__tg_promote2((__x), (__y))(__x), \
  808. __tg_promote2((__x), (__y))(__y))
  809. // remquo
  810. static float
  811. _TG_ATTRS
  812. __tg_remquo(float __x, float __y, int* __z)
  813. {return remquof(__x, __y, __z);}
  814. static double
  815. _TG_ATTRS
  816. __tg_remquo(double __x, double __y, int* __z)
  817. {return remquo(__x, __y, __z);}
  818. static long double
  819. _TG_ATTRS
  820. __tg_remquo(long double __x,long double __y, int* __z)
  821. {return remquol(__x, __y, __z);}
  822. #undef remquo
  823. #define remquo(__x, __y, __z) \
  824. __tg_remquo(__tg_promote2((__x), (__y))(__x), \
  825. __tg_promote2((__x), (__y))(__y), \
  826. (__z))
  827. // rint
  828. static float
  829. _TG_ATTRS
  830. __tg_rint(float __x) {return rintf(__x);}
  831. static double
  832. _TG_ATTRS
  833. __tg_rint(double __x) {return rint(__x);}
  834. static long double
  835. _TG_ATTRS
  836. __tg_rint(long double __x) {return rintl(__x);}
  837. #undef rint
  838. #define rint(__x) __tg_rint(__tg_promote1((__x))(__x))
  839. // round
  840. static float
  841. _TG_ATTRS
  842. __tg_round(float __x) {return roundf(__x);}
  843. static double
  844. _TG_ATTRS
  845. __tg_round(double __x) {return round(__x);}
  846. static long double
  847. _TG_ATTRS
  848. __tg_round(long double __x) {return roundl(__x);}
  849. #undef round
  850. #define round(__x) __tg_round(__tg_promote1((__x))(__x))
  851. // scalbn
  852. static float
  853. _TG_ATTRS
  854. __tg_scalbn(float __x, int __y) {return scalbnf(__x, __y);}
  855. static double
  856. _TG_ATTRS
  857. __tg_scalbn(double __x, int __y) {return scalbn(__x, __y);}
  858. static long double
  859. _TG_ATTRS
  860. __tg_scalbn(long double __x, int __y) {return scalbnl(__x, __y);}
  861. #undef scalbn
  862. #define scalbn(__x, __y) __tg_scalbn(__tg_promote1((__x))(__x), __y)
  863. // scalbln
  864. static float
  865. _TG_ATTRS
  866. __tg_scalbln(float __x, long __y) {return scalblnf(__x, __y);}
  867. static double
  868. _TG_ATTRS
  869. __tg_scalbln(double __x, long __y) {return scalbln(__x, __y);}
  870. static long double
  871. _TG_ATTRS
  872. __tg_scalbln(long double __x, long __y) {return scalblnl(__x, __y);}
  873. #undef scalbln
  874. #define scalbln(__x, __y) __tg_scalbln(__tg_promote1((__x))(__x), __y)
  875. // tgamma
  876. static float
  877. _TG_ATTRS
  878. __tg_tgamma(float __x) {return tgammaf(__x);}
  879. static double
  880. _TG_ATTRS
  881. __tg_tgamma(double __x) {return tgamma(__x);}
  882. static long double
  883. _TG_ATTRS
  884. __tg_tgamma(long double __x) {return tgammal(__x);}
  885. #undef tgamma
  886. #define tgamma(__x) __tg_tgamma(__tg_promote1((__x))(__x))
  887. // trunc
  888. static float
  889. _TG_ATTRS
  890. __tg_trunc(float __x) {return truncf(__x);}
  891. static double
  892. _TG_ATTRS
  893. __tg_trunc(double __x) {return trunc(__x);}
  894. static long double
  895. _TG_ATTRS
  896. __tg_trunc(long double __x) {return truncl(__x);}
  897. #undef trunc
  898. #define trunc(__x) __tg_trunc(__tg_promote1((__x))(__x))
  899. // carg
  900. static float
  901. _TG_ATTRS
  902. __tg_carg(float __x) {return atan2f(0.F, __x);}
  903. static double
  904. _TG_ATTRS
  905. __tg_carg(double __x) {return atan2(0., __x);}
  906. static long double
  907. _TG_ATTRS
  908. __tg_carg(long double __x) {return atan2l(0.L, __x);}
  909. static float
  910. _TG_ATTRS
  911. __tg_carg(float _Complex __x) {return cargf(__x);}
  912. static double
  913. _TG_ATTRS
  914. __tg_carg(double _Complex __x) {return carg(__x);}
  915. static long double
  916. _TG_ATTRS
  917. __tg_carg(long double _Complex __x) {return cargl(__x);}
  918. #undef carg
  919. #define carg(__x) __tg_carg(__tg_promote1((__x))(__x))
  920. // cimag
  921. static float
  922. _TG_ATTRS
  923. __tg_cimag(float __x) {return 0;}
  924. static double
  925. _TG_ATTRS
  926. __tg_cimag(double __x) {return 0;}
  927. static long double
  928. _TG_ATTRS
  929. __tg_cimag(long double __x) {return 0;}
  930. static float
  931. _TG_ATTRS
  932. __tg_cimag(float _Complex __x) {return cimagf(__x);}
  933. static double
  934. _TG_ATTRS
  935. __tg_cimag(double _Complex __x) {return cimag(__x);}
  936. static long double
  937. _TG_ATTRS
  938. __tg_cimag(long double _Complex __x) {return cimagl(__x);}
  939. #undef cimag
  940. #define cimag(__x) __tg_cimag(__tg_promote1((__x))(__x))
  941. // conj
  942. static float _Complex
  943. _TG_ATTRS
  944. __tg_conj(float __x) {return __x;}
  945. static double _Complex
  946. _TG_ATTRS
  947. __tg_conj(double __x) {return __x;}
  948. static long double _Complex
  949. _TG_ATTRS
  950. __tg_conj(long double __x) {return __x;}
  951. static float _Complex
  952. _TG_ATTRS
  953. __tg_conj(float _Complex __x) {return conjf(__x);}
  954. static double _Complex
  955. _TG_ATTRS
  956. __tg_conj(double _Complex __x) {return conj(__x);}
  957. static long double _Complex
  958. _TG_ATTRS
  959. __tg_conj(long double _Complex __x) {return conjl(__x);}
  960. #undef conj
  961. #define conj(__x) __tg_conj(__tg_promote1((__x))(__x))
  962. // cproj
  963. static float _Complex
  964. _TG_ATTRS
  965. __tg_cproj(float __x) {return cprojf(__x);}
  966. static double _Complex
  967. _TG_ATTRS
  968. __tg_cproj(double __x) {return cproj(__x);}
  969. static long double _Complex
  970. _TG_ATTRS
  971. __tg_cproj(long double __x) {return cprojl(__x);}
  972. static float _Complex
  973. _TG_ATTRS
  974. __tg_cproj(float _Complex __x) {return cprojf(__x);}
  975. static double _Complex
  976. _TG_ATTRS
  977. __tg_cproj(double _Complex __x) {return cproj(__x);}
  978. static long double _Complex
  979. _TG_ATTRS
  980. __tg_cproj(long double _Complex __x) {return cprojl(__x);}
  981. #undef cproj
  982. #define cproj(__x) __tg_cproj(__tg_promote1((__x))(__x))
  983. // creal
  984. static float
  985. _TG_ATTRS
  986. __tg_creal(float __x) {return __x;}
  987. static double
  988. _TG_ATTRS
  989. __tg_creal(double __x) {return __x;}
  990. static long double
  991. _TG_ATTRS
  992. __tg_creal(long double __x) {return __x;}
  993. static float
  994. _TG_ATTRS
  995. __tg_creal(float _Complex __x) {return crealf(__x);}
  996. static double
  997. _TG_ATTRS
  998. __tg_creal(double _Complex __x) {return creal(__x);}
  999. static long double
  1000. _TG_ATTRS
  1001. __tg_creal(long double _Complex __x) {return creall(__x);}
  1002. #undef creal
  1003. #define creal(__x) __tg_creal(__tg_promote1((__x))(__x))
  1004. #undef _TG_ATTRSp
  1005. #undef _TG_ATTRS
  1006. #endif /* __cplusplus */
  1007. #endif /* __has_include_next */
  1008. #endif /* __CLANG_TGMATH_H */