use C11 CMPLX or gcc __builtin_complex if available to define cpack macros

This commit is contained in:
Steven G. Johnson 2012-12-20 14:04:23 -05:00
parent e08651b8a9
commit 67d2324543

View file

@ -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 */