float_wrappers.c 8.2 KB

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