initial cmath code and minor libm.h update
[libm] / src / cmath / conj.c
diff --git a/src/cmath/conj.c b/src/cmath/conj.c
new file mode 100644 (file)
index 0000000..8720feb
--- /dev/null
@@ -0,0 +1,23 @@
+#include "libm.h"
+
+// nice, but internally ugly:
+// macros generate gratuitous code the compiler has to optimize away
+double complex conj(double complex z)
+{
+       return cpack(creal(z), -cimag(z));
+}
+
+/*
+// always works, but ugly union
+double complex conj(double complex z) {
+       union dcomplex u = {z};
+
+       u.a[1] = -u.a[1];
+       return u.z;
+}
+
+// reasonable, needs clever compiler that understands *I
+double complex conj(double complex z) {
+       return creal(z) - cimag(z)*I;
+}
+*/