summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-03-03 21:16:07 -0500
committerJakob Kaivo <jkk@ung.org>2019-03-03 21:16:07 -0500
commit7de5c55472611fe8ee33f4254f640c7097003748 (patch)
tree42d4eae5f89b8e9cb10660dec1122fb760bcf4e7
parentd767dff01337517e61deaf6da9f51158a3e4ffc5 (diff)
add macros from C11/C18 as they make implementation *much* cleaner
-rw-r--r--src/complex/CMPLX.c16
-rw-r--r--src/complex/CMPLXF.c16
-rw-r--r--src/complex/CMPLXL.c17
3 files changed, 49 insertions, 0 deletions
diff --git a/src/complex/CMPLX.c b/src/complex/CMPLX.c
new file mode 100644
index 00000000..d0ffdedf
--- /dev/null
+++ b/src/complex/CMPLX.c
@@ -0,0 +1,16 @@
+#include <complex.h>
+
+#ifdef __STDC_IEC_559_COMPLEX__
+#define CMPLX(__x, __y) \
+ ((double complex)((double)(__x) + _Imaginary_I * (double)(__y)))
+#else
+#define CMPLX(__x, __y) \
+ (((union { \
+ double complex __c; \
+ double __d[2]; \
+ }){ .__d = { __x, __y } }).__c)
+#endif
+
+/*
+STDC(201112)
+*/
diff --git a/src/complex/CMPLXF.c b/src/complex/CMPLXF.c
new file mode 100644
index 00000000..397e7ad7
--- /dev/null
+++ b/src/complex/CMPLXF.c
@@ -0,0 +1,16 @@
+#include <complex.h>
+
+#ifdef __STDC_IEC_559_COMPLEX__
+#define CMPLXF(__x, __y) \
+ ((float complex)((float)(__x) + _Imaginary_I * (float)(__y)))
+#else
+#define CMPLXF(__x, __y) \
+ (((union { \
+ float complex __c; \
+ float __f[2]; \
+ }){ .__f = { __x, __y } }).__c)
+#endif
+
+/*
+STDC(201112)
+*/
diff --git a/src/complex/CMPLXL.c b/src/complex/CMPLXL.c
new file mode 100644
index 00000000..8e820512
--- /dev/null
+++ b/src/complex/CMPLXL.c
@@ -0,0 +1,17 @@
+#include <complex.h>
+
+#ifdef __STDC_IEC_559_COMPLEX__
+#define CMPLXL(__x, __y) \
+ ((long double complex)((long double)(__x) + \
+ _Imaginary_I * (long double)(__y)))
+#else
+#define CMPLXL(__x, __y) \
+ (((union { \
+ long double complex __c; \
+ long double __ld[2]; \
+ }){ .__ld = { __x, __y } }).__c)
+#endif
+
+/*
+STDC(201112)
+*/