float_wrappers.c 8.4 KB

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