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