float_wrappers.c 9.1 KB

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