X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=blobdiff_plain;f=include%2Fcomplex.h;h=8206e02679acc6d3a26fea3aedc5e1cf3dc81962;hp=8ee70575cbb0761f42db9900e36f284aff570945;hb=b3175f5c48d414ba792dfb77078dd5f559abd844;hpb=b69f695acedd4ce2798ef9ea28d834ceccc789bd diff --git a/include/complex.h b/include/complex.h index 8ee70575..8206e026 100644 --- a/include/complex.h +++ b/include/complex.h @@ -6,7 +6,11 @@ extern "C" { #endif #define complex _Complex +#ifdef __GNUC__ +#define _Complex_I (__extension__ 1.0fi) +#else #define _Complex_I 1.0fi +#endif #define I _Complex_I double complex cacos(double complex); @@ -97,6 +101,26 @@ double creal(double complex); float crealf(float complex); long double creall(long double complex); +#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) + +#define __CMPLX(x, y, t) \ + ((union { _Complex t __z; t __xy[2]; }){.__xy = {(x),(y)}}.__z) + +#if __STDC_VERSION__ >= 201112L +#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