float_wrappers.c 6.6 KB

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