float_wrappers.c 8.1 KB

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