float_wrappers.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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. /* Implement the following, as defined by SuSv3 */
  37. #if 0
  38. float asinhf(float);
  39. float atanf(float);
  40. float cargf(float complex);
  41. float cbrtf(float);
  42. float ceilf(float);
  43. float copysignf(float, float);
  44. float cosf(float);
  45. float erfcf(float);
  46. float erff(float);
  47. float expm1f(float);
  48. float fabsf(float);
  49. float floorf(float);
  50. float frexpf(float value, int *);
  51. int ilogbf(float);
  52. float ldexpf(float, int);
  53. long long llroundf(float);
  54. float log1pf(float);
  55. float logbf(float);
  56. long lroundf(float);
  57. float modff(float, float *);
  58. float rintf(float);
  59. float roundf(float);
  60. float scalbnf(float, int);
  61. float sinf(float);
  62. float tanf(float);
  63. float tanhf(float);
  64. #endif
  65. /* The following functions implemented as wrappers
  66. * in separate files (w_funcf.c)
  67. */
  68. #if 0
  69. float acosf(float);
  70. float acoshf(float);
  71. float asinf(float);
  72. float atan2f(float, float);
  73. float atanhf(float);
  74. float coshf(float);
  75. float exp2f(float);
  76. float expf(float);
  77. float fmodf(float, float);
  78. float hypotf(float, float);
  79. float lgammaf(float);
  80. float log10f(float);
  81. float log2f(float);
  82. float logf(float);
  83. float powf(float, float);
  84. float remainderf(float, float);
  85. float sinhf(float);
  86. float sqrtf(float);
  87. float j0f(float x);
  88. float j1f(float x);
  89. float jnf(int n, float x);
  90. float y0f(float x);
  91. float y1f(float x);
  92. float ynf(int n, float x);
  93. float tgammaf(float x);
  94. float scalbf(float x, float fn);
  95. float gammaf(float x);
  96. float scalbl(float x, float fn);
  97. #endif
  98. #ifdef L_asinhf
  99. WRAPPER1(asinh)
  100. #endif
  101. #ifdef L_atanf
  102. WRAPPER1(atan)
  103. #endif
  104. #ifdef L_cargf
  105. float cargf (float complex x)
  106. {
  107. return (float) carg( (double complex)x );
  108. }
  109. #endif
  110. #ifdef L_cbrtf
  111. WRAPPER1(cbrt)
  112. #endif
  113. #ifdef L_ceilf
  114. WRAPPER1(ceil)
  115. #endif
  116. #ifdef L_copysignf
  117. float copysignf (float x, float y)
  118. {
  119. return (float) copysign( (double)x, (double)y );
  120. }
  121. #endif
  122. #ifdef L_cosf
  123. WRAPPER1(cos)
  124. libm_hidden_def(cosf)
  125. #endif
  126. #ifdef L_erfcf
  127. WRAPPER1(erfc)
  128. #endif
  129. #ifdef L_erff
  130. WRAPPER1(erf)
  131. #endif
  132. #ifdef L_expm1f
  133. WRAPPER1(expm1)
  134. #endif
  135. #ifdef L_fabsf
  136. WRAPPER1(fabs)
  137. #endif
  138. #ifdef L_fdimf
  139. float fdimf (float x, float y)
  140. {
  141. return (float) fdim( (double)x, (double)y );
  142. }
  143. #endif
  144. #ifdef L_floorf
  145. WRAPPER1(floor)
  146. #endif
  147. #ifdef L_fmaf
  148. float fmaf (float x, float y, float z)
  149. {
  150. return (float) fma( (double)x, (double)y, (double)z );
  151. }
  152. #endif
  153. #ifdef L_fmaxf
  154. float fmaxf (float x, float y)
  155. {
  156. return (float) fmax( (double)x, (double)y );
  157. }
  158. #endif
  159. #ifdef L_fminf
  160. float fminf (float x, float y)
  161. {
  162. return (float) fmin( (double)x, (double)y );
  163. }
  164. #endif
  165. #ifdef L_frexpf
  166. float frexpf (float x, int *_exp)
  167. {
  168. return (float) frexp( (double)x, _exp );
  169. }
  170. #endif
  171. #ifdef L_ilogbf
  172. int_WRAPPER1(ilogb)
  173. #endif
  174. #ifdef L_ldexpf
  175. float ldexpf (float x, int _exp)
  176. {
  177. return (float) ldexp( (double)x, _exp );
  178. }
  179. #endif
  180. #ifdef L_llrintf
  181. long_long_WRAPPER1(llrint)
  182. #endif
  183. #ifdef L_llroundf
  184. long_long_WRAPPER1(llround)
  185. #endif
  186. #ifdef L_log1pf
  187. WRAPPER1(log1p)
  188. #endif
  189. #ifdef L_logbf
  190. WRAPPER1(logb)
  191. #endif
  192. #ifdef L_lrintf
  193. long_WRAPPER1(lrint)
  194. #endif
  195. #ifdef L_lroundf
  196. long_WRAPPER1(lround)
  197. #endif
  198. #ifdef L_modff
  199. float modff (float x, float *iptr)
  200. {
  201. double y, result;
  202. result = modf( x, &y );
  203. *iptr = (float)y;
  204. return (float) result;
  205. }
  206. #endif
  207. #ifdef L_nearbyintf
  208. WRAPPER1(nearbyint)
  209. #endif
  210. #ifdef L_nexttowardf
  211. float nexttowardf (float x, long double y)
  212. {
  213. return (float) nexttoward( (double)x, (long double)y );
  214. }
  215. #endif
  216. #ifdef L_remquof
  217. float remquof (float x, float y, int *quo)
  218. {
  219. return (float) remquo( (double)x, (double)y, quo );
  220. }
  221. #endif
  222. #ifdef L_rintf
  223. WRAPPER1(rint)
  224. #endif
  225. #ifdef L_roundf
  226. WRAPPER1(round)
  227. #endif
  228. #ifdef L_scalblnf
  229. float scalblnf (float x, long _exp)
  230. {
  231. return (float) scalbln( (double)x, _exp );
  232. }
  233. #endif
  234. #ifdef L_scalbnf
  235. float scalbnf (float x, int _exp)
  236. {
  237. return (float) scalbn( (double)x, _exp );
  238. }
  239. #endif
  240. #ifdef L_sinf
  241. WRAPPER1(sin)
  242. libm_hidden_def(sinf)
  243. #endif
  244. #ifdef L_tanf
  245. WRAPPER1(tan)
  246. #endif
  247. #ifdef L_tanhf
  248. WRAPPER1(tanh)
  249. #endif
  250. #ifdef L_truncf
  251. WRAPPER1(trunc)
  252. #endif
  253. #ifdef L_significandf
  254. WRAPPER1(significand)
  255. #endif