tgmath.h 30 KB

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