float_wrappers.c 8.0 KB

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