float_wrappers.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  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 "math.h"
  13. /* For the time being, do _NOT_ implement these functions
  14. * that are defined by SuSv3 */
  15. #undef L_exp2f /*float exp2f(float);*/
  16. #undef L_fdimf /*float fdimf(float, float);*/
  17. #undef L_fmaf /*float fmaf(float, float, float);*/
  18. #undef L_fmaxf /*float fmaxf(float, float);*/
  19. #undef L_fminf /*float fminf(float, float);*/
  20. #undef L_llrintf /*long long llrintf(float);*/
  21. #undef L_log2f /*float log2f(float);*/
  22. #undef L_lrintf /*long lrintf(float);*/
  23. #undef L_nearbyintf /*float nearbyintf(float);*/
  24. #undef L_nexttowardf /*float nexttowardf(float, long double);*/
  25. #undef L_remquof /*float remquof(float, float, int *);*/
  26. #undef L_scalblnf /*float scalblnf(float, long);*/
  27. #undef L_tgammaf /*float tgammaf(float);*/
  28. #undef L_truncf /*float truncf(float);*/
  29. /* Implement the following, as defined by SuSv3 */
  30. #if 0
  31. float acosf(float);
  32. float acoshf(float);
  33. float asinf(float);
  34. float asinhf(float);
  35. float atan2f(float, float);
  36. float atanf(float);
  37. float atanhf(float);
  38. float cbrtf(float);
  39. float ceilf(float);
  40. float copysignf(float, float);
  41. float cosf(float);
  42. float coshf(float);
  43. float erfcf(float);
  44. float erff(float);
  45. float expf(float);
  46. float expm1f(float);
  47. float fabsf(float);
  48. float floorf(float);
  49. float fmodf(float, float);
  50. float frexpf(float value, int *);
  51. float hypotf(float, float);
  52. int ilogbf(float);
  53. float ldexpf(float, int);
  54. float lgammaf(float);
  55. long long llroundf(float);
  56. float log10f(float);
  57. float log1pf(float);
  58. float logbf(float);
  59. float logf(float);
  60. long lroundf(float);
  61. float modff(float, float *);
  62. float nextafterf(float, float);
  63. float powf(float, float);
  64. float remainderf(float, float);
  65. float rintf(float);
  66. float roundf(float);
  67. float scalbnf(float, int);
  68. float sinf(float);
  69. float sinhf(float);
  70. float sqrtf(float);
  71. float tanf(float);
  72. float tanhf(float);
  73. #endif
  74. #ifdef L_acosf
  75. float acosf (float x)
  76. {
  77. return (float) acos( (double)x );
  78. }
  79. #endif
  80. #ifdef L_acoshf
  81. float acoshf (float x)
  82. {
  83. return (float) acosh( (double)x );
  84. }
  85. #endif
  86. #ifdef L_asinf
  87. float asinf (float x)
  88. {
  89. return (float) asin( (double)x );
  90. }
  91. #endif
  92. #ifdef L_asinhf
  93. float asinhf (float x)
  94. {
  95. return (float) asinh( (double)x );
  96. }
  97. #endif
  98. #ifdef L_atan2f
  99. float atan2f (float x, float y)
  100. {
  101. return (float) atan2( (double)x, (double)y );
  102. }
  103. #endif
  104. #ifdef L_atanf
  105. float atanf (float x)
  106. {
  107. return (float) atan( (double)x );
  108. }
  109. #endif
  110. #ifdef L_atanhf
  111. float atanhf (float x)
  112. {
  113. return (float) atanh( (double)x );
  114. }
  115. #endif
  116. #ifdef L_cbrtf
  117. float cbrtf (float x)
  118. {
  119. return (float) cbrt( (double)x );
  120. }
  121. #endif
  122. #ifdef L_ceilf
  123. float ceilf (float x)
  124. {
  125. return (float) ceil( (double)x );
  126. }
  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. float cosf (float x)
  136. {
  137. return (float) cos( (double)x );
  138. }
  139. #endif
  140. #ifdef L_coshf
  141. float coshf (float x)
  142. {
  143. return (float) cosh( (double)x );
  144. }
  145. #endif
  146. #ifdef L_erfcf
  147. float erfcf (float x)
  148. {
  149. return (float) erfc( (double)x );
  150. }
  151. #endif
  152. #ifdef L_erff
  153. float erff (float x)
  154. {
  155. return (float) erf( (double)x );
  156. }
  157. #endif
  158. #ifdef L_exp2f
  159. float exp2f (float x)
  160. {
  161. return (float) exp2( (double)x );
  162. }
  163. #endif
  164. #ifdef L_expf
  165. float expf (float x)
  166. {
  167. return (float) exp( (double)x );
  168. }
  169. #endif
  170. #ifdef L_expm1f
  171. float expm1f (float x)
  172. {
  173. return (float) expm1( (double)x );
  174. }
  175. #endif
  176. #ifdef L_fabsf
  177. float fabsf (float x)
  178. {
  179. return (float) fabs( (double)x );
  180. }
  181. #endif
  182. #ifdef L_fdimf
  183. float fdimf (float x, float y)
  184. {
  185. return (float) fdim( (double)x, (double)y );
  186. }
  187. #endif
  188. #ifdef L_floorf
  189. float floorf (float x)
  190. {
  191. return (float) floor( (double)x );
  192. }
  193. #endif
  194. #ifdef L_fmaf
  195. float fmaf (float x, float y, float z)
  196. {
  197. return (float) fma( (double)x, (double)y, (double)z );
  198. }
  199. #endif
  200. #ifdef L_fmaxf
  201. float fmaxf (float x, float y)
  202. {
  203. return (float) fmax( (double)x, (double)y );
  204. }
  205. #endif
  206. #ifdef L_fminf
  207. float fminf (float x, float y)
  208. {
  209. return (float) fmin( (double)x, (double)y );
  210. }
  211. #endif
  212. #ifdef L_fmodf
  213. float fmodf (float x, float y)
  214. {
  215. return (float) fmod( (double)x, (double)y );
  216. }
  217. #endif
  218. #ifdef L_frexpf
  219. float frexpf (float x, int *exp)
  220. {
  221. return (float) frexp( (double)x, exp );
  222. }
  223. #endif
  224. #ifdef L_hypotf
  225. float hypotf (float x, float y)
  226. {
  227. return (float) hypot( (double)x, (double)y );
  228. }
  229. #endif
  230. #ifdef L_ilogbf
  231. int ilogbf (float x)
  232. {
  233. return (float) ilogb( (double)x );
  234. }
  235. #endif
  236. #ifdef L_ldexpf
  237. float ldexpf (float x, int exp)
  238. {
  239. return (float) ldexp( (double)x, exp );
  240. }
  241. #endif
  242. #ifdef L_lgammaf
  243. float lgammaf (float x)
  244. {
  245. return (float) lgamma( (double)x );
  246. }
  247. #endif
  248. #ifdef L_llrintf
  249. long long llrintf (float x)
  250. {
  251. return (float) llrint( (double)x );
  252. }
  253. #endif
  254. #ifdef L_llroundf
  255. long long llroundf (float x)
  256. {
  257. return (float) llround( (double)x );
  258. }
  259. #endif
  260. #ifdef L_log10f
  261. float log10f (float x)
  262. {
  263. return (float) log10( (double)x );
  264. }
  265. #endif
  266. #ifdef L_log1pf
  267. float log1pf (float x)
  268. {
  269. return (float) log1p( (double)x );
  270. }
  271. #endif
  272. #ifdef L_log2f
  273. float log2f (float x)
  274. {
  275. return (float) log2( (double)x );
  276. }
  277. #endif
  278. #ifdef L_logbf
  279. float logbf (float x)
  280. {
  281. return (float) logb( (double)x );
  282. }
  283. #endif
  284. #ifdef L_logf
  285. float logf (float x)
  286. {
  287. return (float) log( (double)x );
  288. }
  289. #endif
  290. #ifdef L_lrintf
  291. long lrintf (float x)
  292. {
  293. return (float) lrint( (double)x );
  294. }
  295. #endif
  296. #ifdef L_lroundf
  297. long lroundf (float x)
  298. {
  299. return (float) lround( (double)x );
  300. }
  301. #endif
  302. #ifdef L_modff
  303. float modff (float x, float *iptr)
  304. {
  305. double y, result;
  306. result = modf ( x, &y );
  307. *iptr = (float)y;
  308. return (float) result;
  309. }
  310. #endif
  311. #ifdef L_nearbyintf
  312. float nearbyintf (float x)
  313. {
  314. return (float) nearbyint( (double)x );
  315. }
  316. #endif
  317. #ifdef L_nextafterf
  318. float nextafterf (float x, float y)
  319. {
  320. return (float) nextafter( (double)x, (double)y );
  321. }
  322. #endif
  323. #ifdef L_nexttowardf
  324. float nexttowardf (float x, long double y)
  325. {
  326. return (float) nexttoward( (double)x, (double)y );
  327. }
  328. #endif
  329. #ifdef L_powf
  330. float powf (float x, float y)
  331. {
  332. return (float) pow( (double)x, (double)y );
  333. }
  334. #endif
  335. #ifdef L_remainderf
  336. float remainderf (float x, float y)
  337. {
  338. return (float) remainder( (double)x, (double)y );
  339. }
  340. #endif
  341. #ifdef L_remquof
  342. float remquof (float x, float y, int *quo)
  343. {
  344. return (float) remquo( (double)x, (double)y, quo );
  345. }
  346. #endif
  347. #ifdef L_rintf
  348. float rintf (float x)
  349. {
  350. return (float) rint( (double)x );
  351. }
  352. #endif
  353. #ifdef L_roundf
  354. float roundf (float x)
  355. {
  356. return (float) round( (double)x );
  357. }
  358. #endif
  359. #ifdef L_scalblnf
  360. float scalblnf (float x, long exp)
  361. {
  362. return (float) scalbln( (double)x, exp );
  363. }
  364. #endif
  365. #ifdef L_scalbnf
  366. float scalbnf (float x, int exp)
  367. {
  368. return (float) scalbn( (double)x, exp );
  369. }
  370. #endif
  371. #ifdef L_sinf
  372. float sinf (float x)
  373. {
  374. return (float) sin( (double)x );
  375. }
  376. #endif
  377. #ifdef L_sinhf
  378. float sinhf (float x)
  379. {
  380. return (float) sinh( (double)x );
  381. }
  382. #endif
  383. #ifdef L_sqrtf
  384. float sqrtf (float x)
  385. {
  386. return (float) sqrt( (double)x );
  387. }
  388. #endif
  389. #ifdef L_tanf
  390. float tanf (float x)
  391. {
  392. return (float) tan( (double)x );
  393. }
  394. #endif
  395. #ifdef L_tanhf
  396. float tanhf (float x)
  397. {
  398. return (float) tanh( (double)x );
  399. }
  400. #endif
  401. #ifdef L_tgammaf
  402. float tgammaf (float x)
  403. {
  404. return (float) tgamma( (double)x );
  405. }
  406. #endif
  407. #ifdef L_truncf
  408. float truncf (float x)
  409. {
  410. return (float) trunc( (double)x );
  411. }
  412. #endif