summaryrefslogtreecommitdiff
path: root/include/complex.h
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2012-03-22 15:54:55 -0400
committerRich Felker <dalias@aerifal.cx>2012-03-22 15:54:55 -0400
commit13e400b3559666b5e584bdf6f8450aad826b43ae (patch)
treefb19a9f228b2a78dc8e8afc8f7d3439b0865c736 /include/complex.h
parent132f0a00831d3b64cc6ae35df69d6865516c64b5 (diff)
downloadmusl-13e400b3559666b5e584bdf6f8450aad826b43ae.tar.gz
musl-13e400b3559666b5e584bdf6f8450aad826b43ae.tar.bz2
musl-13e400b3559666b5e584bdf6f8450aad826b43ae.tar.xz
musl-13e400b3559666b5e584bdf6f8450aad826b43ae.zip
add creal/cimag macros in complex.h (and use them in the functions defs)
Diffstat (limited to 'include/complex.h')
-rw-r--r--include/complex.h11
1 files changed, 11 insertions, 0 deletions
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