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 long double math functions |
| 4 | * defined by SuSv3 by actually calling the double version of |
| 5 | * each function and then casting the result back to a long double |
| 6 | * to return to the user. |
| 7 | * |
| 8 | * Copyright (C) 2005 by Erik Andersen <andersen@uclibc.org> |
| 9 | * |
| 10 | * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. |
| 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 | #define WRAPPER1(func) \ |
| 20 | long double func##l(long double x) \ |
| 21 | { \ |
| 22 | return (long double) func((double) x); \ |
| 23 | } |
| 24 | #define WRAPPER2(func) \ |
| 25 | long double func##l(long double x, long double y) \ |
| 26 | { \ |
| 27 | return (long double) func((double) x, (double) y); \ |
| 28 | } |
| 29 | #define int_WRAPPER1(func) \ |
| 30 | int func##l(long double x) \ |
| 31 | { \ |
| 32 | return func((double) x); \ |
| 33 | } |
| 34 | #define long_WRAPPER1(func) \ |
| 35 | long func##l(long double x) \ |
| 36 | { \ |
| 37 | return func((double) x); \ |
| 38 | } |
| 39 | #define long_long_WRAPPER1(func) \ |
| 40 | long long func##l(long double x) \ |
| 41 | { \ |
| 42 | return func((double) x); \ |
| 43 | } |
| 44 | |
| 45 | /* Implement the following, as defined by SuSv3 */ |
| 46 | #if 0 |
| 47 | long double acoshl(long double); |
| 48 | long double acosl(long double); |
| 49 | long double asinhl(long double); |
| 50 | long double asinl(long double); |
| 51 | long double atan2l(long double, long double); |
| 52 | long double atanhl(long double); |
| 53 | long double atanl(long double); |
| 54 | long double cargl(long double complex); |
| 55 | long double cbrtl(long double); |
| 56 | long double ceill(long double); |
| 57 | long double copysignl(long double, long double); |
| 58 | long double coshl(long double); |
| 59 | long double cosl(long double); |
| 60 | long double erfcl(long double); |
| 61 | long double erfl(long double); |
| 62 | long double exp2l(long double); |
| 63 | long double expl(long double); |
| 64 | long double expm1l(long double); |
| 65 | long double fabsl(long double); |
| 66 | long double fdiml(long double, long double); |
| 67 | long double floorl(long double); |
| 68 | long double fmal(long double, long double, long double); |
| 69 | long double fmaxl(long double, long double); |
| 70 | long double fminl(long double, long double); |
| 71 | long double fmodl(long double, long double); |
| 72 | long double frexpl(long double value, int *); |
| 73 | long double hypotl(long double, long double); |
| 74 | int ilogbl(long double); |
| 75 | long double ldexpl(long double, int); |
| 76 | long double lgammal(long double); |
| 77 | long long llrintl(long double); |
| 78 | long long llroundl(long double); |
| 79 | long double log10l(long double); |
| 80 | long double log1pl(long double); |
| 81 | long double log2l(long double); |
| 82 | long double logbl(long double); |
| 83 | long double logl(long double); |
| 84 | long lrintl(long double); |
| 85 | long lroundl(long double); |
| 86 | long double modfl(long double, long double *); |
| 87 | long double nearbyintl(long double); |
| 88 | long double nextafterl(long double, long double); |
| 89 | long double nexttowardl(long double, long double); |
| 90 | long double powl(long double, long double); |
| 91 | long double remainderl(long double, long double); |
| 92 | long double remquol(long double, long double, int *); |
| 93 | long double rintl(long double); |
| 94 | long double roundl(long double); |
| 95 | long double scalblnl(long double, long); |
| 96 | long double scalbnl(long double, int); |
| 97 | long double sinhl(long double); |
| 98 | long double sinl(long double); |
| 99 | long double sqrtl(long double); |
| 100 | long double tanhl(long double); |
| 101 | long double tanl(long double); |
| 102 | long double tgammal(long double); |
| 103 | long double truncl(long double); |
| 104 | #endif |
| 105 | |
| 106 | #ifdef L_acoshl |
| 107 | WRAPPER1(acosh) |
| 108 | #endif |
| 109 | |
| 110 | #ifdef L_acosl |
| 111 | WRAPPER1(acos) |
| 112 | #endif |
| 113 | |
| 114 | #ifdef L_asinhl |
| 115 | WRAPPER1(asinh) |
| 116 | #endif |
| 117 | |
| 118 | #ifdef L_asinl |
| 119 | WRAPPER1(asin) |
| 120 | #endif |
| 121 | |
| 122 | #ifdef L_atan2l |
| 123 | WRAPPER2(atan2) |
| 124 | #endif |
| 125 | |
| 126 | #ifdef L_atanhl |
| 127 | WRAPPER1(atanh) |
| 128 | #endif |
| 129 | |
| 130 | #ifdef L_atanl |
| 131 | WRAPPER1(atan) |
| 132 | #endif |
| 133 | |
| 134 | #ifdef L_cargl |
| 135 | long double cargl (long double complex x) |
| 136 | { |
| 137 | return (long double) carg( (double complex)x ); |
| 138 | } |
| 139 | #endif |
| 140 | |
| 141 | #ifdef L_cbrtl |
| 142 | WRAPPER1(cbrt) |
| 143 | #endif |
| 144 | |
| 145 | #ifdef L_ceill |
| 146 | WRAPPER1(ceil) |
| 147 | #endif |
| 148 | |
| 149 | #ifdef L_copysignl |
| 150 | WRAPPER2(copysign) |
| 151 | #endif |
| 152 | |
| 153 | #ifdef L_coshl |
| 154 | WRAPPER1(cosh) |
| 155 | #endif |
| 156 | |
| 157 | #ifdef L_cosl |
| 158 | WRAPPER1(cos) |
| 159 | #endif |
| 160 | |
| 161 | #ifdef L_erfcl |
| 162 | WRAPPER1(erfc) |
| 163 | #endif |
| 164 | |
| 165 | #ifdef L_erfl |
| 166 | WRAPPER1(erf) |
| 167 | #endif |
| 168 | |
| 169 | #ifdef L_exp2l |
| 170 | WRAPPER1(exp2) |
| 171 | #endif |
| 172 | |
| 173 | #ifdef L_expl |
| 174 | WRAPPER1(exp) |
| 175 | #endif |
| 176 | |
| 177 | #ifdef L_expm1l |
| 178 | WRAPPER1(expm1) |
| 179 | #endif |
| 180 | |
| 181 | #ifdef L_fabsl |
| 182 | WRAPPER1(fabs) |
| 183 | #endif |
| 184 | |
| 185 | #ifdef L_fdiml |
| 186 | WRAPPER2(fdim) |
| 187 | #endif |
| 188 | |
| 189 | #ifdef L_floorl |
| 190 | WRAPPER1(floor) |
| 191 | #endif |
| 192 | |
| 193 | #ifdef L_fmal |
| 194 | long double fmal (long double x, long double y, long double z) |
| 195 | { |
| 196 | return (long double) fma( (double)x, (double)y, (double)z ); |
| 197 | } |
| 198 | #endif |
| 199 | |
| 200 | #ifdef L_fmaxl |
| 201 | WRAPPER2(fmax) |
| 202 | #endif |
| 203 | |
| 204 | #ifdef L_fminl |
| 205 | WRAPPER2(fmin) |
| 206 | #endif |
| 207 | |
| 208 | #ifdef L_fmodl |
| 209 | WRAPPER2(fmod) |
| 210 | #endif |
| 211 | |
| 212 | #ifdef L_frexpl |
| 213 | long double frexpl (long double x, int *ex) |
| 214 | { |
| 215 | return (long double) frexp( (double)x, ex ); |
| 216 | } |
| 217 | #endif |
| 218 | |
| 219 | #ifdef L_gammal |
| 220 | WRAPPER1(gamma) |
| 221 | #endif |
| 222 | |
| 223 | #ifdef L_hypotl |
| 224 | WRAPPER2(hypot) |
| 225 | #endif |
| 226 | |
| 227 | #ifdef L_ilogbl |
| 228 | int_WRAPPER1(ilogb) |
| 229 | #endif |
| 230 | |
| 231 | #ifdef L_ldexpl |
| 232 | long double ldexpl (long double x, int ex) |
| 233 | { |
| 234 | return (long double) ldexp( (double)x, ex ); |
| 235 | } |
| 236 | #endif |
| 237 | |
| 238 | #ifdef L_lgammal |
| 239 | WRAPPER1(lgamma) |
| 240 | #endif |
| 241 | |
| 242 | #ifdef L_llrintl |
| 243 | long_long_WRAPPER1(llrint) |
| 244 | #endif |
| 245 | |
| 246 | #ifdef L_llroundl |
| 247 | long_long_WRAPPER1(llround) |
| 248 | #endif |
| 249 | |
| 250 | #ifdef L_log10l |
| 251 | WRAPPER1(log10) |
| 252 | #endif |
| 253 | |
| 254 | #ifdef L_log1pl |
| 255 | WRAPPER1(log1p) |
| 256 | #endif |
| 257 | |
| 258 | #ifdef L_log2l |
| 259 | WRAPPER1(log2) |
| 260 | #endif |
| 261 | |
| 262 | #ifdef L_logbl |
| 263 | WRAPPER1(logb) |
| 264 | #endif |
| 265 | |
| 266 | #ifdef L_logl |
| 267 | WRAPPER1(log) |
| 268 | #endif |
| 269 | |
| 270 | #ifdef L_lrintl |
| 271 | long_WRAPPER1(lrint) |
| 272 | #endif |
| 273 | |
| 274 | #ifdef L_lroundl |
| 275 | long_WRAPPER1(lround) |
| 276 | #endif |
| 277 | |
| 278 | #ifdef L_modfl |
| 279 | long double modfl (long double x, long double *iptr) |
| 280 | { |
| 281 | double y, result; |
| 282 | result = modf ( x, &y ); |
| 283 | *iptr = (long double)y; |
| 284 | return (long double) result; |
| 285 | } |
| 286 | #endif |
| 287 | |
| 288 | #ifdef L_nearbyintl |
| 289 | WRAPPER1(nearbyint) |
| 290 | #endif |
| 291 | |
| 292 | #ifdef L_nextafterl |
| 293 | WRAPPER2(nextafter) |
| 294 | #endif |
| 295 | |
| 296 | /* Disabled in Makefile.in */ |
| 297 | #if 0 /* def L_nexttowardl */ |
| 298 | WRAPPER2(nexttoward) |
| 299 | libm_hidden_def(nexttowardl) |
| 300 | #endif |
| 301 | |
| 302 | #ifdef L_powl |
| 303 | WRAPPER2(pow) |
| 304 | #endif |
| 305 | |
| 306 | #ifdef L_remainderl |
| 307 | WRAPPER2(remainder) |
| 308 | #endif |
| 309 | |
| 310 | #ifdef L_remquol |
| 311 | long double remquol (long double x, long double y, int *quo) |
| 312 | { |
| 313 | return (long double) remquo( (double)x, (double)y, quo ); |
| 314 | } |
| 315 | #endif |
| 316 | |
| 317 | #ifdef L_rintl |
| 318 | WRAPPER1(rint) |
| 319 | #endif |
| 320 | |
| 321 | #ifdef L_roundl |
| 322 | WRAPPER1(round) |
| 323 | #endif |
| 324 | |
| 325 | #ifdef L_scalblnl |
| 326 | long double scalblnl (long double x, long ex) |
| 327 | { |
| 328 | return (long double) scalbln( (double)x, ex ); |
| 329 | } |
| 330 | #endif |
| 331 | |
| 332 | #ifdef L_scalbnl |
| 333 | long double scalbnl (long double x, int ex) |
| 334 | { |
| 335 | return (long double) scalbn( (double)x, ex ); |
| 336 | } |
| 337 | #endif |
| 338 | |
| 339 | /* scalb is an obsolete function */ |
| 340 | |
| 341 | #ifdef L_sinhl |
| 342 | WRAPPER1(sinh) |
| 343 | #endif |
| 344 | |
| 345 | #ifdef L_sinl |
| 346 | WRAPPER1(sin) |
| 347 | #endif |
| 348 | |
| 349 | #ifdef L_sqrtl |
| 350 | WRAPPER1(sqrt) |
| 351 | #endif |
| 352 | |
| 353 | #ifdef L_tanhl |
| 354 | WRAPPER1(tanh) |
| 355 | #endif |
| 356 | |
| 357 | #ifdef L_tanl |
| 358 | WRAPPER1(tan) |
| 359 | #endif |
| 360 | |
| 361 | #ifdef L_tgammal |
| 362 | WRAPPER1(tgamma) |
| 363 | #endif |
| 364 | |
| 365 | #ifdef L_truncl |
| 366 | WRAPPER1(trunc) |
| 367 | #endif |
| 368 | |
| 369 | #ifdef L_significandl |
| 370 | WRAPPER1(significand) |
| 371 | #endif |
| 372 | |
| 373 | #if defined __DO_C99_MATH__ && !defined __NO_LONG_DOUBLE_MATH |
| 374 | |
| 375 | # ifdef L___fpclassifyl |
| 376 | int_WRAPPER1(__fpclassify) |
| 377 | libm_hidden_def(__fpclassifyl) |
| 378 | # endif |
| 379 | |
| 380 | # ifdef L___finitel |
| 381 | int_WRAPPER1(__finite) |
| 382 | libm_hidden_def(__finitel) |
| 383 | # endif |
| 384 | |
| 385 | # ifdef L___signbitl |
| 386 | int_WRAPPER1(__signbit) |
| 387 | libm_hidden_def(__signbitl) |
| 388 | # endif |
| 389 | |
| 390 | # ifdef L___isnanl |
| 391 | int_WRAPPER1(__isnan) |
| 392 | libm_hidden_def(__isnanl) |
| 393 | # endif |
| 394 | |
| 395 | # ifdef L___isinfl |
| 396 | int_WRAPPER1(__isinf) |
| 397 | libm_hidden_def(__isinfl) |
| 398 | # endif |
| 399 | |
| 400 | #endif |