+# When compiling with GCC on some OSs (Solaris, AIX), _Complex_I doesn't
+# work; in the reported cases so far, 1.0fi works well instead. According
+# to the C99 spec, the complex.h header must provide a working definition
+# of _Complex_I, so we always try _Complex_I first. The 1.0fi fallback
+# is a workaround for the failure of some systems to conform to C99.
+if test "$ac_cv_type_complex_double" = yes; then
+ AC_MSG_CHECKING([for i])
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+#if HAVE_COMPLEX_H
+#include <complex.h>
+#endif
+complex double z;
+]], [[
+z = _Complex_I;
+]])],
+ [AC_DEFINE(GUILE_I,_Complex_I,[The imaginary unit (positive square root of -1).])
+ AC_MSG_RESULT([_Complex_I])],
+ [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+#if HAVE_COMPLEX_H
+#include <complex.h>
+#endif
+complex double z;
+]],[[
+z = 1.0fi;
+]])],
+ [AC_DEFINE(GUILE_I,1.0fi)
+ AC_MSG_RESULT([1.0fi])],
+ [ac_cv_type_complex_double=no
+ AC_MSG_RESULT([not available])])])
+fi
+
+# glibc 2.3.6 (circa 2006) and various prior versions had a bug where
+# csqrt(-i) returned a negative real part, when it should be positive
+# for the principal root.
+#
+if test "$ac_cv_type_complex_double" = yes; then
+
+ AC_CACHE_CHECK([whether csqrt is usable],
+ guile_cv_use_csqrt,
+ [AC_RUN_IFELSE([AC_LANG_SOURCE([[
+#include <complex.h>
+/* "volatile" is meant to prevent gcc from calculating the sqrt as a
+ constant, we want to test libc. */
+volatile complex double z = - _Complex_I;
+int
+main (void)
+{
+ z = csqrt (z);
+ if (creal (z) > 0.0)
+ return 0; /* good */
+ else
+ return 1; /* bad */
+}]])],
+ [guile_cv_use_csqrt=yes],
+ [guile_cv_use_csqrt="no, glibc 2.3 bug"],
+ [guile_cv_use_csqrt="yes, hopefully (cross-compiling)"])])
+ case $guile_cv_use_csqrt in
+ yes*)
+ AC_DEFINE(HAVE_USABLE_CSQRT, 1, [Define to 1 if csqrt is bug-free])
+ ;;
+ esac
+fi
+
+