From 13e400b3559666b5e584bdf6f8450aad826b43ae Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Thu, 22 Mar 2012 15:54:55 -0400 Subject: add creal/cimag macros in complex.h (and use them in the functions defs) --- include/complex.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'include/complex.h') diff --git a/include/complex.h b/include/complex.h index 8ee70575..90496bd5 100644 --- a/include/complex.h +++ b/include/complex.h @@ -97,6 +97,17 @@ double creal(double complex); float crealf(float complex); long double creall(long double complex); +#define __CREALIMAG(x, t, i) \ + ((union { _Complex t __z; t __xy[2]; }){(_Complex t)(x)}.__xy[i]) + +#define creal(x) __CREALIMAG(x, double, 0) +#define crealf(x) __CREALIMAG(x, float, 0) +#define creall(x) __CREALIMAG(x, long double, 0) + +#define cimag(x) __CREALIMAG(x, double, 1) +#define cimagf(x) __CREALIMAG(x, float, 1) +#define cimagl(x) __CREALIMAG(x, long double, 1) + #ifdef __cplusplus } #endif -- cgit v1.2.1