float_wrappers.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Wrapper functions implementing all the float math functions
  4. * defined by SuSv3 by actually calling the double version of
  5. * each function and then casting the result back to a float
  6. * to return to the user.
  7. *
  8. * Copyright (C) 2005 by Erik Andersen <andersen@uclibc.org>
  9. *
  10. * GNU Lesser General Public License version 2.1 or later.
  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. float func##f (float x) \
  19. { \
  20. return (float) func((double)x); \
  21. }
  22. #define int_WRAPPER1(func) \
  23. int func##f (float x) \
  24. { \
  25. return func((double)x); \
  26. }
  27. #define long_WRAPPER1(func) \
  28. long func##f (float x) \
  29. { \
  30. return func((double)x); \
  31. }
  32. #define long_long_WRAPPER1(func) \
  33. long long func##f (float x) \
  34. { \
  35. return func((double)x); \
  36. }
  37. #ifndef __DO_XSI_MATH__
  38. # undef L_j0f /* float j0f(float x); */
  39. # undef L_j1f /* float j1f(float x); */
  40. # undef L_jnf /* float jnf(int n, float x); */
  41. # undef L_y0f /* float y0f(float x); */
  42. # undef L_y1f /* float y1f(float x); */
  43. # undef L_ynf /* float ynf(int n, float x); */
  44. #endif
  45. /* Implement the following, as defined by SuSv3 */
  46. #if 0
  47. float acosf(float);
  48. float acoshf(float);
  49. float asinf(float);
  50. float asinhf(float);
  51. float atan2f(float, float);
  52. float atanf(float);
  53. float atanhf(float);
  54. float cargf(float complex);
  55. float cbrtf(float);
  56. float ceilf(float);
  57. float copysignf(float, float);
  58. float cosf(float);
  59. float coshf(float);
  60. float erfcf(float);
  61. float erff(float);
  62. float exp2f(float);
  63. float expf(float);
  64. float expm1f(float);
  65. float fabsf(float);
  66. float floorf(float);
  67. float fmodf(float, float);
  68. float frexpf(float value, int *);
  69. float hypotf(float, float);
  70. int ilogbf(float);
  71. float ldexpf(float, int);
  72. float lgammaf(float);
  73. long long llroundf(float);
  74. float log10f(float);
  75. float log1pf(float);
  76. float log2f(float);
  77. float logbf(float);
  78. float logf(float);
  79. long lroundf(float);
  80. float modff(float, float *);
  81. float powf(float, float);
  82. float remainderf(float, float);
  83. float rintf(float);
  84. float roundf(float);
  85. float scalbnf(float, int);
  86. float sinf(float);
  87. float sinhf(float);
  88. float sqrtf(float);
  89. float tanf(float);
  90. float tanhf(float);
  91. #endif
  92. #ifdef L_acosf
  93. WRAPPER1(acos)
  94. #endif
  95. #ifdef L_acoshf
  96. WRAPPER1(acosh)
  97. #endif
  98. #ifdef L_asinf
  99. WRAPPER1(asin)
  100. #endif
  101. #ifdef L_asinhf
  102. WRAPPER1(asinh)
  103. #endif
  104. #ifdef L_atan2f
  105. float atan2f (float x, float y)
  106. {
  107. return (float) atan2( (double)x, (double)y );
  108. }
  109. #endif
  110. #ifdef L_atanf
  111. WRAPPER1(atan)
  112. #endif
  113. #ifdef L_atanhf
  114. WRAPPER1(atanh)
  115. #endif
  116. #ifdef L_cargf
  117. float cargf (float complex x)
  118. {
  119. return (float) carg( (double complex)x );
  120. }
  121. #endif
  122. #ifdef L_cbrtf
  123. WRAPPER1(cbrt)
  124. #endif
  125. #ifdef L_ceilf
  126. WRAPPER1(ceil)
  127. #endif
  128. #ifdef L_copysignf
  129. float copysignf (float x, float y)
  130. {
  131. return (float) copysign( (double)x, (double)y );
  132. }
  133. #endif
  134. #ifdef L_cosf
  135. WRAPPER1(cos)
  136. libm_hidden_def(cosf)
  137. #endif
  138. #ifdef L_coshf
  139. WRAPPER1(cosh)
  140. #endif
  141. #ifdef L_erfcf
  142. WRAPPER1(erfc)
  143. #endif
  144. #ifdef L_erff
  145. WRAPPER1(erf)
  146. #endif
  147. #ifdef L_exp2f
  148. WRAPPER1(exp2)
  149. #endif
  150. #ifdef L_expf
  151. WRAPPER1(exp)
  152. #endif
  153. #ifdef L_expm1f
  154. WRAPPER1(expm1)
  155. #endif
  156. #ifdef L_fabsf
  157. WRAPPER1(fabs)
  158. #endif
  159. #ifdef L_fdimf
  160. float fdimf (float x, float y)
  161. {
  162. return (float) fdim( (double)x, (double)y );
  163. }
  164. #endif
  165. #ifdef L_floorf
  166. WRAPPER1(floor)
  167. #endif
  168. #ifdef L_fmaf
  169. float fmaf (float x, float y, float z)
  170. {
  171. return (float) fma( (double)x, (double)y, (double)z );
  172. }
  173. #endif
  174. #ifdef L_fmaxf
  175. float fmaxf (float x, float y)
  176. {
  177. return (float) fmax( (double)x, (double)y );
  178. }
  179. #endif
  180. #ifdef L_fminf
  181. float fminf (float x, float y)
  182. {
  183. return (float) fmin( (double)x, (double)y );
  184. }
  185. #endif
  186. #ifdef L_fmodf
  187. float fmodf (float x, float y)
  188. {
  189. return (float) fmod( (double)x, (double)y );
  190. }
  191. #endif
  192. #ifdef L_frexpf
  193. float frexpf (float x, int *_exp)
  194. {
  195. return (float) frexp( (double)x, _exp );
  196. }
  197. #endif
  198. #ifdef L_hypotf
  199. float hypotf (float x, float y)
  200. {
  201. return (float) hypot( (double)x, (double)y );
  202. }
  203. #endif
  204. #ifdef L_ilogbf
  205. int_WRAPPER1(ilogb)
  206. #endif
  207. #ifdef L_j0f
  208. WRAPPER1(j0)
  209. #endif
  210. #ifdef L_j1f
  211. WRAPPER1(j1)
  212. #endif
  213. #ifdef L_jnf
  214. float jnf(int n, float x)
  215. {
  216. return (float) jn(n, (double)x);
  217. }
  218. #endif
  219. #ifdef L_ldexpf
  220. float ldexpf (float x, int _exp)
  221. {
  222. return (float) ldexp( (double)x, _exp );
  223. }
  224. #endif
  225. #ifdef L_lgammaf
  226. WRAPPER1(lgamma)
  227. #endif
  228. #ifdef L_llrintf
  229. long_long_WRAPPER1(llrint)
  230. #endif
  231. #ifdef L_llroundf
  232. long_long_WRAPPER1(llround)
  233. #endif
  234. #ifdef L_log10f
  235. WRAPPER1(log10)
  236. #endif
  237. #ifdef L_log1pf
  238. WRAPPER1(log1p)
  239. #endif
  240. #ifdef L_log2f
  241. WRAPPER1(log2)
  242. #endif
  243. #ifdef L_logbf
  244. WRAPPER1(logb)
  245. #endif
  246. #ifdef L_logf
  247. WRAPPER1(log)
  248. #endif
  249. #ifdef L_lrintf
  250. long_WRAPPER1(lrint)
  251. #endif
  252. #ifdef L_lroundf
  253. long_WRAPPER1(lround)
  254. #endif
  255. #ifdef L_modff
  256. float modff (float x, float *iptr)
  257. {
  258. double y, result;
  259. result = modf( x, &y );
  260. *iptr = (float)y;
  261. return (float) result;
  262. }
  263. #endif
  264. #ifdef L_nearbyintf
  265. WRAPPER1(nearbyint)
  266. #endif
  267. #ifdef L_nexttowardf
  268. float nexttowardf (float x, long double y)
  269. {
  270. return (float) nexttoward( (double)x, (long double)y );
  271. }
  272. #endif
  273. #ifdef L_powf
  274. float powf (float x, float y)
  275. {
  276. return (float) pow( (double)x, (double)y );
  277. }
  278. #endif
  279. #ifdef L_remainderf
  280. float remainderf (float x, float y)
  281. {
  282. return (float) remainder( (double)x, (double)y );
  283. }
  284. #endif
  285. #ifdef L_remquof
  286. float remquof (float x, float y, int *quo)
  287. {
  288. return (float) remquo( (double)x, (double)y, quo );
  289. }
  290. #endif
  291. #ifdef L_rintf
  292. WRAPPER1(rint)
  293. #endif
  294. #ifdef L_roundf
  295. WRAPPER1(round)
  296. #endif
  297. #ifdef L_scalblnf
  298. float scalblnf (float x, long _exp)
  299. {
  300. return (float) scalbln( (double)x, _exp );
  301. }
  302. #endif
  303. #ifdef L_scalbnf
  304. float scalbnf (float x, int _exp)
  305. {
  306. return (float) scalbn( (double)x, _exp );
  307. }
  308. #endif
  309. #ifdef L_sinf
  310. WRAPPER1(sin)
  311. libm_hidden_def(sinf)
  312. #endif
  313. #ifdef L_sinhf
  314. WRAPPER1(sinh)
  315. #endif
  316. #ifdef L_sqrtf
  317. WRAPPER1(sqrt)
  318. #endif
  319. #ifdef L_tanf
  320. WRAPPER1(tan)
  321. #endif
  322. #ifdef L_tanhf
  323. WRAPPER1(tanh)
  324. #endif
  325. #ifdef L_tgammaf
  326. WRAPPER1(tgamma)
  327. #endif
  328. #ifdef L_truncf
  329. WRAPPER1(trunc)
  330. #endif
  331. #if defined L_scalbf && defined __UCLIBC_SUSV3_LEGACY__
  332. float scalbf (float x, float y)
  333. {
  334. return (float) scalb( (double)x, (double)y );
  335. }
  336. #endif
  337. #ifdef L_gammaf
  338. WRAPPER1(gamma)
  339. #endif
  340. #ifdef L_significandf
  341. WRAPPER1(significand)
  342. #endif
  343. #ifdef L_y0f
  344. WRAPPER1(y0)
  345. #endif
  346. #ifdef L_y1f
  347. WRAPPER1(y1)
  348. #endif
  349. #ifdef L_ynf
  350. float ynf(int n, float x)
  351. {
  352. return (float) yn(n, (double)x);
  353. }
  354. #endif