float_wrappers.c 9.1 KB

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