float_wrappers.c 7.7 KB

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