diff --git a/src/math_private.h b/src/math_private.h index a9dd508..5fe8cd6 100644 --- a/src/math_private.h +++ b/src/math_private.h @@ -260,7 +260,21 @@ typedef union { * (0.0+I)*(y+0.0*I) and laboriously computing the full complex product. * In particular, I*Inf is corrupted to NaN+I*Inf, and I*-0 is corrupted * to -0.0+I*0.0. + * + * In C11, a CMPLX(x,y) macro was added to circumvent this limitation, + * and gcc 4.7 added a __builtin_complex feature to simplify implementation + * of CMPLX in libc, so we can take advantage of these features if they + * are available. */ +#if defined(CMPLXF) && defined(CMPLX) && defined(CMPLXL) /* C11 */ +# define cpackf(x,y) CMPLXF(x,y) +# define cpack(x,y) CMPLX(x,y) +# define cpackl(x,y) CMPLXL(x,y) +#elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) && !defined(__INTEL_COMPILER) +# define cpackf(x,y) __builtin_complex ((float) (x), (float) (y)) +# define cpack(x,y) __builtin_complex ((double) (x), (double) (y)) +# define cpackl(x,y) __builtin_complex ((long double) (x), (long double) (y)) +#else /* define our own cpack functions */ static __inline float complex cpackf(float x, float y) { @@ -290,6 +304,7 @@ cpackl(long double x, long double y) IMAGPART(z) = y; return (z.f); } +#endif /* define our own cpack functions */ //VBS //#endif /* _COMPLEX_H */