float_wrappers.c 6.4 KB

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