Index: configure.in =================================================================== RCS file: /cvsroot/guile/guile/guile-core/configure.in,v retrieving revision 1.268.2.37 diff -u -r1.268.2.37 configure.in --- configure.in 6 Feb 2008 22:27:59 -0000 1.268.2.37 +++ configure.in 9 Feb 2008 18:43:21 -0000 @@ -715,6 +716,30 @@ [AC_DEFINE(HAVE_CRYPT,1, [Define to 1 if you have the `crypt' function.])]) +# 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. +if test "$ac_cv_type_complex_double" = yes; then + AC_MSG_CHECKING([for i]) + AC_TRY_COMPILE([ +#if HAVE_COMPLEX_H +#include +#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_TRY_COMPILE([ +#if HAVE_COMPLEX_H +#include +#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. Index: libguile/numbers.c =================================================================== RCS file: /cvsroot/guile/guile/guile-core/libguile/numbers.c,v retrieving revision 1.281.2.12 diff -u -r1.281.2.12 numbers.c --- libguile/numbers.c 6 Feb 2008 13:17:49 -0000 1.281.2.12 +++ libguile/numbers.c 9 Feb 2008 18:43:23 -0000 @@ -162,11 +162,12 @@ #endif } - +#if defined (GUILE_I) /* For an SCM object Z which is a complex number (ie. satisfies SCM_COMPLEXP), return its value as a C level "complex double". */ #define SCM_COMPLEX_VALUE(z) \ - (SCM_COMPLEX_REAL (z) + _Complex_I * SCM_COMPLEX_IMAG (z)) + (SCM_COMPLEX_REAL (z) + GUILE_I * SCM_COMPLEX_IMAG (z)) +#endif /* Convert a C "complex double" to an SCM value. */ #if HAVE_COMPLEX_DOUBLE @@ -6011,7 +6012,7 @@ { if (SCM_COMPLEXP (z)) { -#if HAVE_COMPLEX_DOUBLE && HAVE_CLOG +#if HAVE_COMPLEX_DOUBLE && HAVE_CLOG && defined (GUILE_I) return scm_from_complex_double (clog (SCM_COMPLEX_VALUE (z))); #else double re = SCM_COMPLEX_REAL (z); @@ -6045,7 +6046,7 @@ /* Mingw has clog() but not clog10(). (Maybe it'd be worth using clog() and a multiply by M_LOG10E, rather than the fallback log10+hypot+atan2.) */ -#if HAVE_COMPLEX_DOUBLE && HAVE_CLOG10 +#if HAVE_COMPLEX_DOUBLE && HAVE_CLOG10 && defined (GUILE_I) return scm_from_complex_double (clog10 (SCM_COMPLEX_VALUE (z))); #else double re = SCM_COMPLEX_REAL (z); @@ -6077,7 +6078,7 @@ { if (SCM_COMPLEXP (z)) { -#if HAVE_COMPLEX_DOUBLE && HAVE_CEXP +#if HAVE_COMPLEX_DOUBLE && HAVE_CEXP && defined (GUILE_I) return scm_from_complex_double (cexp (SCM_COMPLEX_VALUE (z))); #else return scm_c_make_polar (exp (SCM_COMPLEX_REAL (z)), @@ -6111,7 +6112,7 @@ { if (SCM_COMPLEXP (x)) { -#if HAVE_COMPLEX_DOUBLE && HAVE_USABLE_CSQRT +#if HAVE_COMPLEX_DOUBLE && HAVE_USABLE_CSQRT && defined (GUILE_I) return scm_from_complex_double (csqrt (SCM_COMPLEX_VALUE (x))); #else double re = SCM_COMPLEX_REAL (x);