Browse Source

Merge pull request #16 from stevengj/CMPLX

use C11 CMPLX or gcc __builtin_complex; this fixes issue #15
Viral B. Shah 12 năm trước cách đây
mục cha
commit
e3e2501359
1 tập tin đã thay đổi với 15 bổ sung0 xóa
  1. 15 0
      src/math_private.h

+ 15 - 0
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 */