X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=include%2Fcomplex.h;h=4d21728ea919de97592226ae7b3206016eef2974;hb=2de85a985654d2c944931267645d9a0686242dfe;hp=8ee70575cbb0761f42db9900e36f284aff570945;hpb=b69f695acedd4ce2798ef9ea28d834ceccc789bd;p=musl diff --git a/include/complex.h b/include/complex.h index 8ee70575..4d21728e 100644 --- a/include/complex.h +++ b/include/complex.h @@ -6,7 +6,11 @@ extern "C" { #endif #define complex _Complex -#define _Complex_I 1.0fi +#ifdef __GNUC__ +#define _Complex_I (__extension__ (0.0f+1.0fi)) +#else +#define _Complex_I (0.0f+1.0fi) +#endif #define I _Complex_I double complex cacos(double complex); @@ -97,6 +101,32 @@ double creal(double complex); float crealf(float complex); long double creall(long double complex); +#ifndef __cplusplus +#define __CIMAG(x, t) \ + (+(union { _Complex t __z; t __xy[2]; }){(_Complex t)(x)}.__xy[1]) + +#define creal(x) ((double)(x)) +#define crealf(x) ((float)(x)) +#define creall(x) ((long double)(x)) + +#define cimag(x) __CIMAG(x, double) +#define cimagf(x) __CIMAG(x, float) +#define cimagl(x) __CIMAG(x, long double) +#endif + +#if __STDC_VERSION__ >= 201112L +#if defined(_Imaginary_I) +#define __CMPLX(x, y, t) ((t)(x) + _Imaginary_I*(t)(y))) +#elif defined(__clang__) +#define __CMPLX(x, y, t) (+(_Complex t){ (t)(x), (t)(y) }) +#else +#define __CMPLX(x, y, t) (__builtin_complex((t)(x), (t)(y))) +#endif +#define CMPLX(x, y) __CMPLX(x, y, double) +#define CMPLXF(x, y) __CMPLX(x, y, float) +#define CMPLXL(x, y) __CMPLX(x, y, long double) +#endif + #ifdef __cplusplus } #endif