summaryrefslogtreecommitdiffstats
path: root/include/complex.h
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2012-01-05 12:05:48 +0000
committered <ed@FreeBSD.org>2012-01-05 12:05:48 +0000
commit7b66fc748479f74f48351332bc661cc02bff0374 (patch)
tree2c3837421c98d6a8c2bd6fe8421eedd7dc636b64 /include/complex.h
parente3196d88828e276ddbcd21c347d95355ebbf9dac (diff)
downloadFreeBSD-src-7b66fc748479f74f48351332bc661cc02bff0374.zip
FreeBSD-src-7b66fc748479f74f48351332bc661cc02bff0374.tar.gz
Make _Complex_I a proper float _Complex when using GCC 4.2.
It turns out our GCC has quite an interesting bug: typeof(1.0fi) != float _Complex typeof((float _Complex)1.0fi) != float _Complex typeof((float _Complex)1.0i) == float _Complex In other words: if casting to an equal size, GCC seems to take a shortcut. By casting down from a double to a float, GCC doesn't take this shortcut, yielding the proper type. To prevent foot-shooting, add a _Static_assert() to guarantee that _Complex_I is always a float _Complex. I'm not going to MFC this part of the diff. MFC after: 2 weeks
Diffstat (limited to 'include/complex.h')
-rw-r--r--include/complex.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/include/complex.h b/include/complex.h
index 4142304..395983f 100644
--- a/include/complex.h
+++ b/include/complex.h
@@ -29,11 +29,15 @@
#ifndef _COMPLEX_H
#define _COMPLEX_H
+#include <sys/cdefs.h>
+
#ifdef __GNUC__
#if __STDC_VERSION__ < 199901
#define _Complex __complex__
#endif
-#define _Complex_I 1.0fi
+#define _Complex_I ((float _Complex)1.0i)
+_Static_assert(__generic(_Complex_I, float _Complex, 1, 0),
+ "_Complex_I must be of type float _Complex");
#endif
#define complex _Complex
OpenPOWER on IntegriCloud