ldouble_wrappers.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. /*
  2. * Wrapper functions implementing all the long double math functions
  3. * defined by SuSv3 by actually calling the double version of
  4. * each function and then casting the result back to a long double
  5. * to return to the user.
  6. *
  7. * Copyright (C) 2005 by Erik Andersen <andersen@uclibc.org>
  8. *
  9. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  10. */
  11. #include <features.h>
  12. /* Prevent math.h from defining colliding inlines */
  13. #undef __USE_EXTERN_INLINES
  14. #include "math.h"
  15. #include <complex.h>
  16. #if !defined __NO_LONG_DOUBLE_MATH
  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 asinhl(long double);
  45. long double atanl(long double);
  46. long double cargl(long double complex);
  47. long double cbrtl(long double);
  48. long double ceill(long double);
  49. long double copysignl(long double, long double);
  50. long double cosl(long double);
  51. long double erfcl(long double);
  52. long double erfl(long double);
  53. long double expm1l(long double);
  54. long double fabsl(long double);
  55. long double fdiml(long double, long double);
  56. long double floorl(long double);
  57. long double fmal(long double, long double, long double);
  58. long double fmaxl(long double, long double);
  59. long double fminl(long double, long double);
  60. long double frexpl(long double value, int *);
  61. int ilogbl(long double);
  62. long double ldexpl(long double, int);
  63. long long llrintl(long double);
  64. long long llroundl(long double);
  65. long double log1pl(long double);
  66. long double logbl(long double);
  67. long lrintl(long double);
  68. long lroundl(long double);
  69. long double modfl(long double, long double *);
  70. long double nearbyintl(long double);
  71. long double nextafterl(long double, long double);
  72. long double nexttowardl(long double, long double);
  73. long double remquol(long double, long double, int *);
  74. long double rintl(long double);
  75. long double roundl(long double);
  76. long double scalblnl(long double, long);
  77. long double scalbnl(long double, int);
  78. long double sinl(long double);
  79. long double tanhl(long double);
  80. long double tanl(long double);
  81. long double truncl(long double);
  82. #endif
  83. /* The following functions implemented as wrappers
  84. * in separate files (w_funcl.c)
  85. */
  86. #if 0
  87. long double acosl(long double);
  88. long double acoshl(long double);
  89. long double asinl(long double);
  90. long double atan2l(long double, long double);
  91. long double atanhl(long double);
  92. long double coshl(long double);
  93. long double exp2l(long double);
  94. long double expl(long double);
  95. long double fmodl(long double, long double);
  96. long double hypotl(long double, long double);
  97. long double lgammal(long double);
  98. long double log10l(long double);
  99. long double log2l(long double);
  100. long double logl(long double);
  101. long double powl(long double, long double);
  102. long double remainderl(long double, long double);
  103. long double sinhl(long double);
  104. long double sqrtl(long double);
  105. long double j0l(long double x);
  106. long double j1l(long double x);
  107. long double jnl(int n, long double x);
  108. long double y0l(long double x);
  109. long double y1l(long double x);
  110. long double ynl(int n, long double x);
  111. long double tgammal(long double x);
  112. long double scalbl(long double x, long double fn);
  113. long double gammal(long double x);
  114. long double scalbl(long double x, long double fn);
  115. #endif
  116. #ifdef L_asinhl
  117. WRAPPER1(asinh)
  118. #endif
  119. #ifdef L_atanl
  120. WRAPPER1(atan)
  121. #endif
  122. #ifdef L_cargl
  123. long double cargl (long double complex x)
  124. {
  125. return (long double) carg( (double complex)x );
  126. }
  127. #endif
  128. #ifdef L_cbrtl
  129. WRAPPER1(cbrt)
  130. #endif
  131. #ifdef L_ceill
  132. WRAPPER1(ceil)
  133. #endif
  134. #ifdef L_copysignl
  135. WRAPPER2(copysign)
  136. #endif
  137. #ifdef L_cosl
  138. WRAPPER1(cos)
  139. libm_hidden_def(cosl)
  140. #endif
  141. #ifdef L_erfcl
  142. WRAPPER1(erfc)
  143. #endif
  144. #ifdef L_erfl
  145. WRAPPER1(erf)
  146. #endif
  147. #ifdef L_expm1l
  148. WRAPPER1(expm1)
  149. #endif
  150. #ifdef L_fabsl
  151. WRAPPER1(fabs)
  152. #endif
  153. #ifdef L_fdiml
  154. WRAPPER2(fdim)
  155. #endif
  156. #ifdef L_floorl
  157. WRAPPER1(floor)
  158. #endif
  159. #ifdef L_fmal
  160. long double fmal (long double x, long double y, long double z)
  161. {
  162. return (long double) fma( (double)x, (double)y, (double)z );
  163. }
  164. #endif
  165. #ifdef L_fmaxl
  166. WRAPPER2(fmax)
  167. #endif
  168. #ifdef L_fminl
  169. WRAPPER2(fmin)
  170. #endif
  171. #ifdef L_frexpl
  172. long double frexpl (long double x, int *ex)
  173. {
  174. return (long double) frexp( (double)x, ex );
  175. }
  176. #endif
  177. #ifdef L_ilogbl
  178. int_WRAPPER1(ilogb)
  179. #endif
  180. #ifdef L_ldexpl
  181. long double ldexpl (long double x, int ex)
  182. {
  183. return (long double) ldexp( (double)x, ex );
  184. }
  185. #endif
  186. #ifdef L_llrintl
  187. long_long_WRAPPER1(llrint)
  188. #endif
  189. #ifdef L_llroundl
  190. long_long_WRAPPER1(llround)
  191. #endif
  192. #ifdef L_log1pl
  193. WRAPPER1(log1p)
  194. #endif
  195. #ifdef L_logbl
  196. WRAPPER1(logb)
  197. #endif
  198. #ifdef L_lrintl
  199. long_WRAPPER1(lrint)
  200. #endif
  201. #ifdef L_lroundl
  202. long_WRAPPER1(lround)
  203. #endif
  204. #ifdef L_modfl
  205. long double modfl (long double x, long double *iptr)
  206. {
  207. double y, result;
  208. result = modf ( x, &y );
  209. *iptr = (long double)y;
  210. return (long double) result;
  211. }
  212. #endif
  213. #ifdef L_nearbyintl
  214. WRAPPER1(nearbyint)
  215. #endif
  216. #ifdef L_nextafterl
  217. WRAPPER2(nextafter)
  218. libm_hidden_def(nextafterl)
  219. #endif
  220. #ifdef L_nexttowardl
  221. # if 0 /* TODO */
  222. strong_alias(nextafterl, nexttowardl)
  223. # else
  224. long double nexttowardl(long double x, long double y)
  225. {
  226. return nextafterl(x, y);
  227. }
  228. #endif
  229. #endif
  230. #ifdef L_remquol
  231. long double remquol (long double x, long double y, int *quo)
  232. {
  233. return (long double) remquo( (double)x, (double)y, quo );
  234. }
  235. #endif
  236. #ifdef L_rintl
  237. WRAPPER1(rint)
  238. #endif
  239. #ifdef L_roundl
  240. WRAPPER1(round)
  241. #endif
  242. #ifdef L_scalblnl
  243. long double scalblnl (long double x, long ex)
  244. {
  245. return (long double) scalbln( (double)x, ex );
  246. }
  247. #endif
  248. #ifdef L_scalbnl
  249. long double scalbnl (long double x, int ex)
  250. {
  251. return (long double) scalbn( (double)x, ex );
  252. }
  253. #endif
  254. #ifdef L_sinl
  255. WRAPPER1(sin)
  256. libm_hidden_def(sinl)
  257. #endif
  258. #ifdef L_tanhl
  259. WRAPPER1(tanh)
  260. #endif
  261. #ifdef L_tanl
  262. WRAPPER1(tan)
  263. #endif
  264. #ifdef L_truncl
  265. WRAPPER1(trunc)
  266. #endif
  267. #ifdef L_significandl
  268. WRAPPER1(significand)
  269. #endif
  270. #if defined __DO_C99_MATH__ && !defined __NO_LONG_DOUBLE_MATH
  271. # ifdef L___fpclassifyl
  272. int_WRAPPER1(__fpclassify)
  273. libm_hidden_def(__fpclassifyl)
  274. # endif
  275. # ifdef L___finitel
  276. int_WRAPPER1(__finite)
  277. libm_hidden_def(__finitel)
  278. # endif
  279. # ifdef L___signbitl
  280. int_WRAPPER1(__signbit)
  281. libm_hidden_def(__signbitl)
  282. # endif
  283. # ifdef L___isnanl
  284. int_WRAPPER1(__isnan)
  285. libm_hidden_def(__isnanl)
  286. # endif
  287. # ifdef L___isinfl
  288. int_WRAPPER1(__isinf)
  289. libm_hidden_def(__isinfl)
  290. # endif
  291. #endif /* __DO_C99_MATH__ */
  292. #endif /* __NO_LONG_DOUBLE_MATH */