From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Neil Jerram Newsgroups: gmane.lisp.guile.bugs Subject: Fix for _Complex_I problems Date: Sat, 09 Feb 2008 18:54:12 +0000 Message-ID: <87k5leklkb.fsf_-_@ossau.uklinux.net> References: <534824.44153.qm@web37914.mail.mud.yahoo.com> <47A031C6.2030106@dpawson.co.uk> <87odb3uguq.fsf@ossau.uklinux.net> <47A18131.3090503@dpawson.co.uk> <871w7wiep3.fsf@ossau.uklinux.net> <87ir15aw7s.fsf@dellish.bordeaux.inria.fr> <87ve50qpms.fsf_-_@ossau.uklinux.net> <874pcjyfas.fsf@dellish.bordeaux.inria.fr> <87abmbw8du.fsf@ossau.uklinux.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1202615580 17799 80.91.229.12 (10 Feb 2008 03:53:00 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 10 Feb 2008 03:53:00 +0000 (UTC) Cc: "Ludovic =?iso-8859-1?Q?Court=E8s=29=2C?= Guile Bugs " To: Rainer Tammer , Greg Troxel Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Sun Feb 10 04:53:22 2008 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1JO3Fo-00079N-4B for guile-bugs@m.gmane.org; Sun, 10 Feb 2008 04:53:20 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JO3FK-000278-UR for guile-bugs@m.gmane.org; Sat, 09 Feb 2008 22:52:51 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JNuqA-0004mE-Cg for bug-guile@gnu.org; Sat, 09 Feb 2008 13:54:18 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JNuq9-0004lW-W0 for bug-guile@gnu.org; Sat, 09 Feb 2008 13:54:18 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JNuq9-0004lE-GA for bug-guile@gnu.org; Sat, 09 Feb 2008 13:54:17 -0500 Original-Received: from mail3.uklinux.net ([80.84.72.33]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JNuq9-0006S7-3a for bug-guile@gnu.org; Sat, 09 Feb 2008 13:54:17 -0500 Original-Received: from arudy (host86-145-183-175.range86-145.btcentralplus.com [86.145.183.175]) by mail3.uklinux.net (Postfix) with ESMTP id 62D921F6B6E; Sat, 9 Feb 2008 18:54:14 +0000 (GMT) Original-Received: from laruns (laruns [192.168.0.10]) by arudy (Postfix) with ESMTP id 63C6D3800A; Sat, 9 Feb 2008 18:54:13 +0000 (GMT) In-Reply-To: <87abmbw8du.fsf@ossau.uklinux.net> (Neil Jerram's message of "Fri, 08 Feb 2008 19:33:33 +0000") User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) X-detected-kernel: by monty-python.gnu.org: Linux 2.4-2.6 X-Mailman-Approved-At: Sat, 09 Feb 2008 22:52:45 -0500 X-BeenThere: bug-guile@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.bugs:3778 Archived-At: --=-=-= You've both recently reported a compilation problem with _Complex_I, compiling with GCC on Solaris and AIX. My proposed fix for this is attached; please can you review and let me know if you have any comments? (Should I also attach the regenerated ./configure, so you can run that and check that it gives the expected result on your OSs?) Thanks, Neil --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=complex.patch 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); --=-=-=--