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