| OLD | NEW |
| 1 /* Implementation of various C99 functions | 1 /* Implementation of various C99 functions |
| 2 Copyright (C) 2004, 2009 Free Software Foundation, Inc. | 2 Copyright (C) 2004, 2009 Free Software Foundation, Inc. |
| 3 | 3 |
| 4 This file is part of the GNU Fortran 95 runtime library (libgfortran). | 4 This file is part of the GNU Fortran 95 runtime library (libgfortran). |
| 5 | 5 |
| 6 Libgfortran is free software; you can redistribute it and/or | 6 Libgfortran is free software; you can redistribute it and/or |
| 7 modify it under the terms of the GNU General Public | 7 modify it under the terms of the GNU General Public |
| 8 License as published by the Free Software Foundation; either | 8 License as published by the Free Software Foundation; either |
| 9 version 3 of the License, or (at your option) any later version. | 9 version 3 of the License, or (at your option) any later version. |
| 10 | 10 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 | 47 |
| 48 #ifdef __osf__ | 48 #ifdef __osf__ |
| 49 #undef HAVE_CABS | 49 #undef HAVE_CABS |
| 50 #undef HAVE_CABSF | 50 #undef HAVE_CABSF |
| 51 #undef HAVE_CABSL | 51 #undef HAVE_CABSL |
| 52 #define cabs __gfc_cabs | 52 #define cabs __gfc_cabs |
| 53 #define cabsf __gfc_cabsf | 53 #define cabsf __gfc_cabsf |
| 54 #define cabsl __gfc_cabsl | 54 #define cabsl __gfc_cabsl |
| 55 #endif | 55 #endif |
| 56 | 56 |
| 57 /* Prototypes to silence -Wstrict-prototypes -Wmissing-prototypes. */ | 57 /* On a C99 system "I" (with I*I = -1) should be defined in complex.h; |
| 58 if not, we define a fallback version here. */ |
| 59 #ifndef I |
| 60 # if defined(_Imaginary_I) |
| 61 # define I _Imaginary_I |
| 62 # elif defined(_Complex_I) |
| 63 # define I _Complex_I |
| 64 # else |
| 65 # define I (1.0fi) |
| 66 # endif |
| 67 #endif |
| 58 | 68 |
| 59 float cabsf(float complex); | 69 /* Prototypes are included to silence -Wstrict-prototypes |
| 60 double cabs(double complex); | 70 -Wmissing-prototypes. */ |
| 61 long double cabsl(long double complex); | |
| 62 | |
| 63 float cargf(float complex); | |
| 64 double carg(double complex); | |
| 65 long double cargl(long double complex); | |
| 66 | |
| 67 float complex clog10f(float complex); | |
| 68 double complex clog10(double complex); | |
| 69 long double complex clog10l(long double complex); | |
| 70 | 71 |
| 71 | 72 |
| 72 /* Wrappers for systems without the various C99 single precision Bessel | 73 /* Wrappers for systems without the various C99 single precision Bessel |
| 73 functions. */ | 74 functions. */ |
| 74 | 75 |
| 75 #if defined(HAVE_J0) && ! defined(HAVE_J0F) | 76 #if defined(HAVE_J0) && ! defined(HAVE_J0F) |
| 76 #define HAVE_J0F 1 | 77 #define HAVE_J0F 1 |
| 77 extern float j0f (float); | 78 float j0f (float); |
| 78 | 79 |
| 79 float | 80 float |
| 80 j0f (float x) | 81 j0f (float x) |
| 81 { | 82 { |
| 82 return (float) j0 ((double) x); | 83 return (float) j0 ((double) x); |
| 83 } | 84 } |
| 84 #endif | 85 #endif |
| 85 | 86 |
| 86 #if defined(HAVE_J1) && !defined(HAVE_J1F) | 87 #if defined(HAVE_J1) && !defined(HAVE_J1F) |
| 87 #define HAVE_J1F 1 | 88 #define HAVE_J1F 1 |
| 88 extern float j1f (float); | 89 float j1f (float); |
| 89 | 90 |
| 90 float j1f (float x) | 91 float j1f (float x) |
| 91 { | 92 { |
| 92 return (float) j1 ((double) x); | 93 return (float) j1 ((double) x); |
| 93 } | 94 } |
| 94 #endif | 95 #endif |
| 95 | 96 |
| 96 #if defined(HAVE_JN) && !defined(HAVE_JNF) | 97 #if defined(HAVE_JN) && !defined(HAVE_JNF) |
| 97 #define HAVE_JNF 1 | 98 #define HAVE_JNF 1 |
| 98 extern float jnf (int, float); | 99 float jnf (int, float); |
| 99 | 100 |
| 100 float | 101 float |
| 101 jnf (int n, float x) | 102 jnf (int n, float x) |
| 102 { | 103 { |
| 103 return (float) jn (n, (double) x); | 104 return (float) jn (n, (double) x); |
| 104 } | 105 } |
| 105 #endif | 106 #endif |
| 106 | 107 |
| 107 #if defined(HAVE_Y0) && !defined(HAVE_Y0F) | 108 #if defined(HAVE_Y0) && !defined(HAVE_Y0F) |
| 108 #define HAVE_Y0F 1 | 109 #define HAVE_Y0F 1 |
| 109 extern float y0f (float); | 110 float y0f (float); |
| 110 | 111 |
| 111 float | 112 float |
| 112 y0f (float x) | 113 y0f (float x) |
| 113 { | 114 { |
| 114 return (float) y0 ((double) x); | 115 return (float) y0 ((double) x); |
| 115 } | 116 } |
| 116 #endif | 117 #endif |
| 117 | 118 |
| 118 #if defined(HAVE_Y1) && !defined(HAVE_Y1F) | 119 #if defined(HAVE_Y1) && !defined(HAVE_Y1F) |
| 119 #define HAVE_Y1F 1 | 120 #define HAVE_Y1F 1 |
| 120 extern float y1f (float); | 121 float y1f (float); |
| 121 | 122 |
| 122 float | 123 float |
| 123 y1f (float x) | 124 y1f (float x) |
| 124 { | 125 { |
| 125 return (float) y1 ((double) x); | 126 return (float) y1 ((double) x); |
| 126 } | 127 } |
| 127 #endif | 128 #endif |
| 128 | 129 |
| 129 #if defined(HAVE_YN) && !defined(HAVE_YNF) | 130 #if defined(HAVE_YN) && !defined(HAVE_YNF) |
| 130 #define HAVE_YNF 1 | 131 #define HAVE_YNF 1 |
| 131 extern float ynf (int, float); | 132 float ynf (int, float); |
| 132 | 133 |
| 133 float | 134 float |
| 134 ynf (int n, float x) | 135 ynf (int n, float x) |
| 135 { | 136 { |
| 136 return (float) yn (n, (double) x); | 137 return (float) yn (n, (double) x); |
| 137 } | 138 } |
| 138 #endif | 139 #endif |
| 139 | 140 |
| 140 | 141 |
| 141 /* Wrappers for systems without the C99 erff() and erfcf() functions. */ | 142 /* Wrappers for systems without the C99 erff() and erfcf() functions. */ |
| 142 | 143 |
| 143 #if defined(HAVE_ERF) && !defined(HAVE_ERFF) | 144 #if defined(HAVE_ERF) && !defined(HAVE_ERFF) |
| 144 #define HAVE_ERFF 1 | 145 #define HAVE_ERFF 1 |
| 145 extern float erff (float); | 146 float erff (float); |
| 146 | 147 |
| 147 float | 148 float |
| 148 erff (float x) | 149 erff (float x) |
| 149 { | 150 { |
| 150 return (float) erf ((double) x); | 151 return (float) erf ((double) x); |
| 151 } | 152 } |
| 152 #endif | 153 #endif |
| 153 | 154 |
| 154 #if defined(HAVE_ERFC) && !defined(HAVE_ERFCF) | 155 #if defined(HAVE_ERFC) && !defined(HAVE_ERFCF) |
| 155 #define HAVE_ERFCF 1 | 156 #define HAVE_ERFCF 1 |
| 156 extern float erfcf (float); | 157 float erfcf (float); |
| 157 | 158 |
| 158 float | 159 float |
| 159 erfcf (float x) | 160 erfcf (float x) |
| 160 { | 161 { |
| 161 return (float) erfc ((double) x); | 162 return (float) erfc ((double) x); |
| 162 } | 163 } |
| 163 #endif | 164 #endif |
| 164 | 165 |
| 165 | 166 |
| 166 #ifndef HAVE_ACOSF | 167 #ifndef HAVE_ACOSF |
| 167 #define HAVE_ACOSF 1 | 168 #define HAVE_ACOSF 1 |
| 169 float acosf (float x); |
| 170 |
| 168 float | 171 float |
| 169 acosf(float x) | 172 acosf (float x) |
| 170 { | 173 { |
| 171 return (float) acos(x); | 174 return (float) acos (x); |
| 172 } | 175 } |
| 173 #endif | 176 #endif |
| 174 | 177 |
| 175 #if HAVE_ACOSH && !HAVE_ACOSHF | 178 #if HAVE_ACOSH && !HAVE_ACOSHF |
| 179 float acoshf (float x); |
| 180 |
| 176 float | 181 float |
| 177 acoshf (float x) | 182 acoshf (float x) |
| 178 { | 183 { |
| 179 return (float) acosh ((double) x); | 184 return (float) acosh ((double) x); |
| 180 } | 185 } |
| 181 #endif | 186 #endif |
| 182 | 187 |
| 183 #ifndef HAVE_ASINF | 188 #ifndef HAVE_ASINF |
| 184 #define HAVE_ASINF 1 | 189 #define HAVE_ASINF 1 |
| 190 float asinf (float x); |
| 191 |
| 185 float | 192 float |
| 186 asinf(float x) | 193 asinf (float x) |
| 187 { | 194 { |
| 188 return (float) asin(x); | 195 return (float) asin (x); |
| 189 } | 196 } |
| 190 #endif | 197 #endif |
| 191 | 198 |
| 192 #if HAVE_ASINH && !HAVE_ASINHF | 199 #if HAVE_ASINH && !HAVE_ASINHF |
| 200 float asinhf (float x); |
| 201 |
| 193 float | 202 float |
| 194 asinhf (float x) | 203 asinhf (float x) |
| 195 { | 204 { |
| 196 return (float) asinh ((double) x); | 205 return (float) asinh ((double) x); |
| 197 } | 206 } |
| 198 #endif | 207 #endif |
| 199 | 208 |
| 200 #ifndef HAVE_ATAN2F | 209 #ifndef HAVE_ATAN2F |
| 201 #define HAVE_ATAN2F 1 | 210 #define HAVE_ATAN2F 1 |
| 211 float atan2f (float y, float x); |
| 212 |
| 202 float | 213 float |
| 203 atan2f(float y, float x) | 214 atan2f (float y, float x) |
| 204 { | 215 { |
| 205 return (float) atan2(y, x); | 216 return (float) atan2 (y, x); |
| 206 } | 217 } |
| 207 #endif | 218 #endif |
| 208 | 219 |
| 209 #ifndef HAVE_ATANF | 220 #ifndef HAVE_ATANF |
| 210 #define HAVE_ATANF 1 | 221 #define HAVE_ATANF 1 |
| 222 float atanf (float x); |
| 223 |
| 211 float | 224 float |
| 212 atanf(float x) | 225 atanf (float x) |
| 213 { | 226 { |
| 214 return (float) atan(x); | 227 return (float) atan (x); |
| 215 } | 228 } |
| 216 #endif | 229 #endif |
| 217 | 230 |
| 218 #if HAVE_ATANH && !HAVE_ATANHF | 231 #if HAVE_ATANH && !HAVE_ATANHF |
| 232 float atanhf (float x); |
| 233 |
| 219 float | 234 float |
| 220 atanhf (float x) | 235 atanhf (float x) |
| 221 { | 236 { |
| 222 return (float) atanh ((double) x); | 237 return (float) atanh ((double) x); |
| 223 } | 238 } |
| 224 #endif | 239 #endif |
| 225 | 240 |
| 226 #ifndef HAVE_CEILF | 241 #ifndef HAVE_CEILF |
| 227 #define HAVE_CEILF 1 | 242 #define HAVE_CEILF 1 |
| 243 float ceilf (float x); |
| 244 |
| 228 float | 245 float |
| 229 ceilf(float x) | 246 ceilf (float x) |
| 230 { | 247 { |
| 231 return (float) ceil(x); | 248 return (float) ceil (x); |
| 232 } | 249 } |
| 233 #endif | 250 #endif |
| 234 | 251 |
| 235 #ifndef HAVE_COPYSIGNF | 252 #ifndef HAVE_COPYSIGNF |
| 236 #define HAVE_COPYSIGNF 1 | 253 #define HAVE_COPYSIGNF 1 |
| 254 float copysignf (float x, float y); |
| 255 |
| 237 float | 256 float |
| 238 copysignf(float x, float y) | 257 copysignf (float x, float y) |
| 239 { | 258 { |
| 240 return (float) copysign(x, y); | 259 return (float) copysign (x, y); |
| 241 } | 260 } |
| 242 #endif | 261 #endif |
| 243 | 262 |
| 244 #ifndef HAVE_COSF | 263 #ifndef HAVE_COSF |
| 245 #define HAVE_COSF 1 | 264 #define HAVE_COSF 1 |
| 265 float cosf (float x); |
| 266 |
| 246 float | 267 float |
| 247 cosf(float x) | 268 cosf (float x) |
| 248 { | 269 { |
| 249 return (float) cos(x); | 270 return (float) cos (x); |
| 250 } | 271 } |
| 251 #endif | 272 #endif |
| 252 | 273 |
| 253 #ifndef HAVE_COSHF | 274 #ifndef HAVE_COSHF |
| 254 #define HAVE_COSHF 1 | 275 #define HAVE_COSHF 1 |
| 276 float coshf (float x); |
| 277 |
| 255 float | 278 float |
| 256 coshf(float x) | 279 coshf (float x) |
| 257 { | 280 { |
| 258 return (float) cosh(x); | 281 return (float) cosh (x); |
| 259 } | 282 } |
| 260 #endif | 283 #endif |
| 261 | 284 |
| 262 #ifndef HAVE_EXPF | 285 #ifndef HAVE_EXPF |
| 263 #define HAVE_EXPF 1 | 286 #define HAVE_EXPF 1 |
| 287 float expf (float x); |
| 288 |
| 264 float | 289 float |
| 265 expf(float x) | 290 expf (float x) |
| 266 { | 291 { |
| 267 return (float) exp(x); | 292 return (float) exp (x); |
| 268 } | 293 } |
| 269 #endif | 294 #endif |
| 270 | 295 |
| 271 #ifndef HAVE_FABSF | 296 #ifndef HAVE_FABSF |
| 272 #define HAVE_FABSF 1 | 297 #define HAVE_FABSF 1 |
| 298 float fabsf (float x); |
| 299 |
| 273 float | 300 float |
| 274 fabsf(float x) | 301 fabsf (float x) |
| 275 { | 302 { |
| 276 return (float) fabs(x); | 303 return (float) fabs (x); |
| 277 } | 304 } |
| 278 #endif | 305 #endif |
| 279 | 306 |
| 280 #ifndef HAVE_FLOORF | 307 #ifndef HAVE_FLOORF |
| 281 #define HAVE_FLOORF 1 | 308 #define HAVE_FLOORF 1 |
| 309 float floorf (float x); |
| 310 |
| 282 float | 311 float |
| 283 floorf(float x) | 312 floorf (float x) |
| 284 { | 313 { |
| 285 return (float) floor(x); | 314 return (float) floor (x); |
| 286 } | 315 } |
| 287 #endif | 316 #endif |
| 288 | 317 |
| 289 #ifndef HAVE_FMODF | 318 #ifndef HAVE_FMODF |
| 290 #define HAVE_FMODF 1 | 319 #define HAVE_FMODF 1 |
| 320 float fmodf (float x, float y); |
| 321 |
| 291 float | 322 float |
| 292 fmodf (float x, float y) | 323 fmodf (float x, float y) |
| 293 { | 324 { |
| 294 return (float) fmod (x, y); | 325 return (float) fmod (x, y); |
| 295 } | 326 } |
| 296 #endif | 327 #endif |
| 297 | 328 |
| 298 #ifndef HAVE_FREXPF | 329 #ifndef HAVE_FREXPF |
| 299 #define HAVE_FREXPF 1 | 330 #define HAVE_FREXPF 1 |
| 331 float frexpf (float x, int *exp); |
| 332 |
| 300 float | 333 float |
| 301 frexpf(float x, int *exp) | 334 frexpf (float x, int *exp) |
| 302 { | 335 { |
| 303 return (float) frexp(x, exp); | 336 return (float) frexp (x, exp); |
| 304 } | 337 } |
| 305 #endif | 338 #endif |
| 306 | 339 |
| 307 #ifndef HAVE_HYPOTF | 340 #ifndef HAVE_HYPOTF |
| 308 #define HAVE_HYPOTF 1 | 341 #define HAVE_HYPOTF 1 |
| 342 float hypotf (float x, float y); |
| 343 |
| 309 float | 344 float |
| 310 hypotf(float x, float y) | 345 hypotf (float x, float y) |
| 311 { | 346 { |
| 312 return (float) hypot(x, y); | 347 return (float) hypot (x, y); |
| 313 } | 348 } |
| 314 #endif | 349 #endif |
| 315 | 350 |
| 316 #ifndef HAVE_LOGF | 351 #ifndef HAVE_LOGF |
| 317 #define HAVE_LOGF 1 | 352 #define HAVE_LOGF 1 |
| 353 float logf (float x); |
| 354 |
| 318 float | 355 float |
| 319 logf(float x) | 356 logf (float x) |
| 320 { | 357 { |
| 321 return (float) log(x); | 358 return (float) log (x); |
| 322 } | 359 } |
| 323 #endif | 360 #endif |
| 324 | 361 |
| 325 #ifndef HAVE_LOG10F | 362 #ifndef HAVE_LOG10F |
| 326 #define HAVE_LOG10F 1 | 363 #define HAVE_LOG10F 1 |
| 364 float log10f (float x); |
| 365 |
| 327 float | 366 float |
| 328 log10f(float x) | 367 log10f (float x) |
| 329 { | 368 { |
| 330 return (float) log10(x); | 369 return (float) log10 (x); |
| 331 } | 370 } |
| 332 #endif | 371 #endif |
| 333 | 372 |
| 334 #ifndef HAVE_SCALBN | 373 #ifndef HAVE_SCALBN |
| 335 #define HAVE_SCALBN 1 | 374 #define HAVE_SCALBN 1 |
| 375 double scalbn (double x, int y); |
| 376 |
| 336 double | 377 double |
| 337 scalbn(double x, int y) | 378 scalbn (double x, int y) |
| 338 { | 379 { |
| 339 #if (FLT_RADIX == 2) && defined(HAVE_LDEXP) | 380 #if (FLT_RADIX == 2) && defined(HAVE_LDEXP) |
| 340 return ldexp (x, y); | 381 return ldexp (x, y); |
| 341 #else | 382 #else |
| 342 return x * pow(FLT_RADIX, y); | 383 return x * pow (FLT_RADIX, y); |
| 343 #endif | 384 #endif |
| 344 } | 385 } |
| 345 #endif | 386 #endif |
| 346 | 387 |
| 347 #ifndef HAVE_SCALBNF | 388 #ifndef HAVE_SCALBNF |
| 348 #define HAVE_SCALBNF 1 | 389 #define HAVE_SCALBNF 1 |
| 390 float scalbnf (float x, int y); |
| 391 |
| 349 float | 392 float |
| 350 scalbnf(float x, int y) | 393 scalbnf (float x, int y) |
| 351 { | 394 { |
| 352 return (float) scalbn(x, y); | 395 return (float) scalbn (x, y); |
| 353 } | 396 } |
| 354 #endif | 397 #endif |
| 355 | 398 |
| 356 #ifndef HAVE_SINF | 399 #ifndef HAVE_SINF |
| 357 #define HAVE_SINF 1 | 400 #define HAVE_SINF 1 |
| 401 float sinf (float x); |
| 402 |
| 358 float | 403 float |
| 359 sinf(float x) | 404 sinf (float x) |
| 360 { | 405 { |
| 361 return (float) sin(x); | 406 return (float) sin (x); |
| 362 } | 407 } |
| 363 #endif | 408 #endif |
| 364 | 409 |
| 365 #ifndef HAVE_SINHF | 410 #ifndef HAVE_SINHF |
| 366 #define HAVE_SINHF 1 | 411 #define HAVE_SINHF 1 |
| 412 float sinhf (float x); |
| 413 |
| 367 float | 414 float |
| 368 sinhf(float x) | 415 sinhf (float x) |
| 369 { | 416 { |
| 370 return (float) sinh(x); | 417 return (float) sinh (x); |
| 371 } | 418 } |
| 372 #endif | 419 #endif |
| 373 | 420 |
| 374 #ifndef HAVE_SQRTF | 421 #ifndef HAVE_SQRTF |
| 375 #define HAVE_SQRTF 1 | 422 #define HAVE_SQRTF 1 |
| 423 float sqrtf (float x); |
| 424 |
| 376 float | 425 float |
| 377 sqrtf(float x) | 426 sqrtf (float x) |
| 378 { | 427 { |
| 379 return (float) sqrt(x); | 428 return (float) sqrt (x); |
| 380 } | 429 } |
| 381 #endif | 430 #endif |
| 382 | 431 |
| 383 #ifndef HAVE_TANF | 432 #ifndef HAVE_TANF |
| 384 #define HAVE_TANF 1 | 433 #define HAVE_TANF 1 |
| 434 float tanf (float x); |
| 435 |
| 385 float | 436 float |
| 386 tanf(float x) | 437 tanf (float x) |
| 387 { | 438 { |
| 388 return (float) tan(x); | 439 return (float) tan (x); |
| 389 } | 440 } |
| 390 #endif | 441 #endif |
| 391 | 442 |
| 392 #ifndef HAVE_TANHF | 443 #ifndef HAVE_TANHF |
| 393 #define HAVE_TANHF 1 | 444 #define HAVE_TANHF 1 |
| 445 float tanhf (float x); |
| 446 |
| 394 float | 447 float |
| 395 tanhf(float x) | 448 tanhf (float x) |
| 396 { | 449 { |
| 397 return (float) tanh(x); | 450 return (float) tanh (x); |
| 398 } | 451 } |
| 399 #endif | 452 #endif |
| 400 | 453 |
| 401 #ifndef HAVE_TRUNC | 454 #ifndef HAVE_TRUNC |
| 402 #define HAVE_TRUNC 1 | 455 #define HAVE_TRUNC 1 |
| 456 double trunc (double x); |
| 457 |
| 403 double | 458 double |
| 404 trunc(double x) | 459 trunc (double x) |
| 405 { | 460 { |
| 406 if (!isfinite (x)) | 461 if (!isfinite (x)) |
| 407 return x; | 462 return x; |
| 408 | 463 |
| 409 if (x < 0.0) | 464 if (x < 0.0) |
| 410 return - floor (-x); | 465 return - floor (-x); |
| 411 else | 466 else |
| 412 return floor (x); | 467 return floor (x); |
| 413 } | 468 } |
| 414 #endif | 469 #endif |
| 415 | 470 |
| 416 #ifndef HAVE_TRUNCF | 471 #ifndef HAVE_TRUNCF |
| 417 #define HAVE_TRUNCF 1 | 472 #define HAVE_TRUNCF 1 |
| 473 float truncf (float x); |
| 474 |
| 418 float | 475 float |
| 419 truncf(float x) | 476 truncf (float x) |
| 420 { | 477 { |
| 421 return (float) trunc (x); | 478 return (float) trunc (x); |
| 422 } | 479 } |
| 423 #endif | 480 #endif |
| 424 | 481 |
| 425 #ifndef HAVE_NEXTAFTERF | 482 #ifndef HAVE_NEXTAFTERF |
| 426 #define HAVE_NEXTAFTERF 1 | 483 #define HAVE_NEXTAFTERF 1 |
| 427 /* This is a portable implementation of nextafterf that is intended to be | 484 /* This is a portable implementation of nextafterf that is intended to be |
| 428 independent of the floating point format or its in memory representation. | 485 independent of the floating point format or its in memory representation. |
| 429 This implementation works correctly with denormalized values. */ | 486 This implementation works correctly with denormalized values. */ |
| 487 float nextafterf (float x, float y); |
| 488 |
| 430 float | 489 float |
| 431 nextafterf(float x, float y) | 490 nextafterf (float x, float y) |
| 432 { | 491 { |
| 433 /* This variable is marked volatile to avoid excess precision problems | 492 /* This variable is marked volatile to avoid excess precision problems |
| 434 on some platforms, including IA-32. */ | 493 on some platforms, including IA-32. */ |
| 435 volatile float delta; | 494 volatile float delta; |
| 436 float absx, denorm_min; | 495 float absx, denorm_min; |
| 437 | 496 |
| 438 if (isnan(x) || isnan(y)) | 497 if (isnan (x) || isnan (y)) |
| 439 return x + y; | 498 return x + y; |
| 440 if (x == y) | 499 if (x == y) |
| 441 return x; | 500 return x; |
| 442 if (!isfinite (x)) | 501 if (!isfinite (x)) |
| 443 return x > 0 ? __FLT_MAX__ : - __FLT_MAX__; | 502 return x > 0 ? __FLT_MAX__ : - __FLT_MAX__; |
| 444 | 503 |
| 445 /* absx = fabsf (x); */ | 504 /* absx = fabsf (x); */ |
| 446 absx = (x < 0.0) ? -x : x; | 505 absx = (x < 0.0) ? -x : x; |
| 447 | 506 |
| 448 /* __FLT_DENORM_MIN__ is non-zero iff the target supports denormals. */ | 507 /* __FLT_DENORM_MIN__ is non-zero iff the target supports denormals. */ |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 | 542 |
| 484 return x + delta; | 543 return x + delta; |
| 485 } | 544 } |
| 486 #endif | 545 #endif |
| 487 | 546 |
| 488 | 547 |
| 489 #if !defined(HAVE_POWF) || defined(HAVE_BROKEN_POWF) | 548 #if !defined(HAVE_POWF) || defined(HAVE_BROKEN_POWF) |
| 490 #ifndef HAVE_POWF | 549 #ifndef HAVE_POWF |
| 491 #define HAVE_POWF 1 | 550 #define HAVE_POWF 1 |
| 492 #endif | 551 #endif |
| 552 float powf (float x, float y); |
| 553 |
| 493 float | 554 float |
| 494 powf(float x, float y) | 555 powf (float x, float y) |
| 495 { | 556 { |
| 496 return (float) pow(x, y); | 557 return (float) pow (x, y); |
| 497 } | 558 } |
| 498 #endif | 559 #endif |
| 499 | 560 |
| 500 /* Note that if fpclassify is not defined, then NaN is not handled */ | 561 /* Note that if fpclassify is not defined, then NaN is not handled */ |
| 501 | 562 |
| 502 /* Algorithm by Steven G. Kargl. */ | 563 /* Algorithm by Steven G. Kargl. */ |
| 503 | 564 |
| 504 #if !defined(HAVE_ROUNDL) | 565 #if !defined(HAVE_ROUNDL) |
| 505 #define HAVE_ROUNDL 1 | 566 #define HAVE_ROUNDL 1 |
| 567 long double roundl (long double x); |
| 568 |
| 506 #if defined(HAVE_CEILL) | 569 #if defined(HAVE_CEILL) |
| 507 /* Round to nearest integral value. If the argument is halfway between two | 570 /* Round to nearest integral value. If the argument is halfway between two |
| 508 integral values then round away from zero. */ | 571 integral values then round away from zero. */ |
| 509 | 572 |
| 510 long double | 573 long double |
| 511 roundl(long double x) | 574 roundl (long double x) |
| 512 { | 575 { |
| 513 long double t; | 576 long double t; |
| 514 if (!isfinite (x)) | 577 if (!isfinite (x)) |
| 515 return (x); | 578 return (x); |
| 516 | 579 |
| 517 if (x >= 0.0) | 580 if (x >= 0.0) |
| 518 { | 581 { |
| 519 t = ceill(x); | 582 t = ceill (x); |
| 520 if (t - x > 0.5) | 583 if (t - x > 0.5) |
| 521 t -= 1.0; | 584 t -= 1.0; |
| 522 return (t); | 585 return (t); |
| 523 } | 586 } |
| 524 else | 587 else |
| 525 { | 588 { |
| 526 t = ceill(-x); | 589 t = ceill (-x); |
| 527 if (t + x > 0.5) | 590 if (t + x > 0.5) |
| 528 t -= 1.0; | 591 t -= 1.0; |
| 529 return (-t); | 592 return (-t); |
| 530 } | 593 } |
| 531 } | 594 } |
| 532 #else | 595 #else |
| 533 | 596 |
| 534 /* Poor version of roundl for system that don't have ceill. */ | 597 /* Poor version of roundl for system that don't have ceill. */ |
| 535 long double | 598 long double |
| 536 roundl(long double x) | 599 roundl (long double x) |
| 537 { | 600 { |
| 538 if (x > DBL_MAX || x < -DBL_MAX) | 601 if (x > DBL_MAX || x < -DBL_MAX) |
| 539 { | 602 { |
| 540 #ifdef HAVE_NEXTAFTERL | 603 #ifdef HAVE_NEXTAFTERL |
| 541 static long double prechalf = nexafterl (0.5L, LDBL_MAX); | 604 static long double prechalf = nexafterl (0.5L, LDBL_MAX); |
| 542 #else | 605 #else |
| 543 static long double prechalf = 0.5L; | 606 static long double prechalf = 0.5L; |
| 544 #endif | 607 #endif |
| 545 return (GFC_INTEGER_LARGEST) (x + (x > 0 ? prechalf : -prechalf)); | 608 return (GFC_INTEGER_LARGEST) (x + (x > 0 ? prechalf : -prechalf)); |
| 546 } | 609 } |
| 547 else | 610 else |
| 548 /* Use round(). */ | 611 /* Use round(). */ |
| 549 return round((double) x); | 612 return round ((double) x); |
| 550 } | 613 } |
| 551 | 614 |
| 552 #endif | 615 #endif |
| 553 #endif | 616 #endif |
| 554 | 617 |
| 555 #ifndef HAVE_ROUND | 618 #ifndef HAVE_ROUND |
| 556 #define HAVE_ROUND 1 | 619 #define HAVE_ROUND 1 |
| 557 /* Round to nearest integral value. If the argument is halfway between two | 620 /* Round to nearest integral value. If the argument is halfway between two |
| 558 integral values then round away from zero. */ | 621 integral values then round away from zero. */ |
| 622 double round (double x); |
| 559 | 623 |
| 560 double | 624 double |
| 561 round(double x) | 625 round (double x) |
| 562 { | 626 { |
| 563 double t; | 627 double t; |
| 564 if (!isfinite (x)) | 628 if (!isfinite (x)) |
| 565 return (x); | 629 return (x); |
| 566 | 630 |
| 567 if (x >= 0.0) | 631 if (x >= 0.0) |
| 568 { | 632 { |
| 569 t = ceil(x); | 633 t = floor (x); |
| 570 if (t - x > 0.5) | 634 if (t - x <= -0.5) |
| 571 » t -= 1.0; | 635 » t += 1.0; |
| 572 return (t); | 636 return (t); |
| 573 } | 637 } |
| 574 else | 638 else |
| 575 { | 639 { |
| 576 t = ceil(-x); | 640 t = floor (-x); |
| 577 if (t + x > 0.5) | 641 if (t + x <= -0.5) |
| 578 » t -= 1.0; | 642 » t += 1.0; |
| 579 return (-t); | 643 return (-t); |
| 580 } | 644 } |
| 581 } | 645 } |
| 582 #endif | 646 #endif |
| 583 | 647 |
| 584 #ifndef HAVE_ROUNDF | 648 #ifndef HAVE_ROUNDF |
| 585 #define HAVE_ROUNDF 1 | 649 #define HAVE_ROUNDF 1 |
| 586 /* Round to nearest integral value. If the argument is halfway between two | 650 /* Round to nearest integral value. If the argument is halfway between two |
| 587 integral values then round away from zero. */ | 651 integral values then round away from zero. */ |
| 652 float roundf (float x); |
| 588 | 653 |
| 589 float | 654 float |
| 590 roundf(float x) | 655 roundf (float x) |
| 591 { | 656 { |
| 592 float t; | 657 float t; |
| 593 if (!isfinite (x)) | 658 if (!isfinite (x)) |
| 594 return (x); | 659 return (x); |
| 595 | 660 |
| 596 if (x >= 0.0) | 661 if (x >= 0.0) |
| 597 { | 662 { |
| 598 t = ceilf(x); | 663 t = floorf (x); |
| 599 if (t - x > 0.5) | 664 if (t - x <= -0.5) |
| 600 » t -= 1.0; | 665 » t += 1.0; |
| 601 return (t); | 666 return (t); |
| 602 } | 667 } |
| 603 else | 668 else |
| 604 { | 669 { |
| 605 t = ceilf(-x); | 670 t = floorf (-x); |
| 606 if (t + x > 0.5) | 671 if (t + x <= -0.5) |
| 607 » t -= 1.0; | 672 » t += 1.0; |
| 608 return (-t); | 673 return (-t); |
| 609 } | 674 } |
| 610 } | 675 } |
| 611 #endif | 676 #endif |
| 612 | 677 |
| 613 | 678 |
| 614 /* lround{f,,l} and llround{f,,l} functions. */ | 679 /* lround{f,,l} and llround{f,,l} functions. */ |
| 615 | 680 |
| 616 #if !defined(HAVE_LROUNDF) && defined(HAVE_ROUNDF) | 681 #if !defined(HAVE_LROUNDF) && defined(HAVE_ROUNDF) |
| 617 #define HAVE_LROUNDF 1 | 682 #define HAVE_LROUNDF 1 |
| 683 long int lroundf (float x); |
| 684 |
| 618 long int | 685 long int |
| 619 lroundf (float x) | 686 lroundf (float x) |
| 620 { | 687 { |
| 621 return (long int) roundf (x); | 688 return (long int) roundf (x); |
| 622 } | 689 } |
| 623 #endif | 690 #endif |
| 624 | 691 |
| 625 #if !defined(HAVE_LROUND) && defined(HAVE_ROUND) | 692 #if !defined(HAVE_LROUND) && defined(HAVE_ROUND) |
| 626 #define HAVE_LROUND 1 | 693 #define HAVE_LROUND 1 |
| 694 long int lround (double x); |
| 695 |
| 627 long int | 696 long int |
| 628 lround (double x) | 697 lround (double x) |
| 629 { | 698 { |
| 630 return (long int) round (x); | 699 return (long int) round (x); |
| 631 } | 700 } |
| 632 #endif | 701 #endif |
| 633 | 702 |
| 634 #if !defined(HAVE_LROUNDL) && defined(HAVE_ROUNDL) | 703 #if !defined(HAVE_LROUNDL) && defined(HAVE_ROUNDL) |
| 635 #define HAVE_LROUNDL 1 | 704 #define HAVE_LROUNDL 1 |
| 705 long int lroundl (long double x); |
| 706 |
| 636 long int | 707 long int |
| 637 lroundl (long double x) | 708 lroundl (long double x) |
| 638 { | 709 { |
| 639 return (long long int) roundl (x); | 710 return (long long int) roundl (x); |
| 640 } | 711 } |
| 641 #endif | 712 #endif |
| 642 | 713 |
| 643 #if !defined(HAVE_LLROUNDF) && defined(HAVE_ROUNDF) | 714 #if !defined(HAVE_LLROUNDF) && defined(HAVE_ROUNDF) |
| 644 #define HAVE_LLROUNDF 1 | 715 #define HAVE_LLROUNDF 1 |
| 716 long long int llroundf (float x); |
| 717 |
| 645 long long int | 718 long long int |
| 646 llroundf (float x) | 719 llroundf (float x) |
| 647 { | 720 { |
| 648 return (long long int) roundf (x); | 721 return (long long int) roundf (x); |
| 649 } | 722 } |
| 650 #endif | 723 #endif |
| 651 | 724 |
| 652 #if !defined(HAVE_LLROUND) && defined(HAVE_ROUND) | 725 #if !defined(HAVE_LLROUND) && defined(HAVE_ROUND) |
| 653 #define HAVE_LLROUND 1 | 726 #define HAVE_LLROUND 1 |
| 727 long long int llround (double x); |
| 728 |
| 654 long long int | 729 long long int |
| 655 llround (double x) | 730 llround (double x) |
| 656 { | 731 { |
| 657 return (long long int) round (x); | 732 return (long long int) round (x); |
| 658 } | 733 } |
| 659 #endif | 734 #endif |
| 660 | 735 |
| 661 #if !defined(HAVE_LLROUNDL) && defined(HAVE_ROUNDL) | 736 #if !defined(HAVE_LLROUNDL) && defined(HAVE_ROUNDL) |
| 662 #define HAVE_LLROUNDL 1 | 737 #define HAVE_LLROUNDL 1 |
| 738 long long int llroundl (long double x); |
| 739 |
| 663 long long int | 740 long long int |
| 664 llroundl (long double x) | 741 llroundl (long double x) |
| 665 { | 742 { |
| 666 return (long long int) roundl (x); | 743 return (long long int) roundl (x); |
| 667 } | 744 } |
| 668 #endif | 745 #endif |
| 669 | 746 |
| 670 | 747 |
| 671 #ifndef HAVE_LOG10L | 748 #ifndef HAVE_LOG10L |
| 672 #define HAVE_LOG10L 1 | 749 #define HAVE_LOG10L 1 |
| 673 /* log10 function for long double variables. The version provided here | 750 /* log10 function for long double variables. The version provided here |
| 674 reduces the argument until it fits into a double, then use log10. */ | 751 reduces the argument until it fits into a double, then use log10. */ |
| 752 long double log10l (long double x); |
| 753 |
| 675 long double | 754 long double |
| 676 log10l(long double x) | 755 log10l (long double x) |
| 677 { | 756 { |
| 678 #if LDBL_MAX_EXP > DBL_MAX_EXP | 757 #if LDBL_MAX_EXP > DBL_MAX_EXP |
| 679 if (x > DBL_MAX) | 758 if (x > DBL_MAX) |
| 680 { | 759 { |
| 681 double val; | 760 double val; |
| 682 int p2_result = 0; | 761 int p2_result = 0; |
| 683 if (x > 0x1p16383L) { p2_result += 16383; x /= 0x1p16383L; } | 762 if (x > 0x1p16383L) { p2_result += 16383; x /= 0x1p16383L; } |
| 684 if (x > 0x1p8191L) { p2_result += 8191; x /= 0x1p8191L; } | 763 if (x > 0x1p8191L) { p2_result += 8191; x /= 0x1p8191L; } |
| 685 if (x > 0x1p4095L) { p2_result += 4095; x /= 0x1p4095L; } | 764 if (x > 0x1p4095L) { p2_result += 4095; x /= 0x1p4095L; } |
| 686 if (x > 0x1p2047L) { p2_result += 2047; x /= 0x1p2047L; } | 765 if (x > 0x1p2047L) { p2_result += 2047; x /= 0x1p2047L; } |
| 687 if (x > 0x1p1023L) { p2_result += 1023; x /= 0x1p1023L; } | 766 if (x > 0x1p1023L) { p2_result += 1023; x /= 0x1p1023L; } |
| 688 val = log10 ((double) x); | 767 val = log10 ((double) x); |
| 689 return (val + p2_result * .30102999566398119521373889472449302L); | 768 return (val + p2_result * .30102999566398119521373889472449302L); |
| 690 } | 769 } |
| 691 #endif | 770 #endif |
| 692 #if LDBL_MIN_EXP < DBL_MIN_EXP | 771 #if LDBL_MIN_EXP < DBL_MIN_EXP |
| 693 if (x < DBL_MIN) | 772 if (x < DBL_MIN) |
| 694 { | 773 { |
| 695 double val; | 774 double val; |
| 696 int p2_result = 0; | 775 int p2_result = 0; |
| 697 if (x < 0x1p-16380L) { p2_result += 16380; x /= 0x1p-16380L; } | 776 if (x < 0x1p-16380L) { p2_result += 16380; x /= 0x1p-16380L; } |
| 698 if (x < 0x1p-8189L) { p2_result += 8189; x /= 0x1p-8189L; } | 777 if (x < 0x1p-8189L) { p2_result += 8189; x /= 0x1p-8189L; } |
| 699 if (x < 0x1p-4093L) { p2_result += 4093; x /= 0x1p-4093L; } | 778 if (x < 0x1p-4093L) { p2_result += 4093; x /= 0x1p-4093L; } |
| 700 if (x < 0x1p-2045L) { p2_result += 2045; x /= 0x1p-2045L; } | 779 if (x < 0x1p-2045L) { p2_result += 2045; x /= 0x1p-2045L; } |
| 701 if (x < 0x1p-1021L) { p2_result += 1021; x /= 0x1p-1021L; } | 780 if (x < 0x1p-1021L) { p2_result += 1021; x /= 0x1p-1021L; } |
| 702 val = fabs(log10 ((double) x)); | 781 val = fabs (log10 ((double) x)); |
| 703 return (- val - p2_result * .30102999566398119521373889472449302L); | 782 return (- val - p2_result * .30102999566398119521373889472449302L); |
| 704 } | 783 } |
| 705 #endif | 784 #endif |
| 706 return log10 (x); | 785 return log10 (x); |
| 707 } | 786 } |
| 708 #endif | 787 #endif |
| 709 | 788 |
| 710 | 789 |
| 711 #ifndef HAVE_FLOORL | 790 #ifndef HAVE_FLOORL |
| 712 #define HAVE_FLOORL 1 | 791 #define HAVE_FLOORL 1 |
| 792 long double floorl (long double x); |
| 793 |
| 713 long double | 794 long double |
| 714 floorl (long double x) | 795 floorl (long double x) |
| 715 { | 796 { |
| 716 /* Zero, possibly signed. */ | 797 /* Zero, possibly signed. */ |
| 717 if (x == 0) | 798 if (x == 0) |
| 718 return x; | 799 return x; |
| 719 | 800 |
| 720 /* Large magnitude. */ | 801 /* Large magnitude. */ |
| 721 if (x > DBL_MAX || x < (-DBL_MAX)) | 802 if (x > DBL_MAX || x < (-DBL_MAX)) |
| 722 return x; | 803 return x; |
| 723 | 804 |
| 724 /* Small positive values. */ | 805 /* Small positive values. */ |
| 725 if (x >= 0 && x < DBL_MIN) | 806 if (x >= 0 && x < DBL_MIN) |
| 726 return 0; | 807 return 0; |
| 727 | 808 |
| 728 /* Small negative values. */ | 809 /* Small negative values. */ |
| 729 if (x < 0 && x > (-DBL_MIN)) | 810 if (x < 0 && x > (-DBL_MIN)) |
| 730 return -1; | 811 return -1; |
| 731 | 812 |
| 732 return floor (x); | 813 return floor (x); |
| 733 } | 814 } |
| 734 #endif | 815 #endif |
| 735 | 816 |
| 736 | 817 |
| 737 #ifndef HAVE_FMODL | 818 #ifndef HAVE_FMODL |
| 738 #define HAVE_FMODL 1 | 819 #define HAVE_FMODL 1 |
| 820 long double fmodl (long double x, long double y); |
| 821 |
| 739 long double | 822 long double |
| 740 fmodl (long double x, long double y) | 823 fmodl (long double x, long double y) |
| 741 { | 824 { |
| 742 if (y == 0.0L) | 825 if (y == 0.0L) |
| 743 return 0.0L; | 826 return 0.0L; |
| 744 | 827 |
| 745 /* Need to check that the result has the same sign as x and magnitude | 828 /* Need to check that the result has the same sign as x and magnitude |
| 746 less than the magnitude of y. */ | 829 less than the magnitude of y. */ |
| 747 return x - floorl (x / y) * y; | 830 return x - floorl (x / y) * y; |
| 748 } | 831 } |
| 749 #endif | 832 #endif |
| 750 | 833 |
| 751 | 834 |
| 752 #if !defined(HAVE_CABSF) | 835 #if !defined(HAVE_CABSF) |
| 753 #define HAVE_CABSF 1 | 836 #define HAVE_CABSF 1 |
| 837 float cabsf (float complex z); |
| 838 |
| 754 float | 839 float |
| 755 cabsf (float complex z) | 840 cabsf (float complex z) |
| 756 { | 841 { |
| 757 return hypotf (REALPART (z), IMAGPART (z)); | 842 return hypotf (REALPART (z), IMAGPART (z)); |
| 758 } | 843 } |
| 759 #endif | 844 #endif |
| 760 | 845 |
| 761 #if !defined(HAVE_CABS) | 846 #if !defined(HAVE_CABS) |
| 762 #define HAVE_CABS 1 | 847 #define HAVE_CABS 1 |
| 848 double cabs (double complex z); |
| 849 |
| 763 double | 850 double |
| 764 cabs (double complex z) | 851 cabs (double complex z) |
| 765 { | 852 { |
| 766 return hypot (REALPART (z), IMAGPART (z)); | 853 return hypot (REALPART (z), IMAGPART (z)); |
| 767 } | 854 } |
| 768 #endif | 855 #endif |
| 769 | 856 |
| 770 #if !defined(HAVE_CABSL) && defined(HAVE_HYPOTL) | 857 #if !defined(HAVE_CABSL) && defined(HAVE_HYPOTL) |
| 771 #define HAVE_CABSL 1 | 858 #define HAVE_CABSL 1 |
| 859 long double cabsl (long double complex z); |
| 860 |
| 772 long double | 861 long double |
| 773 cabsl (long double complex z) | 862 cabsl (long double complex z) |
| 774 { | 863 { |
| 775 return hypotl (REALPART (z), IMAGPART (z)); | 864 return hypotl (REALPART (z), IMAGPART (z)); |
| 776 } | 865 } |
| 777 #endif | 866 #endif |
| 778 | 867 |
| 779 | 868 |
| 780 #if !defined(HAVE_CARGF) | 869 #if !defined(HAVE_CARGF) |
| 781 #define HAVE_CARGF 1 | 870 #define HAVE_CARGF 1 |
| 871 float cargf (float complex z); |
| 872 |
| 782 float | 873 float |
| 783 cargf (float complex z) | 874 cargf (float complex z) |
| 784 { | 875 { |
| 785 return atan2f (IMAGPART (z), REALPART (z)); | 876 return atan2f (IMAGPART (z), REALPART (z)); |
| 786 } | 877 } |
| 787 #endif | 878 #endif |
| 788 | 879 |
| 789 #if !defined(HAVE_CARG) | 880 #if !defined(HAVE_CARG) |
| 790 #define HAVE_CARG 1 | 881 #define HAVE_CARG 1 |
| 882 double carg (double complex z); |
| 883 |
| 791 double | 884 double |
| 792 carg (double complex z) | 885 carg (double complex z) |
| 793 { | 886 { |
| 794 return atan2 (IMAGPART (z), REALPART (z)); | 887 return atan2 (IMAGPART (z), REALPART (z)); |
| 795 } | 888 } |
| 796 #endif | 889 #endif |
| 797 | 890 |
| 798 #if !defined(HAVE_CARGL) && defined(HAVE_ATAN2L) | 891 #if !defined(HAVE_CARGL) && defined(HAVE_ATAN2L) |
| 799 #define HAVE_CARGL 1 | 892 #define HAVE_CARGL 1 |
| 893 long double cargl (long double complex z); |
| 894 |
| 800 long double | 895 long double |
| 801 cargl (long double complex z) | 896 cargl (long double complex z) |
| 802 { | 897 { |
| 803 return atan2l (IMAGPART (z), REALPART (z)); | 898 return atan2l (IMAGPART (z), REALPART (z)); |
| 804 } | 899 } |
| 805 #endif | 900 #endif |
| 806 | 901 |
| 807 | 902 |
| 808 /* exp(z) = exp(a)*(cos(b) + i sin(b)) */ | 903 /* exp(z) = exp(a)*(cos(b) + i sin(b)) */ |
| 809 #if !defined(HAVE_CEXPF) | 904 #if !defined(HAVE_CEXPF) |
| 810 #define HAVE_CEXPF 1 | 905 #define HAVE_CEXPF 1 |
| 906 float complex cexpf (float complex z); |
| 907 |
| 811 float complex | 908 float complex |
| 812 cexpf (float complex z) | 909 cexpf (float complex z) |
| 813 { | 910 { |
| 814 float a, b; | 911 float a, b; |
| 815 float complex v; | 912 float complex v; |
| 816 | 913 |
| 817 a = REALPART (z); | 914 a = REALPART (z); |
| 818 b = IMAGPART (z); | 915 b = IMAGPART (z); |
| 819 COMPLEX_ASSIGN (v, cosf (b), sinf (b)); | 916 COMPLEX_ASSIGN (v, cosf (b), sinf (b)); |
| 820 return expf (a) * v; | 917 return expf (a) * v; |
| 821 } | 918 } |
| 822 #endif | 919 #endif |
| 823 | 920 |
| 824 #if !defined(HAVE_CEXP) | 921 #if !defined(HAVE_CEXP) |
| 825 #define HAVE_CEXP 1 | 922 #define HAVE_CEXP 1 |
| 923 double complex cexp (double complex z); |
| 924 |
| 826 double complex | 925 double complex |
| 827 cexp (double complex z) | 926 cexp (double complex z) |
| 828 { | 927 { |
| 829 double a, b; | 928 double a, b; |
| 830 double complex v; | 929 double complex v; |
| 831 | 930 |
| 832 a = REALPART (z); | 931 a = REALPART (z); |
| 833 b = IMAGPART (z); | 932 b = IMAGPART (z); |
| 834 COMPLEX_ASSIGN (v, cos (b), sin (b)); | 933 COMPLEX_ASSIGN (v, cos (b), sin (b)); |
| 835 return exp (a) * v; | 934 return exp (a) * v; |
| 836 } | 935 } |
| 837 #endif | 936 #endif |
| 838 | 937 |
| 839 #if !defined(HAVE_CEXPL) && defined(HAVE_COSL) && defined(HAVE_SINL) && defined(
EXPL) | 938 #if !defined(HAVE_CEXPL) && defined(HAVE_COSL) && defined(HAVE_SINL) && defined(
EXPL) |
| 840 #define HAVE_CEXPL 1 | 939 #define HAVE_CEXPL 1 |
| 940 long double complex cexpl (long double complex z); |
| 941 |
| 841 long double complex | 942 long double complex |
| 842 cexpl (long double complex z) | 943 cexpl (long double complex z) |
| 843 { | 944 { |
| 844 long double a, b; | 945 long double a, b; |
| 845 long double complex v; | 946 long double complex v; |
| 846 | 947 |
| 847 a = REALPART (z); | 948 a = REALPART (z); |
| 848 b = IMAGPART (z); | 949 b = IMAGPART (z); |
| 849 COMPLEX_ASSIGN (v, cosl (b), sinl (b)); | 950 COMPLEX_ASSIGN (v, cosl (b), sinl (b)); |
| 850 return expl (a) * v; | 951 return expl (a) * v; |
| 851 } | 952 } |
| 852 #endif | 953 #endif |
| 853 | 954 |
| 854 | 955 |
| 855 /* log(z) = log (cabs(z)) + i*carg(z) */ | 956 /* log(z) = log (cabs(z)) + i*carg(z) */ |
| 856 #if !defined(HAVE_CLOGF) | 957 #if !defined(HAVE_CLOGF) |
| 857 #define HAVE_CLOGF 1 | 958 #define HAVE_CLOGF 1 |
| 959 float complex clogf (float complex z); |
| 960 |
| 858 float complex | 961 float complex |
| 859 clogf (float complex z) | 962 clogf (float complex z) |
| 860 { | 963 { |
| 861 float complex v; | 964 float complex v; |
| 862 | 965 |
| 863 COMPLEX_ASSIGN (v, logf (cabsf (z)), cargf (z)); | 966 COMPLEX_ASSIGN (v, logf (cabsf (z)), cargf (z)); |
| 864 return v; | 967 return v; |
| 865 } | 968 } |
| 866 #endif | 969 #endif |
| 867 | 970 |
| 868 #if !defined(HAVE_CLOG) | 971 #if !defined(HAVE_CLOG) |
| 869 #define HAVE_CLOG 1 | 972 #define HAVE_CLOG 1 |
| 973 double complex clog (double complex z); |
| 974 |
| 870 double complex | 975 double complex |
| 871 clog (double complex z) | 976 clog (double complex z) |
| 872 { | 977 { |
| 873 double complex v; | 978 double complex v; |
| 874 | 979 |
| 875 COMPLEX_ASSIGN (v, log (cabs (z)), carg (z)); | 980 COMPLEX_ASSIGN (v, log (cabs (z)), carg (z)); |
| 876 return v; | 981 return v; |
| 877 } | 982 } |
| 878 #endif | 983 #endif |
| 879 | 984 |
| 880 #if !defined(HAVE_CLOGL) && defined(HAVE_LOGL) && defined(HAVE_CABSL) && defined
(HAVE_CARGL) | 985 #if !defined(HAVE_CLOGL) && defined(HAVE_LOGL) && defined(HAVE_CABSL) && defined
(HAVE_CARGL) |
| 881 #define HAVE_CLOGL 1 | 986 #define HAVE_CLOGL 1 |
| 987 long double complex clogl (long double complex z); |
| 988 |
| 882 long double complex | 989 long double complex |
| 883 clogl (long double complex z) | 990 clogl (long double complex z) |
| 884 { | 991 { |
| 885 long double complex v; | 992 long double complex v; |
| 886 | 993 |
| 887 COMPLEX_ASSIGN (v, logl (cabsl (z)), cargl (z)); | 994 COMPLEX_ASSIGN (v, logl (cabsl (z)), cargl (z)); |
| 888 return v; | 995 return v; |
| 889 } | 996 } |
| 890 #endif | 997 #endif |
| 891 | 998 |
| 892 | 999 |
| 893 /* log10(z) = log10 (cabs(z)) + i*carg(z) */ | 1000 /* log10(z) = log10 (cabs(z)) + i*carg(z) */ |
| 894 #if !defined(HAVE_CLOG10F) | 1001 #if !defined(HAVE_CLOG10F) |
| 895 #define HAVE_CLOG10F 1 | 1002 #define HAVE_CLOG10F 1 |
| 1003 float complex clog10f (float complex z); |
| 1004 |
| 896 float complex | 1005 float complex |
| 897 clog10f (float complex z) | 1006 clog10f (float complex z) |
| 898 { | 1007 { |
| 899 float complex v; | 1008 float complex v; |
| 900 | 1009 |
| 901 COMPLEX_ASSIGN (v, log10f (cabsf (z)), cargf (z)); | 1010 COMPLEX_ASSIGN (v, log10f (cabsf (z)), cargf (z)); |
| 902 return v; | 1011 return v; |
| 903 } | 1012 } |
| 904 #endif | 1013 #endif |
| 905 | 1014 |
| 906 #if !defined(HAVE_CLOG10) | 1015 #if !defined(HAVE_CLOG10) |
| 907 #define HAVE_CLOG10 1 | 1016 #define HAVE_CLOG10 1 |
| 1017 double complex clog10 (double complex z); |
| 1018 |
| 908 double complex | 1019 double complex |
| 909 clog10 (double complex z) | 1020 clog10 (double complex z) |
| 910 { | 1021 { |
| 911 double complex v; | 1022 double complex v; |
| 912 | 1023 |
| 913 COMPLEX_ASSIGN (v, log10 (cabs (z)), carg (z)); | 1024 COMPLEX_ASSIGN (v, log10 (cabs (z)), carg (z)); |
| 914 return v; | 1025 return v; |
| 915 } | 1026 } |
| 916 #endif | 1027 #endif |
| 917 | 1028 |
| 918 #if !defined(HAVE_CLOG10L) && defined(HAVE_LOG10L) && defined(HAVE_CABSL) && def
ined(HAVE_CARGL) | 1029 #if !defined(HAVE_CLOG10L) && defined(HAVE_LOG10L) && defined(HAVE_CABSL) && def
ined(HAVE_CARGL) |
| 919 #define HAVE_CLOG10L 1 | 1030 #define HAVE_CLOG10L 1 |
| 1031 long double complex clog10l (long double complex z); |
| 1032 |
| 920 long double complex | 1033 long double complex |
| 921 clog10l (long double complex z) | 1034 clog10l (long double complex z) |
| 922 { | 1035 { |
| 923 long double complex v; | 1036 long double complex v; |
| 924 | 1037 |
| 925 COMPLEX_ASSIGN (v, log10l (cabsl (z)), cargl (z)); | 1038 COMPLEX_ASSIGN (v, log10l (cabsl (z)), cargl (z)); |
| 926 return v; | 1039 return v; |
| 927 } | 1040 } |
| 928 #endif | 1041 #endif |
| 929 | 1042 |
| 930 | 1043 |
| 931 /* pow(base, power) = cexp (power * clog (base)) */ | 1044 /* pow(base, power) = cexp (power * clog (base)) */ |
| 932 #if !defined(HAVE_CPOWF) | 1045 #if !defined(HAVE_CPOWF) |
| 933 #define HAVE_CPOWF 1 | 1046 #define HAVE_CPOWF 1 |
| 1047 float complex cpowf (float complex base, float complex power); |
| 1048 |
| 934 float complex | 1049 float complex |
| 935 cpowf (float complex base, float complex power) | 1050 cpowf (float complex base, float complex power) |
| 936 { | 1051 { |
| 937 return cexpf (power * clogf (base)); | 1052 return cexpf (power * clogf (base)); |
| 938 } | 1053 } |
| 939 #endif | 1054 #endif |
| 940 | 1055 |
| 941 #if !defined(HAVE_CPOW) | 1056 #if !defined(HAVE_CPOW) |
| 942 #define HAVE_CPOW 1 | 1057 #define HAVE_CPOW 1 |
| 1058 double complex cpow (double complex base, double complex power); |
| 1059 |
| 943 double complex | 1060 double complex |
| 944 cpow (double complex base, double complex power) | 1061 cpow (double complex base, double complex power) |
| 945 { | 1062 { |
| 946 return cexp (power * clog (base)); | 1063 return cexp (power * clog (base)); |
| 947 } | 1064 } |
| 948 #endif | 1065 #endif |
| 949 | 1066 |
| 950 #if !defined(HAVE_CPOWL) && defined(HAVE_CEXPL) && defined(HAVE_CLOGL) | 1067 #if !defined(HAVE_CPOWL) && defined(HAVE_CEXPL) && defined(HAVE_CLOGL) |
| 951 #define HAVE_CPOWL 1 | 1068 #define HAVE_CPOWL 1 |
| 1069 long double complex cpowl (long double complex base, long double complex power); |
| 1070 |
| 952 long double complex | 1071 long double complex |
| 953 cpowl (long double complex base, long double complex power) | 1072 cpowl (long double complex base, long double complex power) |
| 954 { | 1073 { |
| 955 return cexpl (power * clogl (base)); | 1074 return cexpl (power * clogl (base)); |
| 956 } | 1075 } |
| 957 #endif | 1076 #endif |
| 958 | 1077 |
| 959 | 1078 |
| 960 /* sqrt(z). Algorithm pulled from glibc. */ | 1079 /* sqrt(z). Algorithm pulled from glibc. */ |
| 961 #if !defined(HAVE_CSQRTF) | 1080 #if !defined(HAVE_CSQRTF) |
| 962 #define HAVE_CSQRTF 1 | 1081 #define HAVE_CSQRTF 1 |
| 1082 float complex csqrtf (float complex z); |
| 1083 |
| 963 float complex | 1084 float complex |
| 964 csqrtf (float complex z) | 1085 csqrtf (float complex z) |
| 965 { | 1086 { |
| 966 float re, im; | 1087 float re, im; |
| 967 float complex v; | 1088 float complex v; |
| 968 | 1089 |
| 969 re = REALPART (z); | 1090 re = REALPART (z); |
| 970 im = IMAGPART (z); | 1091 im = IMAGPART (z); |
| 971 if (im == 0) | 1092 if (im == 0) |
| 972 { | 1093 { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1006 } | 1127 } |
| 1007 | 1128 |
| 1008 COMPLEX_ASSIGN (v, r, copysignf (s, im)); | 1129 COMPLEX_ASSIGN (v, r, copysignf (s, im)); |
| 1009 } | 1130 } |
| 1010 return v; | 1131 return v; |
| 1011 } | 1132 } |
| 1012 #endif | 1133 #endif |
| 1013 | 1134 |
| 1014 #if !defined(HAVE_CSQRT) | 1135 #if !defined(HAVE_CSQRT) |
| 1015 #define HAVE_CSQRT 1 | 1136 #define HAVE_CSQRT 1 |
| 1137 double complex csqrt (double complex z); |
| 1138 |
| 1016 double complex | 1139 double complex |
| 1017 csqrt (double complex z) | 1140 csqrt (double complex z) |
| 1018 { | 1141 { |
| 1019 double re, im; | 1142 double re, im; |
| 1020 double complex v; | 1143 double complex v; |
| 1021 | 1144 |
| 1022 re = REALPART (z); | 1145 re = REALPART (z); |
| 1023 im = IMAGPART (z); | 1146 im = IMAGPART (z); |
| 1024 if (im == 0) | 1147 if (im == 0) |
| 1025 { | 1148 { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1059 } | 1182 } |
| 1060 | 1183 |
| 1061 COMPLEX_ASSIGN (v, r, copysign (s, im)); | 1184 COMPLEX_ASSIGN (v, r, copysign (s, im)); |
| 1062 } | 1185 } |
| 1063 return v; | 1186 return v; |
| 1064 } | 1187 } |
| 1065 #endif | 1188 #endif |
| 1066 | 1189 |
| 1067 #if !defined(HAVE_CSQRTL) && defined(HAVE_COPYSIGNL) && defined(HAVE_SQRTL) && d
efined(HAVE_FABSL) && defined(HAVE_HYPOTL) | 1190 #if !defined(HAVE_CSQRTL) && defined(HAVE_COPYSIGNL) && defined(HAVE_SQRTL) && d
efined(HAVE_FABSL) && defined(HAVE_HYPOTL) |
| 1068 #define HAVE_CSQRTL 1 | 1191 #define HAVE_CSQRTL 1 |
| 1192 long double complex csqrtl (long double complex z); |
| 1193 |
| 1069 long double complex | 1194 long double complex |
| 1070 csqrtl (long double complex z) | 1195 csqrtl (long double complex z) |
| 1071 { | 1196 { |
| 1072 long double re, im; | 1197 long double re, im; |
| 1073 long double complex v; | 1198 long double complex v; |
| 1074 | 1199 |
| 1075 re = REALPART (z); | 1200 re = REALPART (z); |
| 1076 im = IMAGPART (z); | 1201 im = IMAGPART (z); |
| 1077 if (im == 0) | 1202 if (im == 0) |
| 1078 { | 1203 { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1114 COMPLEX_ASSIGN (v, r, copysignl (s, im)); | 1239 COMPLEX_ASSIGN (v, r, copysignl (s, im)); |
| 1115 } | 1240 } |
| 1116 return v; | 1241 return v; |
| 1117 } | 1242 } |
| 1118 #endif | 1243 #endif |
| 1119 | 1244 |
| 1120 | 1245 |
| 1121 /* sinh(a + i b) = sinh(a) cos(b) + i cosh(a) sin(b) */ | 1246 /* sinh(a + i b) = sinh(a) cos(b) + i cosh(a) sin(b) */ |
| 1122 #if !defined(HAVE_CSINHF) | 1247 #if !defined(HAVE_CSINHF) |
| 1123 #define HAVE_CSINHF 1 | 1248 #define HAVE_CSINHF 1 |
| 1249 float complex csinhf (float complex a); |
| 1250 |
| 1124 float complex | 1251 float complex |
| 1125 csinhf (float complex a) | 1252 csinhf (float complex a) |
| 1126 { | 1253 { |
| 1127 float r, i; | 1254 float r, i; |
| 1128 float complex v; | 1255 float complex v; |
| 1129 | 1256 |
| 1130 r = REALPART (a); | 1257 r = REALPART (a); |
| 1131 i = IMAGPART (a); | 1258 i = IMAGPART (a); |
| 1132 COMPLEX_ASSIGN (v, sinhf (r) * cosf (i), coshf (r) * sinf (i)); | 1259 COMPLEX_ASSIGN (v, sinhf (r) * cosf (i), coshf (r) * sinf (i)); |
| 1133 return v; | 1260 return v; |
| 1134 } | 1261 } |
| 1135 #endif | 1262 #endif |
| 1136 | 1263 |
| 1137 #if !defined(HAVE_CSINH) | 1264 #if !defined(HAVE_CSINH) |
| 1138 #define HAVE_CSINH 1 | 1265 #define HAVE_CSINH 1 |
| 1266 double complex csinh (double complex a); |
| 1267 |
| 1139 double complex | 1268 double complex |
| 1140 csinh (double complex a) | 1269 csinh (double complex a) |
| 1141 { | 1270 { |
| 1142 double r, i; | 1271 double r, i; |
| 1143 double complex v; | 1272 double complex v; |
| 1144 | 1273 |
| 1145 r = REALPART (a); | 1274 r = REALPART (a); |
| 1146 i = IMAGPART (a); | 1275 i = IMAGPART (a); |
| 1147 COMPLEX_ASSIGN (v, sinh (r) * cos (i), cosh (r) * sin (i)); | 1276 COMPLEX_ASSIGN (v, sinh (r) * cos (i), cosh (r) * sin (i)); |
| 1148 return v; | 1277 return v; |
| 1149 } | 1278 } |
| 1150 #endif | 1279 #endif |
| 1151 | 1280 |
| 1152 #if !defined(HAVE_CSINHL) && defined(HAVE_COSL) && defined(HAVE_COSHL) && define
d(HAVE_SINL) && defined(HAVE_SINHL) | 1281 #if !defined(HAVE_CSINHL) && defined(HAVE_COSL) && defined(HAVE_COSHL) && define
d(HAVE_SINL) && defined(HAVE_SINHL) |
| 1153 #define HAVE_CSINHL 1 | 1282 #define HAVE_CSINHL 1 |
| 1283 long double complex csinhl (long double complex a); |
| 1284 |
| 1154 long double complex | 1285 long double complex |
| 1155 csinhl (long double complex a) | 1286 csinhl (long double complex a) |
| 1156 { | 1287 { |
| 1157 long double r, i; | 1288 long double r, i; |
| 1158 long double complex v; | 1289 long double complex v; |
| 1159 | 1290 |
| 1160 r = REALPART (a); | 1291 r = REALPART (a); |
| 1161 i = IMAGPART (a); | 1292 i = IMAGPART (a); |
| 1162 COMPLEX_ASSIGN (v, sinhl (r) * cosl (i), coshl (r) * sinl (i)); | 1293 COMPLEX_ASSIGN (v, sinhl (r) * cosl (i), coshl (r) * sinl (i)); |
| 1163 return v; | 1294 return v; |
| 1164 } | 1295 } |
| 1165 #endif | 1296 #endif |
| 1166 | 1297 |
| 1167 | 1298 |
| 1168 /* cosh(a + i b) = cosh(a) cos(b) - i sinh(a) sin(b) */ | 1299 /* cosh(a + i b) = cosh(a) cos(b) + i sinh(a) sin(b) */ |
| 1169 #if !defined(HAVE_CCOSHF) | 1300 #if !defined(HAVE_CCOSHF) |
| 1170 #define HAVE_CCOSHF 1 | 1301 #define HAVE_CCOSHF 1 |
| 1302 float complex ccoshf (float complex a); |
| 1303 |
| 1171 float complex | 1304 float complex |
| 1172 ccoshf (float complex a) | 1305 ccoshf (float complex a) |
| 1173 { | 1306 { |
| 1174 float r, i; | 1307 float r, i; |
| 1175 float complex v; | 1308 float complex v; |
| 1176 | 1309 |
| 1177 r = REALPART (a); | 1310 r = REALPART (a); |
| 1178 i = IMAGPART (a); | 1311 i = IMAGPART (a); |
| 1179 COMPLEX_ASSIGN (v, coshf (r) * cosf (i), - (sinhf (r) * sinf (i))); | 1312 COMPLEX_ASSIGN (v, coshf (r) * cosf (i), sinhf (r) * sinf (i)); |
| 1180 return v; | 1313 return v; |
| 1181 } | 1314 } |
| 1182 #endif | 1315 #endif |
| 1183 | 1316 |
| 1184 #if !defined(HAVE_CCOSH) | 1317 #if !defined(HAVE_CCOSH) |
| 1185 #define HAVE_CCOSH 1 | 1318 #define HAVE_CCOSH 1 |
| 1319 double complex ccosh (double complex a); |
| 1320 |
| 1186 double complex | 1321 double complex |
| 1187 ccosh (double complex a) | 1322 ccosh (double complex a) |
| 1188 { | 1323 { |
| 1189 double r, i; | 1324 double r, i; |
| 1190 double complex v; | 1325 double complex v; |
| 1191 | 1326 |
| 1192 r = REALPART (a); | 1327 r = REALPART (a); |
| 1193 i = IMAGPART (a); | 1328 i = IMAGPART (a); |
| 1194 COMPLEX_ASSIGN (v, cosh (r) * cos (i), - (sinh (r) * sin (i))); | 1329 COMPLEX_ASSIGN (v, cosh (r) * cos (i), sinh (r) * sin (i)); |
| 1195 return v; | 1330 return v; |
| 1196 } | 1331 } |
| 1197 #endif | 1332 #endif |
| 1198 | 1333 |
| 1199 #if !defined(HAVE_CCOSHL) && defined(HAVE_COSL) && defined(HAVE_COSHL) && define
d(HAVE_SINL) && defined(HAVE_SINHL) | 1334 #if !defined(HAVE_CCOSHL) && defined(HAVE_COSL) && defined(HAVE_COSHL) && define
d(HAVE_SINL) && defined(HAVE_SINHL) |
| 1200 #define HAVE_CCOSHL 1 | 1335 #define HAVE_CCOSHL 1 |
| 1336 long double complex ccoshl (long double complex a); |
| 1337 |
| 1201 long double complex | 1338 long double complex |
| 1202 ccoshl (long double complex a) | 1339 ccoshl (long double complex a) |
| 1203 { | 1340 { |
| 1204 long double r, i; | 1341 long double r, i; |
| 1205 long double complex v; | 1342 long double complex v; |
| 1206 | 1343 |
| 1207 r = REALPART (a); | 1344 r = REALPART (a); |
| 1208 i = IMAGPART (a); | 1345 i = IMAGPART (a); |
| 1209 COMPLEX_ASSIGN (v, coshl (r) * cosl (i), - (sinhl (r) * sinl (i))); | 1346 COMPLEX_ASSIGN (v, coshl (r) * cosl (i), sinhl (r) * sinl (i)); |
| 1210 return v; | 1347 return v; |
| 1211 } | 1348 } |
| 1212 #endif | 1349 #endif |
| 1213 | 1350 |
| 1214 | 1351 |
| 1215 /* tanh(a + i b) = (tanh(a) + i tan(b)) / (1 - i tanh(a) tan(b)) */ | 1352 /* tanh(a + i b) = (tanh(a) + i tan(b)) / (1 + i tanh(a) tan(b)) */ |
| 1216 #if !defined(HAVE_CTANHF) | 1353 #if !defined(HAVE_CTANHF) |
| 1217 #define HAVE_CTANHF 1 | 1354 #define HAVE_CTANHF 1 |
| 1355 float complex ctanhf (float complex a); |
| 1356 |
| 1218 float complex | 1357 float complex |
| 1219 ctanhf (float complex a) | 1358 ctanhf (float complex a) |
| 1220 { | 1359 { |
| 1221 float rt, it; | 1360 float rt, it; |
| 1222 float complex n, d; | 1361 float complex n, d; |
| 1223 | 1362 |
| 1224 rt = tanhf (REALPART (a)); | 1363 rt = tanhf (REALPART (a)); |
| 1225 it = tanf (IMAGPART (a)); | 1364 it = tanf (IMAGPART (a)); |
| 1226 COMPLEX_ASSIGN (n, rt, it); | 1365 COMPLEX_ASSIGN (n, rt, it); |
| 1227 COMPLEX_ASSIGN (d, 1, - (rt * it)); | 1366 COMPLEX_ASSIGN (d, 1, rt * it); |
| 1228 | 1367 |
| 1229 return n / d; | 1368 return n / d; |
| 1230 } | 1369 } |
| 1231 #endif | 1370 #endif |
| 1232 | 1371 |
| 1233 #if !defined(HAVE_CTANH) | 1372 #if !defined(HAVE_CTANH) |
| 1234 #define HAVE_CTANH 1 | 1373 #define HAVE_CTANH 1 |
| 1374 double complex ctanh (double complex a); |
| 1235 double complex | 1375 double complex |
| 1236 ctanh (double complex a) | 1376 ctanh (double complex a) |
| 1237 { | 1377 { |
| 1238 double rt, it; | 1378 double rt, it; |
| 1239 double complex n, d; | 1379 double complex n, d; |
| 1240 | 1380 |
| 1241 rt = tanh (REALPART (a)); | 1381 rt = tanh (REALPART (a)); |
| 1242 it = tan (IMAGPART (a)); | 1382 it = tan (IMAGPART (a)); |
| 1243 COMPLEX_ASSIGN (n, rt, it); | 1383 COMPLEX_ASSIGN (n, rt, it); |
| 1244 COMPLEX_ASSIGN (d, 1, - (rt * it)); | 1384 COMPLEX_ASSIGN (d, 1, rt * it); |
| 1245 | 1385 |
| 1246 return n / d; | 1386 return n / d; |
| 1247 } | 1387 } |
| 1248 #endif | 1388 #endif |
| 1249 | 1389 |
| 1250 #if !defined(HAVE_CTANHL) && defined(HAVE_TANL) && defined(HAVE_TANHL) | 1390 #if !defined(HAVE_CTANHL) && defined(HAVE_TANL) && defined(HAVE_TANHL) |
| 1251 #define HAVE_CTANHL 1 | 1391 #define HAVE_CTANHL 1 |
| 1392 long double complex ctanhl (long double complex a); |
| 1393 |
| 1252 long double complex | 1394 long double complex |
| 1253 ctanhl (long double complex a) | 1395 ctanhl (long double complex a) |
| 1254 { | 1396 { |
| 1255 long double rt, it; | 1397 long double rt, it; |
| 1256 long double complex n, d; | 1398 long double complex n, d; |
| 1257 | 1399 |
| 1258 rt = tanhl (REALPART (a)); | 1400 rt = tanhl (REALPART (a)); |
| 1259 it = tanl (IMAGPART (a)); | 1401 it = tanl (IMAGPART (a)); |
| 1260 COMPLEX_ASSIGN (n, rt, it); | 1402 COMPLEX_ASSIGN (n, rt, it); |
| 1261 COMPLEX_ASSIGN (d, 1, - (rt * it)); | 1403 COMPLEX_ASSIGN (d, 1, rt * it); |
| 1262 | 1404 |
| 1263 return n / d; | 1405 return n / d; |
| 1264 } | 1406 } |
| 1265 #endif | 1407 #endif |
| 1266 | 1408 |
| 1267 | 1409 |
| 1268 /* sin(a + i b) = sin(a) cosh(b) + i cos(a) sinh(b) */ | 1410 /* sin(a + i b) = sin(a) cosh(b) + i cos(a) sinh(b) */ |
| 1269 #if !defined(HAVE_CSINF) | 1411 #if !defined(HAVE_CSINF) |
| 1270 #define HAVE_CSINF 1 | 1412 #define HAVE_CSINF 1 |
| 1413 float complex csinf (float complex a); |
| 1414 |
| 1271 float complex | 1415 float complex |
| 1272 csinf (float complex a) | 1416 csinf (float complex a) |
| 1273 { | 1417 { |
| 1274 float r, i; | 1418 float r, i; |
| 1275 float complex v; | 1419 float complex v; |
| 1276 | 1420 |
| 1277 r = REALPART (a); | 1421 r = REALPART (a); |
| 1278 i = IMAGPART (a); | 1422 i = IMAGPART (a); |
| 1279 COMPLEX_ASSIGN (v, sinf (r) * coshf (i), cosf (r) * sinhf (i)); | 1423 COMPLEX_ASSIGN (v, sinf (r) * coshf (i), cosf (r) * sinhf (i)); |
| 1280 return v; | 1424 return v; |
| 1281 } | 1425 } |
| 1282 #endif | 1426 #endif |
| 1283 | 1427 |
| 1284 #if !defined(HAVE_CSIN) | 1428 #if !defined(HAVE_CSIN) |
| 1285 #define HAVE_CSIN 1 | 1429 #define HAVE_CSIN 1 |
| 1430 double complex csin (double complex a); |
| 1431 |
| 1286 double complex | 1432 double complex |
| 1287 csin (double complex a) | 1433 csin (double complex a) |
| 1288 { | 1434 { |
| 1289 double r, i; | 1435 double r, i; |
| 1290 double complex v; | 1436 double complex v; |
| 1291 | 1437 |
| 1292 r = REALPART (a); | 1438 r = REALPART (a); |
| 1293 i = IMAGPART (a); | 1439 i = IMAGPART (a); |
| 1294 COMPLEX_ASSIGN (v, sin (r) * cosh (i), cos (r) * sinh (i)); | 1440 COMPLEX_ASSIGN (v, sin (r) * cosh (i), cos (r) * sinh (i)); |
| 1295 return v; | 1441 return v; |
| 1296 } | 1442 } |
| 1297 #endif | 1443 #endif |
| 1298 | 1444 |
| 1299 #if !defined(HAVE_CSINL) && defined(HAVE_COSL) && defined(HAVE_COSHL) && defined
(HAVE_SINL) && defined(HAVE_SINHL) | 1445 #if !defined(HAVE_CSINL) && defined(HAVE_COSL) && defined(HAVE_COSHL) && defined
(HAVE_SINL) && defined(HAVE_SINHL) |
| 1300 #define HAVE_CSINL 1 | 1446 #define HAVE_CSINL 1 |
| 1447 long double complex csinl (long double complex a); |
| 1448 |
| 1301 long double complex | 1449 long double complex |
| 1302 csinl (long double complex a) | 1450 csinl (long double complex a) |
| 1303 { | 1451 { |
| 1304 long double r, i; | 1452 long double r, i; |
| 1305 long double complex v; | 1453 long double complex v; |
| 1306 | 1454 |
| 1307 r = REALPART (a); | 1455 r = REALPART (a); |
| 1308 i = IMAGPART (a); | 1456 i = IMAGPART (a); |
| 1309 COMPLEX_ASSIGN (v, sinl (r) * coshl (i), cosl (r) * sinhl (i)); | 1457 COMPLEX_ASSIGN (v, sinl (r) * coshl (i), cosl (r) * sinhl (i)); |
| 1310 return v; | 1458 return v; |
| 1311 } | 1459 } |
| 1312 #endif | 1460 #endif |
| 1313 | 1461 |
| 1314 | 1462 |
| 1315 /* cos(a + i b) = cos(a) cosh(b) - i sin(a) sinh(b) */ | 1463 /* cos(a + i b) = cos(a) cosh(b) - i sin(a) sinh(b) */ |
| 1316 #if !defined(HAVE_CCOSF) | 1464 #if !defined(HAVE_CCOSF) |
| 1317 #define HAVE_CCOSF 1 | 1465 #define HAVE_CCOSF 1 |
| 1466 float complex ccosf (float complex a); |
| 1467 |
| 1318 float complex | 1468 float complex |
| 1319 ccosf (float complex a) | 1469 ccosf (float complex a) |
| 1320 { | 1470 { |
| 1321 float r, i; | 1471 float r, i; |
| 1322 float complex v; | 1472 float complex v; |
| 1323 | 1473 |
| 1324 r = REALPART (a); | 1474 r = REALPART (a); |
| 1325 i = IMAGPART (a); | 1475 i = IMAGPART (a); |
| 1326 COMPLEX_ASSIGN (v, cosf (r) * coshf (i), - (sinf (r) * sinhf (i))); | 1476 COMPLEX_ASSIGN (v, cosf (r) * coshf (i), - (sinf (r) * sinhf (i))); |
| 1327 return v; | 1477 return v; |
| 1328 } | 1478 } |
| 1329 #endif | 1479 #endif |
| 1330 | 1480 |
| 1331 #if !defined(HAVE_CCOS) | 1481 #if !defined(HAVE_CCOS) |
| 1332 #define HAVE_CCOS 1 | 1482 #define HAVE_CCOS 1 |
| 1483 double complex ccos (double complex a); |
| 1484 |
| 1333 double complex | 1485 double complex |
| 1334 ccos (double complex a) | 1486 ccos (double complex a) |
| 1335 { | 1487 { |
| 1336 double r, i; | 1488 double r, i; |
| 1337 double complex v; | 1489 double complex v; |
| 1338 | 1490 |
| 1339 r = REALPART (a); | 1491 r = REALPART (a); |
| 1340 i = IMAGPART (a); | 1492 i = IMAGPART (a); |
| 1341 COMPLEX_ASSIGN (v, cos (r) * cosh (i), - (sin (r) * sinh (i))); | 1493 COMPLEX_ASSIGN (v, cos (r) * cosh (i), - (sin (r) * sinh (i))); |
| 1342 return v; | 1494 return v; |
| 1343 } | 1495 } |
| 1344 #endif | 1496 #endif |
| 1345 | 1497 |
| 1346 #if !defined(HAVE_CCOSL) && defined(HAVE_COSL) && defined(HAVE_COSHL) && defined
(HAVE_SINL) && defined(HAVE_SINHL) | 1498 #if !defined(HAVE_CCOSL) && defined(HAVE_COSL) && defined(HAVE_COSHL) && defined
(HAVE_SINL) && defined(HAVE_SINHL) |
| 1347 #define HAVE_CCOSL 1 | 1499 #define HAVE_CCOSL 1 |
| 1500 long double complex ccosl (long double complex a); |
| 1501 |
| 1348 long double complex | 1502 long double complex |
| 1349 ccosl (long double complex a) | 1503 ccosl (long double complex a) |
| 1350 { | 1504 { |
| 1351 long double r, i; | 1505 long double r, i; |
| 1352 long double complex v; | 1506 long double complex v; |
| 1353 | 1507 |
| 1354 r = REALPART (a); | 1508 r = REALPART (a); |
| 1355 i = IMAGPART (a); | 1509 i = IMAGPART (a); |
| 1356 COMPLEX_ASSIGN (v, cosl (r) * coshl (i), - (sinl (r) * sinhl (i))); | 1510 COMPLEX_ASSIGN (v, cosl (r) * coshl (i), - (sinl (r) * sinhl (i))); |
| 1357 return v; | 1511 return v; |
| 1358 } | 1512 } |
| 1359 #endif | 1513 #endif |
| 1360 | 1514 |
| 1361 | 1515 |
| 1362 /* tan(a + i b) = (tan(a) + i tanh(b)) / (1 - i tan(a) tanh(b)) */ | 1516 /* tan(a + i b) = (tan(a) + i tanh(b)) / (1 - i tan(a) tanh(b)) */ |
| 1363 #if !defined(HAVE_CTANF) | 1517 #if !defined(HAVE_CTANF) |
| 1364 #define HAVE_CTANF 1 | 1518 #define HAVE_CTANF 1 |
| 1519 float complex ctanf (float complex a); |
| 1520 |
| 1365 float complex | 1521 float complex |
| 1366 ctanf (float complex a) | 1522 ctanf (float complex a) |
| 1367 { | 1523 { |
| 1368 float rt, it; | 1524 float rt, it; |
| 1369 float complex n, d; | 1525 float complex n, d; |
| 1370 | 1526 |
| 1371 rt = tanf (REALPART (a)); | 1527 rt = tanf (REALPART (a)); |
| 1372 it = tanhf (IMAGPART (a)); | 1528 it = tanhf (IMAGPART (a)); |
| 1373 COMPLEX_ASSIGN (n, rt, it); | 1529 COMPLEX_ASSIGN (n, rt, it); |
| 1374 COMPLEX_ASSIGN (d, 1, - (rt * it)); | 1530 COMPLEX_ASSIGN (d, 1, - (rt * it)); |
| 1375 | 1531 |
| 1376 return n / d; | 1532 return n / d; |
| 1377 } | 1533 } |
| 1378 #endif | 1534 #endif |
| 1379 | 1535 |
| 1380 #if !defined(HAVE_CTAN) | 1536 #if !defined(HAVE_CTAN) |
| 1381 #define HAVE_CTAN 1 | 1537 #define HAVE_CTAN 1 |
| 1538 double complex ctan (double complex a); |
| 1539 |
| 1382 double complex | 1540 double complex |
| 1383 ctan (double complex a) | 1541 ctan (double complex a) |
| 1384 { | 1542 { |
| 1385 double rt, it; | 1543 double rt, it; |
| 1386 double complex n, d; | 1544 double complex n, d; |
| 1387 | 1545 |
| 1388 rt = tan (REALPART (a)); | 1546 rt = tan (REALPART (a)); |
| 1389 it = tanh (IMAGPART (a)); | 1547 it = tanh (IMAGPART (a)); |
| 1390 COMPLEX_ASSIGN (n, rt, it); | 1548 COMPLEX_ASSIGN (n, rt, it); |
| 1391 COMPLEX_ASSIGN (d, 1, - (rt * it)); | 1549 COMPLEX_ASSIGN (d, 1, - (rt * it)); |
| 1392 | 1550 |
| 1393 return n / d; | 1551 return n / d; |
| 1394 } | 1552 } |
| 1395 #endif | 1553 #endif |
| 1396 | 1554 |
| 1397 #if !defined(HAVE_CTANL) && defined(HAVE_TANL) && defined(HAVE_TANHL) | 1555 #if !defined(HAVE_CTANL) && defined(HAVE_TANL) && defined(HAVE_TANHL) |
| 1398 #define HAVE_CTANL 1 | 1556 #define HAVE_CTANL 1 |
| 1557 long double complex ctanl (long double complex a); |
| 1558 |
| 1399 long double complex | 1559 long double complex |
| 1400 ctanl (long double complex a) | 1560 ctanl (long double complex a) |
| 1401 { | 1561 { |
| 1402 long double rt, it; | 1562 long double rt, it; |
| 1403 long double complex n, d; | 1563 long double complex n, d; |
| 1404 | 1564 |
| 1405 rt = tanl (REALPART (a)); | 1565 rt = tanl (REALPART (a)); |
| 1406 it = tanhl (IMAGPART (a)); | 1566 it = tanhl (IMAGPART (a)); |
| 1407 COMPLEX_ASSIGN (n, rt, it); | 1567 COMPLEX_ASSIGN (n, rt, it); |
| 1408 COMPLEX_ASSIGN (d, 1, - (rt * it)); | 1568 COMPLEX_ASSIGN (d, 1, - (rt * it)); |
| 1409 | 1569 |
| 1410 return n / d; | 1570 return n / d; |
| 1411 } | 1571 } |
| 1412 #endif | 1572 #endif |
| 1413 | 1573 |
| 1414 | 1574 |
| 1575 /* Complex ASIN. Returns wrongly NaN for infinite arguments. |
| 1576 Algorithm taken from Abramowitz & Stegun. */ |
| 1577 |
| 1578 #if !defined(HAVE_CASINF) && defined(HAVE_CLOGF) && defined(HAVE_CSQRTF) |
| 1579 #define HAVE_CASINF 1 |
| 1580 complex float casinf (complex float z); |
| 1581 |
| 1582 complex float |
| 1583 casinf (complex float z) |
| 1584 { |
| 1585 return -I*clogf (I*z + csqrtf (1.0f-z*z)); |
| 1586 } |
| 1587 #endif |
| 1588 |
| 1589 |
| 1590 #if !defined(HAVE_CASIN) && defined(HAVE_CLOG) && defined(HAVE_CSQRT) |
| 1591 #define HAVE_CASIN 1 |
| 1592 complex double casin (complex double z); |
| 1593 |
| 1594 complex double |
| 1595 casin (complex double z) |
| 1596 { |
| 1597 return -I*clog (I*z + csqrt (1.0-z*z)); |
| 1598 } |
| 1599 #endif |
| 1600 |
| 1601 |
| 1602 #if !defined(HAVE_CASINL) && defined(HAVE_CLOGL) && defined(HAVE_CSQRTL) |
| 1603 #define HAVE_CASINL 1 |
| 1604 complex long double casinl (complex long double z); |
| 1605 |
| 1606 complex long double |
| 1607 casinl (complex long double z) |
| 1608 { |
| 1609 return -I*clogl (I*z + csqrtl (1.0L-z*z)); |
| 1610 } |
| 1611 #endif |
| 1612 |
| 1613 |
| 1614 /* Complex ACOS. Returns wrongly NaN for infinite arguments. |
| 1615 Algorithm taken from Abramowitz & Stegun. */ |
| 1616 |
| 1617 #if !defined(HAVE_CACOSF) && defined(HAVE_CLOGF) && defined(HAVE_CSQRTF) |
| 1618 #define HAVE_CACOSF 1 |
| 1619 complex float cacosf (complex float z); |
| 1620 |
| 1621 complex float |
| 1622 cacosf (complex float z) |
| 1623 { |
| 1624 return -I*clogf (z + I*csqrtf (1.0f-z*z)); |
| 1625 } |
| 1626 #endif |
| 1627 |
| 1628 |
| 1629 #if !defined(HAVE_CACOS) && defined(HAVE_CLOG) && defined(HAVE_CSQRT) |
| 1630 #define HAVE_CACOS 1 |
| 1631 complex double cacos (complex double z); |
| 1632 |
| 1633 complex double |
| 1634 cacos (complex double z) |
| 1635 { |
| 1636 return -I*clog (z + I*csqrt (1.0-z*z)); |
| 1637 } |
| 1638 #endif |
| 1639 |
| 1640 |
| 1641 #if !defined(HAVE_CACOSL) && defined(HAVE_CLOGL) && defined(HAVE_CSQRTL) |
| 1642 #define HAVE_CACOSL 1 |
| 1643 complex long double cacosl (complex long double z); |
| 1644 |
| 1645 complex long double |
| 1646 cacosl (complex long double z) |
| 1647 { |
| 1648 return -I*clogl (z + I*csqrtl (1.0L-z*z)); |
| 1649 } |
| 1650 #endif |
| 1651 |
| 1652 |
| 1653 /* Complex ATAN. Returns wrongly NaN for infinite arguments. |
| 1654 Algorithm taken from Abramowitz & Stegun. */ |
| 1655 |
| 1656 #if !defined(HAVE_CATANF) && defined(HAVE_CLOGF) |
| 1657 #define HAVE_CACOSF 1 |
| 1658 complex float catanf (complex float z); |
| 1659 |
| 1660 complex float |
| 1661 catanf (complex float z) |
| 1662 { |
| 1663 return I*clogf ((I+z)/(I-z))/2.0f; |
| 1664 } |
| 1665 #endif |
| 1666 |
| 1667 |
| 1668 #if !defined(HAVE_CATAN) && defined(HAVE_CLOG) |
| 1669 #define HAVE_CACOS 1 |
| 1670 complex double catan (complex double z); |
| 1671 |
| 1672 complex double |
| 1673 catan (complex double z) |
| 1674 { |
| 1675 return I*clog ((I+z)/(I-z))/2.0; |
| 1676 } |
| 1677 #endif |
| 1678 |
| 1679 |
| 1680 #if !defined(HAVE_CATANL) && defined(HAVE_CLOGL) |
| 1681 #define HAVE_CACOSL 1 |
| 1682 complex long double catanl (complex long double z); |
| 1683 |
| 1684 complex long double |
| 1685 catanl (complex long double z) |
| 1686 { |
| 1687 return I*clogl ((I+z)/(I-z))/2.0L; |
| 1688 } |
| 1689 #endif |
| 1690 |
| 1691 |
| 1692 /* Complex ASINH. Returns wrongly NaN for infinite arguments. |
| 1693 Algorithm taken from Abramowitz & Stegun. */ |
| 1694 |
| 1695 #if !defined(HAVE_CASINHF) && defined(HAVE_CLOGF) && defined(HAVE_CSQRTF) |
| 1696 #define HAVE_CASINHF 1 |
| 1697 complex float casinhf (complex float z); |
| 1698 |
| 1699 complex float |
| 1700 casinhf (complex float z) |
| 1701 { |
| 1702 return clogf (z + csqrtf (z*z+1.0f)); |
| 1703 } |
| 1704 #endif |
| 1705 |
| 1706 |
| 1707 #if !defined(HAVE_CASINH) && defined(HAVE_CLOG) && defined(HAVE_CSQRT) |
| 1708 #define HAVE_CASINH 1 |
| 1709 complex double casinh (complex double z); |
| 1710 |
| 1711 complex double |
| 1712 casinh (complex double z) |
| 1713 { |
| 1714 return clog (z + csqrt (z*z+1.0)); |
| 1715 } |
| 1716 #endif |
| 1717 |
| 1718 |
| 1719 #if !defined(HAVE_CASINHL) && defined(HAVE_CLOGL) && defined(HAVE_CSQRTL) |
| 1720 #define HAVE_CASINHL 1 |
| 1721 complex long double casinhl (complex long double z); |
| 1722 |
| 1723 complex long double |
| 1724 casinhl (complex long double z) |
| 1725 { |
| 1726 return clogl (z + csqrtl (z*z+1.0L)); |
| 1727 } |
| 1728 #endif |
| 1729 |
| 1730 |
| 1731 /* Complex ACOSH. Returns wrongly NaN for infinite arguments. |
| 1732 Algorithm taken from Abramowitz & Stegun. */ |
| 1733 |
| 1734 #if !defined(HAVE_CACOSHF) && defined(HAVE_CLOGF) && defined(HAVE_CSQRTF) |
| 1735 #define HAVE_CACOSHF 1 |
| 1736 complex float cacoshf (complex float z); |
| 1737 |
| 1738 complex float |
| 1739 cacoshf (complex float z) |
| 1740 { |
| 1741 return clogf (z + csqrtf (z-1.0f) * csqrtf (z+1.0f)); |
| 1742 } |
| 1743 #endif |
| 1744 |
| 1745 |
| 1746 #if !defined(HAVE_CACOSH) && defined(HAVE_CLOG) && defined(HAVE_CSQRT) |
| 1747 #define HAVE_CACOSH 1 |
| 1748 complex double cacosh (complex double z); |
| 1749 |
| 1750 complex double |
| 1751 cacosh (complex double z) |
| 1752 { |
| 1753 return clog (z + csqrt (z-1.0) * csqrt (z+1.0)); |
| 1754 } |
| 1755 #endif |
| 1756 |
| 1757 |
| 1758 #if !defined(HAVE_CACOSHL) && defined(HAVE_CLOGL) && defined(HAVE_CSQRTL) |
| 1759 #define HAVE_CACOSHL 1 |
| 1760 complex long double cacoshl (complex long double z); |
| 1761 |
| 1762 complex long double |
| 1763 cacoshl (complex long double z) |
| 1764 { |
| 1765 return clogl (z + csqrtl (z-1.0L) * csqrtl (z+1.0L)); |
| 1766 } |
| 1767 #endif |
| 1768 |
| 1769 |
| 1770 /* Complex ATANH. Returns wrongly NaN for infinite arguments. |
| 1771 Algorithm taken from Abramowitz & Stegun. */ |
| 1772 |
| 1773 #if !defined(HAVE_CATANHF) && defined(HAVE_CLOGF) |
| 1774 #define HAVE_CATANHF 1 |
| 1775 complex float catanhf (complex float z); |
| 1776 |
| 1777 complex float |
| 1778 catanhf (complex float z) |
| 1779 { |
| 1780 return clogf ((1.0f+z)/(1.0f-z))/2.0f; |
| 1781 } |
| 1782 #endif |
| 1783 |
| 1784 |
| 1785 #if !defined(HAVE_CATANH) && defined(HAVE_CLOG) |
| 1786 #define HAVE_CATANH 1 |
| 1787 complex double catanh (complex double z); |
| 1788 |
| 1789 complex double |
| 1790 catanh (complex double z) |
| 1791 { |
| 1792 return clog ((1.0+z)/(1.0-z))/2.0; |
| 1793 } |
| 1794 #endif |
| 1795 |
| 1796 #if !defined(HAVE_CATANHL) && defined(HAVE_CLOGL) |
| 1797 #define HAVE_CATANHL 1 |
| 1798 complex long double catanhl (complex long double z); |
| 1799 |
| 1800 complex long double |
| 1801 catanhl (complex long double z) |
| 1802 { |
| 1803 return clogl ((1.0L+z)/(1.0L-z))/2.0L; |
| 1804 } |
| 1805 #endif |
| 1806 |
| 1807 |
| 1415 #if !defined(HAVE_TGAMMA) | 1808 #if !defined(HAVE_TGAMMA) |
| 1416 #define HAVE_TGAMMA 1 | 1809 #define HAVE_TGAMMA 1 |
| 1417 | 1810 double tgamma (double); |
| 1418 extern double tgamma (double); | |
| 1419 | 1811 |
| 1420 /* Fallback tgamma() function. Uses the algorithm from | 1812 /* Fallback tgamma() function. Uses the algorithm from |
| 1421 http://www.netlib.org/specfun/gamma and references therein. */ | 1813 http://www.netlib.org/specfun/gamma and references therein. */ |
| 1422 | 1814 |
| 1423 #undef SQRTPI | 1815 #undef SQRTPI |
| 1424 #define SQRTPI 0.9189385332046727417803297 | 1816 #define SQRTPI 0.9189385332046727417803297 |
| 1425 | 1817 |
| 1426 #undef PI | 1818 #undef PI |
| 1427 #define PI 3.1415926535897932384626434 | 1819 #define PI 3.1415926535897932384626434 |
| 1428 | 1820 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1448 8.4171387781295e-04, -5.952379913043012e-04, | 1840 8.4171387781295e-04, -5.952379913043012e-04, |
| 1449 7.93650793500350248e-04, -2.777777777777681622553e-03, | 1841 7.93650793500350248e-04, -2.777777777777681622553e-03, |
| 1450 8.333333333333333331554247e-02, 5.7083835261e-03 }; | 1842 8.333333333333333331554247e-02, 5.7083835261e-03 }; |
| 1451 | 1843 |
| 1452 static const double xminin = 2.23e-308; | 1844 static const double xminin = 2.23e-308; |
| 1453 static const double xbig = 171.624; | 1845 static const double xbig = 171.624; |
| 1454 static const double xnan = __builtin_nan ("0x0"), xinf = __builtin_inf (); | 1846 static const double xnan = __builtin_nan ("0x0"), xinf = __builtin_inf (); |
| 1455 static double eps = 0; | 1847 static double eps = 0; |
| 1456 | 1848 |
| 1457 if (eps == 0) | 1849 if (eps == 0) |
| 1458 eps = nextafter(1., 2.) - 1.; | 1850 eps = nextafter (1., 2.) - 1.; |
| 1459 | 1851 |
| 1460 parity = 0; | 1852 parity = 0; |
| 1461 fact = 1; | 1853 fact = 1; |
| 1462 n = 0; | 1854 n = 0; |
| 1463 y = x; | 1855 y = x; |
| 1464 | 1856 |
| 1465 if (__builtin_isnan (x)) | 1857 if (__builtin_isnan (x)) |
| 1466 return x; | 1858 return x; |
| 1467 | 1859 |
| 1468 if (y <= 0) | 1860 if (y <= 0) |
| 1469 { | 1861 { |
| 1470 y = -x; | 1862 y = -x; |
| 1471 y1 = trunc(y); | 1863 y1 = trunc (y); |
| 1472 res = y - y1; | 1864 res = y - y1; |
| 1473 | 1865 |
| 1474 if (res != 0) | 1866 if (res != 0) |
| 1475 { | 1867 { |
| 1476 » if (y1 != trunc(y1*0.5l)*2) | 1868 » if (y1 != trunc (y1*0.5l)*2) |
| 1477 parity = 1; | 1869 parity = 1; |
| 1478 » fact = -PI / sin(PI*res); | 1870 » fact = -PI / sin (PI*res); |
| 1479 y = y + 1; | 1871 y = y + 1; |
| 1480 } | 1872 } |
| 1481 else | 1873 else |
| 1482 return x == 0 ? copysign (xinf, x) : xnan; | 1874 return x == 0 ? copysign (xinf, x) : xnan; |
| 1483 } | 1875 } |
| 1484 | 1876 |
| 1485 if (y < eps) | 1877 if (y < eps) |
| 1486 { | 1878 { |
| 1487 if (y >= xminin) | 1879 if (y >= xminin) |
| 1488 res = 1 / y; | 1880 res = 1 / y; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1526 else | 1918 else |
| 1527 { | 1919 { |
| 1528 if (y < xbig) | 1920 if (y < xbig) |
| 1529 { | 1921 { |
| 1530 ysq = y * y; | 1922 ysq = y * y; |
| 1531 sum = c[6]; | 1923 sum = c[6]; |
| 1532 for (i = 0; i < 6; i++) | 1924 for (i = 0; i < 6; i++) |
| 1533 sum = sum / ysq + c[i]; | 1925 sum = sum / ysq + c[i]; |
| 1534 | 1926 |
| 1535 sum = sum/y - y + SQRTPI; | 1927 sum = sum/y - y + SQRTPI; |
| 1536 » sum = sum + (y - 0.5) * log(y); | 1928 » sum = sum + (y - 0.5) * log (y); |
| 1537 » res = exp(sum); | 1929 » res = exp (sum); |
| 1538 } | 1930 } |
| 1539 else | 1931 else |
| 1540 return x < 0 ? xnan : xinf; | 1932 return x < 0 ? xnan : xinf; |
| 1541 } | 1933 } |
| 1542 | 1934 |
| 1543 if (parity) | 1935 if (parity) |
| 1544 res = -res; | 1936 res = -res; |
| 1545 if (fact != 1) | 1937 if (fact != 1) |
| 1546 res = fact / res; | 1938 res = fact / res; |
| 1547 | 1939 |
| 1548 return res; | 1940 return res; |
| 1549 } | 1941 } |
| 1550 #endif | 1942 #endif |
| 1551 | 1943 |
| 1552 | 1944 |
| 1553 | 1945 |
| 1554 #if !defined(HAVE_LGAMMA) | 1946 #if !defined(HAVE_LGAMMA) |
| 1555 #define HAVE_LGAMMA 1 | 1947 #define HAVE_LGAMMA 1 |
| 1556 | 1948 double lgamma (double); |
| 1557 extern double lgamma (double); | |
| 1558 | 1949 |
| 1559 /* Fallback lgamma() function. Uses the algorithm from | 1950 /* Fallback lgamma() function. Uses the algorithm from |
| 1560 http://www.netlib.org/specfun/algama and references therein, | 1951 http://www.netlib.org/specfun/algama and references therein, |
| 1561 except for negative arguments (where netlib would return +Inf) | 1952 except for negative arguments (where netlib would return +Inf) |
| 1562 where we use the following identity: | 1953 where we use the following identity: |
| 1563 lgamma(y) = log(pi/(|y*sin(pi*y)|)) - lgamma(-y) | 1954 lgamma(y) = log(pi/(|y*sin(pi*y)|)) - lgamma(-y) |
| 1564 */ | 1955 */ |
| 1565 | 1956 |
| 1566 double | 1957 double |
| 1567 lgamma (double y) | 1958 lgamma (double y) |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1614 -2.777777777777681622553e-03, 8.333333333333333331554247e-02, | 2005 -2.777777777777681622553e-03, 8.333333333333333331554247e-02, |
| 1615 5.7083835261e-03 }; | 2006 5.7083835261e-03 }; |
| 1616 | 2007 |
| 1617 static double xbig = 2.55e305, xinf = __builtin_inf (), eps = 0, | 2008 static double xbig = 2.55e305, xinf = __builtin_inf (), eps = 0, |
| 1618 frtbig = 2.25e76; | 2009 frtbig = 2.25e76; |
| 1619 | 2010 |
| 1620 int i; | 2011 int i; |
| 1621 double corr, res, xden, xm1, xm2, xm4, xnum, ysq; | 2012 double corr, res, xden, xm1, xm2, xm4, xnum, ysq; |
| 1622 | 2013 |
| 1623 if (eps == 0) | 2014 if (eps == 0) |
| 1624 eps = __builtin_nextafter(1., 2.) - 1.; | 2015 eps = __builtin_nextafter (1., 2.) - 1.; |
| 1625 | 2016 |
| 1626 if ((y > 0) && (y <= xbig)) | 2017 if ((y > 0) && (y <= xbig)) |
| 1627 { | 2018 { |
| 1628 if (y <= eps) | 2019 if (y <= eps) |
| 1629 » res = -log(y); | 2020 » res = -log (y); |
| 1630 else if (y <= 1.5) | 2021 else if (y <= 1.5) |
| 1631 { | 2022 { |
| 1632 if (y < PNT68) | 2023 if (y < PNT68) |
| 1633 { | 2024 { |
| 1634 » corr = -log(y); | 2025 » corr = -log (y); |
| 1635 xm1 = y; | 2026 xm1 = y; |
| 1636 } | 2027 } |
| 1637 else | 2028 else |
| 1638 { | 2029 { |
| 1639 corr = 0; | 2030 corr = 0; |
| 1640 xm1 = (y - 0.5) - 0.5; | 2031 xm1 = (y - 0.5) - 0.5; |
| 1641 } | 2032 } |
| 1642 | 2033 |
| 1643 if ((y <= 0.5) || (y >= PNT68)) | 2034 if ((y <= 0.5) || (y >= PNT68)) |
| 1644 { | 2035 { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1692 { | 2083 { |
| 1693 res = 0; | 2084 res = 0; |
| 1694 if (y <= frtbig) | 2085 if (y <= frtbig) |
| 1695 { | 2086 { |
| 1696 res = c[6]; | 2087 res = c[6]; |
| 1697 ysq = y * y; | 2088 ysq = y * y; |
| 1698 for (i = 0; i < 6; i++) | 2089 for (i = 0; i < 6; i++) |
| 1699 res = res / ysq + c[i]; | 2090 res = res / ysq + c[i]; |
| 1700 } | 2091 } |
| 1701 res = res/y; | 2092 res = res/y; |
| 1702 » corr = log(y); | 2093 » corr = log (y); |
| 1703 res = res + SQRTPI - 0.5*corr; | 2094 res = res + SQRTPI - 0.5*corr; |
| 1704 res = res + y*(corr-1); | 2095 res = res + y*(corr-1); |
| 1705 } | 2096 } |
| 1706 } | 2097 } |
| 1707 else if (y < 0 && __builtin_floor (y) != y) | 2098 else if (y < 0 && __builtin_floor (y) != y) |
| 1708 { | 2099 { |
| 1709 /* lgamma(y) = log(pi/(|y*sin(pi*y)|)) - lgamma(-y) | 2100 /* lgamma(y) = log(pi/(|y*sin(pi*y)|)) - lgamma(-y) |
| 1710 For abs(y) very close to zero, we use a series expansion to | 2101 For abs(y) very close to zero, we use a series expansion to |
| 1711 the first order in y to avoid overflow. */ | 2102 the first order in y to avoid overflow. */ |
| 1712 if (y > -1.e-100) | 2103 if (y > -1.e-100) |
| 1713 res = -2 * log (fabs (y)) - lgamma (-y); | 2104 res = -2 * log (fabs (y)) - lgamma (-y); |
| 1714 else | 2105 else |
| 1715 res = log (PI / fabs (y * sin (PI * y))) - lgamma (-y); | 2106 res = log (PI / fabs (y * sin (PI * y))) - lgamma (-y); |
| 1716 } | 2107 } |
| 1717 else | 2108 else |
| 1718 res = xinf; | 2109 res = xinf; |
| 1719 | 2110 |
| 1720 return res; | 2111 return res; |
| 1721 } | 2112 } |
| 1722 #endif | 2113 #endif |
| 1723 | 2114 |
| 1724 | 2115 |
| 1725 #if defined(HAVE_TGAMMA) && !defined(HAVE_TGAMMAF) | 2116 #if defined(HAVE_TGAMMA) && !defined(HAVE_TGAMMAF) |
| 1726 #define HAVE_TGAMMAF 1 | 2117 #define HAVE_TGAMMAF 1 |
| 1727 extern float tgammaf (float); | 2118 float tgammaf (float); |
| 1728 | 2119 |
| 1729 float | 2120 float |
| 1730 tgammaf (float x) | 2121 tgammaf (float x) |
| 1731 { | 2122 { |
| 1732 return (float) tgamma ((double) x); | 2123 return (float) tgamma ((double) x); |
| 1733 } | 2124 } |
| 1734 #endif | 2125 #endif |
| 1735 | 2126 |
| 1736 #if defined(HAVE_LGAMMA) && !defined(HAVE_LGAMMAF) | 2127 #if defined(HAVE_LGAMMA) && !defined(HAVE_LGAMMAF) |
| 1737 #define HAVE_LGAMMAF 1 | 2128 #define HAVE_LGAMMAF 1 |
| 1738 extern float lgammaf (float); | 2129 float lgammaf (float); |
| 1739 | 2130 |
| 1740 float | 2131 float |
| 1741 lgammaf (float x) | 2132 lgammaf (float x) |
| 1742 { | 2133 { |
| 1743 return (float) lgamma ((double) x); | 2134 return (float) lgamma ((double) x); |
| 1744 } | 2135 } |
| 1745 #endif | 2136 #endif |
| OLD | NEW |