ldouble_wrappers.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Wrapper functions implementing all the long double math functions
  4. * defined by SuSv3 by actually calling the double version of
  5. * each function and then casting the result back to a long double
  6. * to return to the user.
  7. *
  8. * Copyright (C) 2005 by Erik Andersen <andersen@uclibc.org>
  9. *
  10. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  11. */
  12. #include <features.h>
  13. /* Prevent math.h from defining colliding inlines */
  14. #undef __USE_EXTERN_INLINES
  15. #include "math.h"
  16. #include <complex.h>
  17. #if !defined __NO_LONG_DOUBLE_MATH
  18. # define WRAPPER1(func) \
  19. long double func##l(long double x) \
  20. { \
  21. return (long double) func((double) x); \
  22. }
  23. # define WRAPPER2(func) \
  24. long double func##l(long double x, long double y) \
  25. { \
  26. return (long double) func((double) x, (double) y); \
  27. }
  28. # define int_WRAPPER1(func) \
  29. int func##l(long double x) \
  30. { \
  31. return func((double) x); \
  32. }
  33. # define long_WRAPPER1(func) \
  34. long func##l(long double x) \
  35. { \
  36. return func((double) x); \
  37. }
  38. # define long_long_WRAPPER1(func) \
  39. long long func##l(long double x) \
  40. { \
  41. return func((double) x); \
  42. }
  43. #ifndef __DO_XSI_MATH__
  44. # undef L_j0l /* long double j0l(long double x); */
  45. # undef L_j1l /* long double j1l(long double x); */
  46. # undef L_jnl /* long double jnl(int n, long double x); */
  47. # undef L_y0l /* long double y0l(long double x); */
  48. # undef L_y1l /* long double y1l(long double x); */
  49. # undef L_ynl /* long double ynl(int n, long double x); */
  50. #endif
  51. /* Implement the following, as defined by SuSv3 */
  52. #if 0
  53. long double acoshl(long double);
  54. long double acosl(long double);
  55. long double asinhl(long double);
  56. long double asinl(long double);
  57. long double atan2l(long double, long double);
  58. long double atanhl(long double);
  59. long double atanl(long double);
  60. long double cargl(long double complex);
  61. long double cbrtl(long double);
  62. long double ceill(long double);
  63. long double copysignl(long double, long double);
  64. long double coshl(long double);
  65. long double cosl(long double);
  66. long double erfcl(long double);
  67. long double erfl(long double);
  68. long double exp2l(long double);
  69. long double expl(long double);
  70. long double expm1l(long double);
  71. long double fabsl(long double);
  72. long double fdiml(long double, long double);
  73. long double floorl(long double);
  74. long double fmal(long double, long double, long double);
  75. long double fmaxl(long double, long double);
  76. long double fminl(long double, long double);
  77. long double fmodl(long double, long double);
  78. long double frexpl(long double value, int *);
  79. long double hypotl(long double, long double);
  80. int ilogbl(long double);
  81. long double ldexpl(long double, int);
  82. long double lgammal(long double);
  83. long long llrintl(long double);
  84. long long llroundl(long double);
  85. long double log10l(long double);
  86. long double log1pl(long double);
  87. long double log2l(long double);
  88. long double logbl(long double);
  89. long double logl(long double);
  90. long lrintl(long double);
  91. long lroundl(long double);
  92. long double modfl(long double, long double *);
  93. long double nearbyintl(long double);
  94. long double nextafterl(long double, long double);
  95. long double nexttowardl(long double, long double);
  96. long double powl(long double, long double);
  97. long double remainderl(long double, long double);
  98. long double remquol(long double, long double, int *);
  99. long double rintl(long double);
  100. long double roundl(long double);
  101. long double scalblnl(long double, long);
  102. long double scalbnl(long double, int);
  103. long double sinhl(long double);
  104. long double sinl(long double);
  105. long double sqrtl(long double);
  106. long double tanhl(long double);
  107. long double tanl(long double);
  108. long double tgammal(long double);
  109. long double truncl(long double);
  110. #endif
  111. #ifdef L_acoshl
  112. WRAPPER1(acosh)
  113. #endif
  114. #ifdef L_acosl
  115. WRAPPER1(acos)
  116. #endif
  117. #ifdef L_asinhl
  118. WRAPPER1(asinh)
  119. #endif
  120. #ifdef L_asinl
  121. WRAPPER1(asin)
  122. #endif
  123. #ifdef L_atan2l
  124. WRAPPER2(atan2)
  125. #endif
  126. #ifdef L_atanhl
  127. WRAPPER1(atanh)
  128. #endif
  129. #ifdef L_atanl
  130. WRAPPER1(atan)
  131. #endif
  132. #ifdef L_cargl
  133. long double cargl (long double complex x)
  134. {
  135. return (long double) carg( (double complex)x );
  136. }
  137. #endif
  138. #ifdef L_cbrtl
  139. WRAPPER1(cbrt)
  140. #endif
  141. #ifdef L_ceill
  142. WRAPPER1(ceil)
  143. #endif
  144. #ifdef L_copysignl
  145. WRAPPER2(copysign)
  146. #endif
  147. #ifdef L_coshl
  148. WRAPPER1(cosh)
  149. #endif
  150. #ifdef L_cosl
  151. WRAPPER1(cos)
  152. libm_hidden_def(cosl)
  153. #endif
  154. #ifdef L_erfcl
  155. WRAPPER1(erfc)
  156. #endif
  157. #ifdef L_erfl
  158. WRAPPER1(erf)
  159. #endif
  160. #ifdef L_exp2l
  161. WRAPPER1(exp2)
  162. #endif
  163. #ifdef L_expl
  164. WRAPPER1(exp)
  165. libm_hidden_def(expl)
  166. #endif
  167. #ifdef L_expm1l
  168. WRAPPER1(expm1)
  169. #endif
  170. #ifdef L_fabsl
  171. WRAPPER1(fabs)
  172. #endif
  173. #ifdef L_fdiml
  174. WRAPPER2(fdim)
  175. #endif
  176. #ifdef L_floorl
  177. WRAPPER1(floor)
  178. #endif
  179. #ifdef L_fmal
  180. long double fmal (long double x, long double y, long double z)
  181. {
  182. return (long double) fma( (double)x, (double)y, (double)z );
  183. }
  184. #endif
  185. #ifdef L_fmaxl
  186. WRAPPER2(fmax)
  187. #endif
  188. #ifdef L_fminl
  189. WRAPPER2(fmin)
  190. #endif
  191. #ifdef L_fmodl
  192. WRAPPER2(fmod)
  193. #endif
  194. #ifdef L_frexpl
  195. long double frexpl (long double x, int *ex)
  196. {
  197. return (long double) frexp( (double)x, ex );
  198. }
  199. #endif
  200. #ifdef L_gammal
  201. WRAPPER1(gamma)
  202. #endif
  203. #ifdef L_hypotl
  204. WRAPPER2(hypot)
  205. libm_hidden_def(hypotl)
  206. #endif
  207. #ifdef L_ilogbl
  208. int_WRAPPER1(ilogb)
  209. #endif
  210. #ifdef L_j0l
  211. WRAPPER1(j0)
  212. #endif
  213. #ifdef L_j1l
  214. WRAPPER1(j1)
  215. #endif
  216. #ifdef L_jnl
  217. long double jnl(int n, long double x)
  218. {
  219. return (long double) jn(n, (double)x);
  220. }
  221. #endif
  222. #ifdef L_ldexpl
  223. long double ldexpl (long double x, int ex)
  224. {
  225. return (long double) ldexp( (double)x, ex );
  226. }
  227. #endif
  228. #ifdef L_lgammal
  229. WRAPPER1(lgamma)
  230. #endif
  231. #ifdef L_llrintl
  232. long_long_WRAPPER1(llrint)
  233. #endif
  234. #ifdef L_llroundl
  235. long_long_WRAPPER1(llround)
  236. #endif
  237. #ifdef L_log10l
  238. WRAPPER1(log10)
  239. #endif
  240. #ifdef L_log1pl
  241. WRAPPER1(log1p)
  242. #endif
  243. #ifdef L_log2l
  244. WRAPPER1(log2)
  245. #endif
  246. #ifdef L_logbl
  247. WRAPPER1(logb)
  248. #endif
  249. #ifdef L_logl
  250. WRAPPER1(log)
  251. #endif
  252. #ifdef L_lrintl
  253. long_WRAPPER1(lrint)
  254. #endif
  255. #ifdef L_lroundl
  256. long_WRAPPER1(lround)
  257. #endif
  258. #ifdef L_modfl
  259. long double modfl (long double x, long double *iptr)
  260. {
  261. double y, result;
  262. result = modf ( x, &y );
  263. *iptr = (long double)y;
  264. return (long double) result;
  265. }
  266. #endif
  267. #ifdef L_nearbyintl
  268. WRAPPER1(nearbyint)
  269. #endif
  270. #ifdef L_nextafterl
  271. WRAPPER2(nextafter)
  272. libm_hidden_def(nextafterl)
  273. #endif
  274. #ifdef L_nexttowardl
  275. # if 0 /* TODO */
  276. strong_alias(nextafterl, nexttowardl)
  277. # else
  278. long double nexttowardl(long double x, long double y)
  279. {
  280. return nextafterl(x, y);
  281. }
  282. #endif
  283. #endif
  284. #ifdef L_powl
  285. WRAPPER2(pow)
  286. #endif
  287. #ifdef L_remainderl
  288. WRAPPER2(remainder)
  289. #endif
  290. #ifdef L_remquol
  291. long double remquol (long double x, long double y, int *quo)
  292. {
  293. return (long double) remquo( (double)x, (double)y, quo );
  294. }
  295. #endif
  296. #ifdef L_rintl
  297. WRAPPER1(rint)
  298. #endif
  299. #ifdef L_roundl
  300. WRAPPER1(round)
  301. #endif
  302. #ifdef L_scalblnl
  303. long double scalblnl (long double x, long ex)
  304. {
  305. return (long double) scalbln( (double)x, ex );
  306. }
  307. #endif
  308. #ifdef L_scalbnl
  309. long double scalbnl (long double x, int ex)
  310. {
  311. return (long double) scalbn( (double)x, ex );
  312. }
  313. #endif
  314. /* scalb is an obsolete function */
  315. #ifdef L_sinhl
  316. WRAPPER1(sinh)
  317. #endif
  318. #ifdef L_sinl
  319. WRAPPER1(sin)
  320. libm_hidden_def(sinl)
  321. #endif
  322. #ifdef L_sqrtl
  323. WRAPPER1(sqrt)
  324. #endif
  325. #ifdef L_tanhl
  326. WRAPPER1(tanh)
  327. #endif
  328. #ifdef L_tanl
  329. WRAPPER1(tan)
  330. #endif
  331. #ifdef L_tgammal
  332. WRAPPER1(tgamma)
  333. #endif
  334. #ifdef L_truncl
  335. WRAPPER1(trunc)
  336. #endif
  337. #ifdef L_significandl
  338. WRAPPER1(significand)
  339. #endif
  340. #ifdef L_y0l
  341. WRAPPER1(y0)
  342. #endif
  343. #ifdef L_y1l
  344. WRAPPER1(y1)
  345. #endif
  346. #ifdef L_ynl
  347. long double ynl(int n, long double x)
  348. {
  349. return (long double) yn(n, (double)x);
  350. }
  351. #endif
  352. #if defined __DO_C99_MATH__ && !defined __NO_LONG_DOUBLE_MATH
  353. # ifdef L___fpclassifyl
  354. int_WRAPPER1(__fpclassify)
  355. libm_hidden_def(__fpclassifyl)
  356. # endif
  357. # ifdef L___finitel
  358. int_WRAPPER1(__finite)
  359. libm_hidden_def(__finitel)
  360. # endif
  361. # ifdef L___signbitl
  362. int_WRAPPER1(__signbit)
  363. libm_hidden_def(__signbitl)
  364. # endif
  365. # ifdef L___isnanl
  366. int_WRAPPER1(__isnan)
  367. libm_hidden_def(__isnanl)
  368. # endif
  369. # ifdef L___isinfl
  370. int_WRAPPER1(__isinf)
  371. libm_hidden_def(__isinfl)
  372. # endif
  373. #endif /* __DO_C99_MATH__ */
  374. #endif /* __NO_LONG_DOUBLE_MATH */