From 7de5c55472611fe8ee33f4254f640c7097003748 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Sun, 3 Mar 2019 21:16:07 -0500 Subject: add macros from C11/C18 as they make implementation *much* cleaner --- src/complex/CMPLX.c | 16 ++++++++++++++++ src/complex/CMPLXF.c | 16 ++++++++++++++++ src/complex/CMPLXL.c | 17 +++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 src/complex/CMPLX.c create mode 100644 src/complex/CMPLXF.c create mode 100644 src/complex/CMPLXL.c 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 + +#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 + +#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 + +#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) +*/ -- cgit v1.2.1