From fcb83049b1942fafa784fc51869818651c04acbb Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Wed, 27 Feb 2019 18:29:03 -0500 Subject: basic implementation --- src/complex/_Complex_I.c | 4 +++- src/complex/cimag.c | 6 +++++- src/complex/conj.c | 2 +- src/complex/creal.c | 6 +++++- 4 files changed, 14 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/complex/_Complex_I.c b/src/complex/_Complex_I.c index 0cb6aede..a250d031 100644 --- a/src/complex/_Complex_I.c +++ b/src/complex/_Complex_I.c @@ -1,6 +1,8 @@ #include -#define _Complex_I (const float _Complex)1 /* TODO: imaginary unit */ +#define _Complex_I \ + (((union { _Complex float __c; float __f[2]; }){.__f = {0., 1.} }).__c) + /* STDC(199901) diff --git a/src/complex/cimag.c b/src/complex/cimag.c index 414ecdba..c08ae122 100644 --- a/src/complex/cimag.c +++ b/src/complex/cimag.c @@ -5,7 +5,11 @@ TYPE TGFN(cimag)(TYPE complex z) { - return 0.0; + union { + complex TYPE c; + TYPE f[2]; + } u = { .c = z }; + return z[1]; } /*d diff --git a/src/complex/conj.c b/src/complex/conj.c index f1631106..18e50c9c 100644 --- a/src/complex/conj.c +++ b/src/complex/conj.c @@ -5,7 +5,7 @@ TYPE complex TGFN(conj)(TYPE complex z) { - return 0.0; + return TGFN(creal)(z) - TGFN(cimag)(z); } /*d diff --git a/src/complex/creal.c b/src/complex/creal.c index 86f3cb1b..eac2576e 100644 --- a/src/complex/creal.c +++ b/src/complex/creal.c @@ -5,7 +5,11 @@ TYPE TGFN(creal)(TYPE complex z) { - return 0.0; + union { + complex TYPE c; + TYPE f[2]; + } u = { .c = z }; + return z[0]; } /*d -- cgit v1.2.1