ldouble_wrappers.c 6.8 KB

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