ldouble_wrappers.c 7.7 KB

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