From unknown Sun Jun 22 07:42:46 2025 X-Loop: help-debbugs@gnu.org Subject: bug#25785: scm_c_make_polar broken on APPLE Resent-From: Matt Wette Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Sat, 18 Feb 2017 17:39:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 25785 X-GNU-PR-Package: guile X-GNU-PR-Keywords: To: 25785@debbugs.gnu.org X-Debbugs-Original-To: bug-guile@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.14874394987981 (code B ref -1); Sat, 18 Feb 2017 17:39:01 +0000 Received: (at submit) by debbugs.gnu.org; 18 Feb 2017 17:38:18 +0000 Received: from localhost ([127.0.0.1]:45245 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cf8xe-00024f-BC for submit@debbugs.gnu.org; Sat, 18 Feb 2017 12:38:18 -0500 Received: from eggs.gnu.org ([208.118.235.92]:44269) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cf8xd-00024S-6K for submit@debbugs.gnu.org; Sat, 18 Feb 2017 12:38:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cf8xU-0005gp-LC for submit@debbugs.gnu.org; Sat, 18 Feb 2017 12:38:11 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: *** X-Spam-Status: No, score=3.1 required=5.0 tests=BAYES_50,FREEMAIL_FROM, HTML_MESSAGE, MANY_SPAN_IN_TEXT, T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:41467) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cf8xU-0005gj-Gt for submit@debbugs.gnu.org; Sat, 18 Feb 2017 12:38:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35225) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cf8xQ-0000x5-SH for bug-guile@gnu.org; Sat, 18 Feb 2017 12:38:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cf8xL-0005fC-Rb for bug-guile@gnu.org; Sat, 18 Feb 2017 12:38:04 -0500 Received: from mail-pg0-x22c.google.com ([2607:f8b0:400e:c05::22c]:33694) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cf8xL-0005ez-Hz for bug-guile@gnu.org; Sat, 18 Feb 2017 12:37:59 -0500 Received: by mail-pg0-x22c.google.com with SMTP id a123so1242612pgc.0 for ; Sat, 18 Feb 2017 09:37:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:mime-version:subject:message-id:date:to; bh=1V74h6NQiIj86KUQoZg9lkStqEvGamHRhPo5Co5slQ0=; b=N3wZAHbaV3u5rjLNqiR9FYlI1yLj8xvIdPcF/P4lRmhHLw+HNjT30dDrxxZAh+Otbr H1NIV6CgOc3KwA2fjWxFYvmdskA25emWDRWOvgrQ0nD6murR4s72cliL8gZgxz8rihKs RVrXqzYxIdXA3W5mMSR1yz8uMuM/mz1DLc6NCauVyunOcQfzavXTclc8PISDbP0Dhp6O p3AKiqrMTOuf2P9us/oKxQ4PSgCsiNCc/NN872xCvHF7GZuErLV4ZGyOz1pd7cl1pBFH TEURG5WYt8O2PvA4Na5aUV3mITXUPnWRERdudCKWiVRMMczvl7SF0M1HVK03hnr0s6St lBlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:mime-version:subject:message-id:date:to; bh=1V74h6NQiIj86KUQoZg9lkStqEvGamHRhPo5Co5slQ0=; b=DB0OQ1KvdEDzyJb5TomfOzxfYLEMr3GeoBCAK0FZFdlxLREXDGwAMVY99OXJ5tKfOQ 81ze3CiDOiALSXW+LlgVt93Q8E1oGQllMoEL4HWK+DapnaStzFUiLhnNEVpg8muuBLQH MZ4L2B400+0eoIUOOeCfL+WygfnJ23iy0HYIdXEQ39zQbNDed09zDx+bcLegiTsrWr35 8hJoRW3SLsqSTZXf4nl/pScD3HFrNvReQNLRkyhYOd/WOSJ820QCta5jkfE087CAs7rZ 9gX239HNa3nPLj/i8KPmMkQxOrUfHtSku8qzntJNbnptecklmJqQN+Ws207v8NoDBu+B M1Xg== X-Gm-Message-State: AMke39mI8o9nnvv7NBGqBFxIm+i7DAiHE+ww6RKlol+1WxZdNs76wlXQf7nEYzkXaBHTaQ== X-Received: by 10.84.241.138 with SMTP id b10mr19820313pll.32.1487439477944; Sat, 18 Feb 2017 09:37:57 -0800 (PST) Received: from nautilus.championbroadband.com (216-165-246-244.championbroadband.com. [216.165.246.244]) by smtp.gmail.com with ESMTPSA id i15sm5244927pfj.0.2017.02.18.09.37.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Feb 2017 09:37:56 -0800 (PST) From: Matt Wette Content-Type: multipart/alternative; boundary="Apple-Mail=_A118C0A3-D324-47B9-9844-79DF6C0C3EB2" Mime-Version: 1.0 (Mac OS X Mail 10.2 \(3259\)) Message-Id: Date: Sat, 18 Feb 2017 09:37:54 -0800 X-Mailer: Apple Mail (2.3259) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -1.7 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.0 (----) --Apple-Mail=_A118C0A3-D324-47B9-9844-79DF6C0C3EB2 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 numbers.c:scm_c_make_polar in guile-2.1.7 breaks on APPLE (macOS 10.12). Reason: APPLE does not have sincos(), and gcc will optimize sin/cos to = use cexp(), and cexp() does not preserve sign of zero. Patch includes (and attached) for guile-2.1.7. This uses macOS = __sincos(). Example: In scm_c_make_polar, =E2=80=9Cgcc -O2=E2=80=9D turns sin(), cos() into = cexp(), since cexp(i*x) =3D cos(x) + i*sin(x): gcc -O0 =3D> LM4339: movq -32(%rbp), %rax movd %rax, %xmm0 call _sin movd %xmm0, %rax movq %rax, -8(%rbp) LM4340: movq -32(%rbp), %rax movd %rax, %xmm0 call _cos movd %xmm0, %rax movq %rax, -16(%rbp) gcc -O2 =3D> pxor %xmm0, %xmm0 LVL2703: call _cexp I wrote a little C program to show that cexp() does not preserve the = zero-signed-ness: cos,sin: +1.000000 -0.000000 __sincos: +1.000000 -0.000000 cexp: +1.000000 +0.000000 The scm_c_make_polar will use sincos() if available, but macOS does not = have sincos(), it has __sincos(). #include #include #include #include extern double z, p, n; int main() { double complex c; double d, sine, cosine; d =3D z*n; printf(" cos,sin: %+f %+f\n", cos(d), sin(d)); __sincos(d, &sine, &cosine); printf("__sincos: %+f %+f\n", cosine, sine); c =3D cexp(CMPLX(0.0, d)); printf(" cexp: %+f %+f\n", creal(c), cimag(c)); } double z =3D 0.0, p =3D +1.0, n =3D -1.0; --- configure.ac.orig 2017-02-18 08:35:06.000000000 -0800 +++ configure.ac 2017-02-18 08:35:26.000000000 -0800 @@ -1152,8 +1152,9 @@ # asinh, acosh, atanh, trunc - C99 standard, generally not available = on # older systems # sincos - GLIBC extension +# __sincos - APPLE extension # -AC_CHECK_FUNCS(asinh acosh atanh copysign finite sincos trunc) +AC_CHECK_FUNCS(asinh acosh atanh copysign finite sincos __sincos trunc) =20 # C99 specifies isinf and isnan as macros. # HP-UX provides only macros, no functions. --- libguile/numbers.c.patch.labs 2017-02-18 08:31:21.000000000 = -0800 +++ libguile/numbers.c 2017-02-18 08:34:18.000000000 -0800 @@ -9109,6 +9109,8 @@ details. */ #if (defined HAVE_SINCOS) && (defined __GLIBC__) && (defined = _GNU_SOURCE) sincos (ang, &s, &c); +#elif (defined HAVE___SINCOS) + __sincos (ang, &s, &c); #else s =3D sin (ang); c =3D cos (ang); --Apple-Mail=_A118C0A3-D324-47B9-9844-79DF6C0C3EB2 Content-Type: multipart/mixed; boundary="Apple-Mail=_1F9A3EBB-9475-4C82-B9EF-39C4681D7900" --Apple-Mail=_1F9A3EBB-9475-4C82-B9EF-39C4681D7900 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 numbers.c:scm_c_make_polar in guile-2.1.7 breaks on APPLE = (macOS 10.12).

Reason:= APPLE does not have sincos(), and gcc will optimize sin/cos to use = cexp(), and cexp() does not preserve sign of zero.

Patch includes (and = attached) for guile-2.1.7.  This uses macOS __sincos().

Example:
In scm_c_make_polar, =E2=80=9Cgcc -O2=E2=80=9D =  turns sin(), cos() into cexp(), since cexp(i*x) =3D cos(x) + = i*sin(x):

gcc -O0 = =3D>
LM4339:
= movq = -32(%rbp), %rax
= movd = %rax, %xmm0
= call = _sin
= movd = %xmm0, %rax
= movq = %rax, -8(%rbp)
LM4340:
= movq = -32(%rbp), %rax
= movd = %rax, %xmm0
= call = _cos
= movd = %xmm0, %rax
= movq = %rax, -16(%rbp)

gcc -O2 =3D>
pxor %xmm0, %xmm0
LVL2703:
call _cexp

I wrote a little C = program to show that cexp() does not preserve the = zero-signed-ness:

 cos,sin: +1.000000 = -0.000000
__sincos: = +1.000000 -0.000000
    = cexp: +1.000000 +0.000000

The scm_c_make_polar will use = sincos() if available, but macOS does not have sincos(), it has = __sincos().

#include <stdio.h>
#include <stdint.h>
#include <math.h>
#include = <complex.h>

extern double z, p, n;

int main() = {
  double complex c;
  = double d, sine, cosine;

  d =3D z*n;
  printf(" = cos,sin: %+f %+f\n", cos(d), sin(d));
  = __sincos(d, &sine, &cosine);
  = printf("__sincos: %+f %+f\n", cosine, sine);
  c =3D = cexp(CMPLX(0.0, d));
  = printf("    cexp: %+f %+f\n", creal(c), = cimag(c));
}

double z =3D 0.0, p =3D +1.0, n =3D = -1.0;


--- configure.ac.orig = 2017-02-18 08:35:06.000000000 -0800
+++ configure.ac 2017-02-18 08:35:26.000000000 = -0800
@@ -1152,8 +1152,9 = @@
 #   = asinh, acosh, atanh, trunc - C99 standard, generally not available = on
 #   =                     =          older systems
 #   sincos - GLIBC = extension
+#   __sincos - = APPLE extension
 #
-AC_CHECK_FUNCS(asinh acosh atanh copysign finite sincos = trunc)
+AC_CHECK_FUNCS(asinh = acosh atanh copysign finite sincos __sincos trunc)
 
 # C99 specifies isinf and isnan as = macros.
 # HP-UX = provides only macros, no functions.
--- libguile/numbers.c.patch.labs = 2017-02-18 08:31:21.000000000 -0800
+++ libguile/numbers.c 2017-02-18 08:34:18.000000000 = -0800
@@ -9109,6 +9109,8 = @@
      = details.  */
 #if= (defined HAVE_SINCOS) && (defined __GLIBC__) && = (defined _GNU_SOURCE)
  =  sincos (ang, &s, &c);
+#elif (defined HAVE___SINCOS)
+  __sincos (ang, &s, = &c);
 #else
  =  s =3D sin (ang);
  =  c =3D cos (ang);
= --Apple-Mail=_1F9A3EBB-9475-4C82-B9EF-39C4681D7900 Content-Disposition: attachment; filename=sincos.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="sincos.patch" Content-Transfer-Encoding: 7bit --- configure.ac.orig 2017-02-18 08:35:06.000000000 -0800 +++ configure.ac 2017-02-18 08:35:26.000000000 -0800 @@ -1152,8 +1152,9 @@ # asinh, acosh, atanh, trunc - C99 standard, generally not available on # older systems # sincos - GLIBC extension +# __sincos - APPLE extension # -AC_CHECK_FUNCS(asinh acosh atanh copysign finite sincos trunc) +AC_CHECK_FUNCS(asinh acosh atanh copysign finite sincos __sincos trunc) # C99 specifies isinf and isnan as macros. # HP-UX provides only macros, no functions. --- libguile/numbers.c.patch.labs 2017-02-18 08:31:21.000000000 -0800 +++ libguile/numbers.c 2017-02-18 08:34:18.000000000 -0800 @@ -9109,6 +9109,8 @@ details. */ #if (defined HAVE_SINCOS) && (defined __GLIBC__) && (defined _GNU_SOURCE) sincos (ang, &s, &c); +#elif (defined HAVE___SINCOS) + __sincos (ang, &s, &c); #else s = sin (ang); c = cos (ang); --Apple-Mail=_1F9A3EBB-9475-4C82-B9EF-39C4681D7900 Content-Transfer-Encoding: 7bit Content-Type: text/html; charset=us-ascii

--Apple-Mail=_1F9A3EBB-9475-4C82-B9EF-39C4681D7900-- --Apple-Mail=_A118C0A3-D324-47B9-9844-79DF6C0C3EB2-- From unknown Sun Jun 22 07:42:46 2025 X-Loop: help-debbugs@gnu.org Subject: bug#25785: scm_c_make_polar broken References: In-Reply-To: Resent-From: Matt Wette Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Sat, 18 Feb 2017 21:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25785 X-GNU-PR-Package: guile X-GNU-PR-Keywords: To: 25785@debbugs.gnu.org Received: via spool by 25785-submit@debbugs.gnu.org id=B25785.148745344523672 (code B ref 25785); Sat, 18 Feb 2017 21:31:02 +0000 Received: (at 25785) by debbugs.gnu.org; 18 Feb 2017 21:30:45 +0000 Received: from localhost ([127.0.0.1]:45427 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cfCaa-00069k-Tz for submit@debbugs.gnu.org; Sat, 18 Feb 2017 16:30:45 -0500 Received: from mail-pf0-f171.google.com ([209.85.192.171]:34707) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cfCaZ-00069X-Bn for 25785@debbugs.gnu.org; Sat, 18 Feb 2017 16:30:43 -0500 Received: by mail-pf0-f171.google.com with SMTP id e4so21102750pfg.1 for <25785@debbugs.gnu.org>; Sat, 18 Feb 2017 13:30:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:mime-version:subject:message-id:date:to; bh=f4rlQOOHp6xniWZBfES/f9TvE7YsprXmUoyWT6rS+n8=; b=haXVzeqI/mzbIs+O2srSN3EW5qE+1/ylf4d0sSVzN4Ukrt4P1afYy052WcJyRk5DTP bMKFIWDKhWgnBEnna9A8gBShMYfNaiUNsZGaHZdfXqMNJw/dfjlhP0ugBXLuEW+U0fV5 kXiUsDl80GTNyjGJIqVly/bkUkXWFgv6ozU66e0uXpoCknWjjw7rU2G9PC+Oz0oMXGRT 3/mIfhKbqmkB8mJWtvE+6tinFLF9ZWnR+4N4EWN9QXMY4iLfmZelOFiCl11Phtvm9MG8 fj6KqZUWgDmI+r3ukjKFfJvPu+XuZakTu6W4fr0nXZvY5En3Mh9AfFOTUsE+TX/MqamC 9iNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:mime-version:subject:message-id:date:to; bh=f4rlQOOHp6xniWZBfES/f9TvE7YsprXmUoyWT6rS+n8=; b=qG6Yw7dA/wcsWA32fML2OC6VknhU9loBP1qI18Hz0sQVHErmp4GvAQce3AuCuiXE0Y w5W6dkx6NP4FTqcEWyTC0DZRZivVKomwwLq102Dmh+zCLa1dN3j0eit1aQOipezxQLP6 X8jmYUrlbWl+Yz/jO/d5zrAu/7xkNzBDp9kZJCkad7FvXjrNwPvhuEaw/eGcpVRrrnYG 0uH5SZxx/v0d+/YzXAc/2kEp2gfc0UcHahS8Id1MV8KB2/8kWL8NtMSQamHDX0Xj2E4R P2M/jBWf9mFEcpFQdn2mmd/4M+wanbm2HCCc51jsoJ68EPVBasWTWZTF6mQxik3XXq8u F2aw== X-Gm-Message-State: AMke39n3ExPEVosZcNoz2o6gvf86m7h/bgCxsMWNrgkN7CgRIEX8/K2qLsIZWzJ/I2/Deg== X-Received: by 10.99.115.30 with SMTP id o30mr247881pgc.27.1487453437300; Sat, 18 Feb 2017 13:30:37 -0800 (PST) Received: from nautilus.championbroadband.com (216-165-246-244.championbroadband.com. [216.165.246.244]) by smtp.gmail.com with ESMTPSA id q7sm26761835pfb.98.2017.02.18.13.30.35 for <25785@debbugs.gnu.org> (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Feb 2017 13:30:35 -0800 (PST) From: Matt Wette Content-Type: multipart/alternative; boundary="Apple-Mail=_CCD7D7D4-998E-488C-9C64-614BD30C5AFD" Mime-Version: 1.0 (Mac OS X Mail 10.2 \(3259\)) Message-Id: Date: Sat, 18 Feb 2017 13:30:33 -0800 X-Mailer: Apple Mail (2.3259) X-Spam-Score: -2.8 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.8 (--) --Apple-Mail=_CCD7D7D4-998E-488C-9C64-614BD30C5AFD Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii So, I may have missed the update for config.h.in. I am not sure this = gets autogenerated or not. --- config.h.in.orig 2017-02-18 13:27:19.000000000 -0800 +++ config.h.in 2017-02-18 13:27:45.000000000 -0800 @@ -2183,6 +2183,9 @@ /* Define to 1 if you have the `sincos' function. */ #undef HAVE_SINCOS =20 +/* Define to 1 if you have the `__sincos' function. */ +#undef HAVE___SINCOS + /* Define to 1 if you have the `snprintf' function. */ #undef HAVE_SNPRINTF =20 --Apple-Mail=_CCD7D7D4-998E-488C-9C64-614BD30C5AFD Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii So, I may have missed the update for config.h.in.   I am = not sure this gets autogenerated or not.

--- config.h.in.orig = 2017-02-18 13:27:19.000000000 -0800
+++ = config.h.in = 2017-02-18 13:27:45.000000000 -0800
@@ = -2183,6 +2183,9 @@
 /* Define to 1 if you have the = `sincos' function. */
 #undef HAVE_SINCOS

 

+/* = Define to 1 if you have the `__sincos' function. */
+#undef = HAVE___SINCOS
+
 /* = Define to 1 if you have the `snprintf' function. */
 #undef HAVE_SNPRINTF

 


= --Apple-Mail=_CCD7D7D4-998E-488C-9C64-614BD30C5AFD-- From unknown Sun Jun 22 07:42:46 2025 X-Loop: help-debbugs@gnu.org Subject: bug#25785: scm_c_make_polar broken on APPLE Resent-From: Andy Wingo Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Tue, 21 Feb 2017 21:11:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25785 X-GNU-PR-Package: guile X-GNU-PR-Keywords: To: Matt Wette Cc: 25785@debbugs.gnu.org Received: via spool by 25785-submit@debbugs.gnu.org id=B25785.148771142125668 (code B ref 25785); Tue, 21 Feb 2017 21:11:01 +0000 Received: (at 25785) by debbugs.gnu.org; 21 Feb 2017 21:10:21 +0000 Received: from localhost ([127.0.0.1]:49295 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cgHhV-0006fv-Fz for submit@debbugs.gnu.org; Tue, 21 Feb 2017 16:10:21 -0500 Received: from pb-sasl2.pobox.com ([64.147.108.67]:63817 helo=sasl.smtp.pobox.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cgHhU-0006fo-8u for 25785@debbugs.gnu.org; Tue, 21 Feb 2017 16:10:20 -0500 Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-sasl2.pobox.com (Postfix) with ESMTP id BF7CA60F84; Tue, 21 Feb 2017 16:10:18 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=ZquYeSErt3+gpdZaS5evKoITwhA=; b=ppwZjF c1YbfEFfaZnZDDkCGyBv5FmtO0u1hR18O6eAcE9SCKo2Rv+kH3JzEVtsOF2GvWGK JFBMzy8qjInzMA9gAYaAxhuAvxeJt6hTRBBEqn2TkShBrL1gif7Nm9w775FEgNuC Pra9iH66XFj5+ovM/4rkX5Xe9ydYsGc0WKqZY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=sasl; b=IzSxqjijjsO+Q9HYPDEBTRoTO0wjkMc4 rvDltSK+arhFskDDt/NzyNd4gEAiCi5WsXvJrl4o3EblC9BNwhSrMK5UeX2kcw+x JMlZELP1FdYne1uerHvOTM/n6kTKZYNruJKwuxnES81SXWZhsXkZJ2GpPz0EBa7m qMjrRaJ2xig= Received: from pb-sasl2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-sasl2.pobox.com (Postfix) with ESMTP id B811560F83; Tue, 21 Feb 2017 16:10:18 -0500 (EST) Received: from clucks (unknown [88.160.190.192]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by pb-sasl2.pobox.com (Postfix) with ESMTPSA id 9B24660F82; Tue, 21 Feb 2017 16:10:17 -0500 (EST) From: Andy Wingo References: Date: Tue, 21 Feb 2017 22:10:09 +0100 In-Reply-To: (Matt Wette's message of "Sat, 18 Feb 2017 09:37:54 -0800") Message-ID: <871surz1vy.fsf@pobox.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Pobox-Relay-ID: 2588B596-F87A-11E6-AD79-6141F2301B6D-02397024!pb-sasl2.pobox.com X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) On Sat 18 Feb 2017 18:37, Matt Wette writes: > Patch includes (and attached) for guile-2.1.7. This uses macOS __sincos(). Thank you for this patch! Applied. The config.h.in is indeed autogenerated (by autoheader, I think). Andy From unknown Sun Jun 22 07:42:46 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Matt Wette Subject: bug#25785: closed (Re: bug#25785: scm_c_make_polar broken on APPLE) Message-ID: References: <87tw7nxnan.fsf@pobox.com> X-Gnu-PR-Message: they-closed 25785 X-Gnu-PR-Package: guile Reply-To: 25785@debbugs.gnu.org Date: Tue, 21 Feb 2017 21:11:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1487711462-25741-1" This is a multi-part message in MIME format... ------------=_1487711462-25741-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #25785: scm_c_make_polar broken on APPLE which was filed against the guile package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 25785@debbugs.gnu.org. --=20 25785: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D25785 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1487711462-25741-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 25785-done) by debbugs.gnu.org; 21 Feb 2017 21:10:52 +0000 Received: from localhost ([127.0.0.1]:49299 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cgHhz-0006ge-P5 for submit@debbugs.gnu.org; Tue, 21 Feb 2017 16:10:51 -0500 Received: from pb-sasl2.pobox.com ([64.147.108.67]:50537 helo=sasl.smtp.pobox.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cgHhx-0006gV-KQ for 25785-done@debbugs.gnu.org; Tue, 21 Feb 2017 16:10:49 -0500 Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-sasl2.pobox.com (Postfix) with ESMTP id AB7EB60F88 for <25785-done@debbugs.gnu.org>; Tue, 21 Feb 2017 16:10:49 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=+eWgJyyk3PEXsDGMvgMtgcUUCAk=; b=p8Wrfj qFU0FtWV8ji03vU315XP0XRPRuvSuNLfmvRnMYISr/ozdqNWv1WbRk17hgmls+2J K8kr5eNqvp7FCK0LzqPY7pp56q9R9+RbIiLU/hDPi06NIJJepFKFtgvZ4/Phwf/A YGZ7cBKjDJogjAWgmeP8TN7dEfqRmrAsY2IP0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:subject :references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=sasl; b=I5Rx6AapmsmnNpVJVPDmtlo3MEtv1SgT Ej/C8TyjvOxEMH6b3MeI3OwA2eKYAxtr0l2z8CnSpMQ8UYGx33/DdyYgppkGqzFM IbRWQdhFLWFzjb48LRykJRpzddhJhstN5JDujywt2OVvwI+tOyyyabvc687eOb80 aVHjcLHV7P0= Received: from pb-sasl2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-sasl2.pobox.com (Postfix) with ESMTP id A079060F87 for <25785-done@debbugs.gnu.org>; Tue, 21 Feb 2017 16:10:49 -0500 (EST) Received: from clucks (unknown [88.160.190.192]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by pb-sasl2.pobox.com (Postfix) with ESMTPSA id 7BAF060F85 for <25785-done@debbugs.gnu.org>; Tue, 21 Feb 2017 16:10:48 -0500 (EST) From: Andy Wingo To: 25785-done@debbugs.gnu.org Subject: Re: bug#25785: scm_c_make_polar broken on APPLE References: Date: Tue, 21 Feb 2017 22:10:40 +0100 In-Reply-To: (Matt Wette's message of "Sat, 18 Feb 2017 09:37:54 -0800") Message-ID: <87tw7nxnan.fsf@pobox.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Pobox-Relay-ID: 37EE6C4E-F87A-11E6-AD85-6141F2301B6D-02397024!pb-sasl2.pobox.com X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 25785-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) Thanks! ------------=_1487711462-25741-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 18 Feb 2017 17:38:18 +0000 Received: from localhost ([127.0.0.1]:45245 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cf8xe-00024f-BC for submit@debbugs.gnu.org; Sat, 18 Feb 2017 12:38:18 -0500 Received: from eggs.gnu.org ([208.118.235.92]:44269) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cf8xd-00024S-6K for submit@debbugs.gnu.org; Sat, 18 Feb 2017 12:38:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cf8xU-0005gp-LC for submit@debbugs.gnu.org; Sat, 18 Feb 2017 12:38:11 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: *** X-Spam-Status: No, score=3.1 required=5.0 tests=BAYES_50,FREEMAIL_FROM, HTML_MESSAGE, MANY_SPAN_IN_TEXT, T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:41467) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cf8xU-0005gj-Gt for submit@debbugs.gnu.org; Sat, 18 Feb 2017 12:38:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35225) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cf8xQ-0000x5-SH for bug-guile@gnu.org; Sat, 18 Feb 2017 12:38:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cf8xL-0005fC-Rb for bug-guile@gnu.org; Sat, 18 Feb 2017 12:38:04 -0500 Received: from mail-pg0-x22c.google.com ([2607:f8b0:400e:c05::22c]:33694) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cf8xL-0005ez-Hz for bug-guile@gnu.org; Sat, 18 Feb 2017 12:37:59 -0500 Received: by mail-pg0-x22c.google.com with SMTP id a123so1242612pgc.0 for ; Sat, 18 Feb 2017 09:37:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:mime-version:subject:message-id:date:to; bh=1V74h6NQiIj86KUQoZg9lkStqEvGamHRhPo5Co5slQ0=; b=N3wZAHbaV3u5rjLNqiR9FYlI1yLj8xvIdPcF/P4lRmhHLw+HNjT30dDrxxZAh+Otbr H1NIV6CgOc3KwA2fjWxFYvmdskA25emWDRWOvgrQ0nD6murR4s72cliL8gZgxz8rihKs RVrXqzYxIdXA3W5mMSR1yz8uMuM/mz1DLc6NCauVyunOcQfzavXTclc8PISDbP0Dhp6O p3AKiqrMTOuf2P9us/oKxQ4PSgCsiNCc/NN872xCvHF7GZuErLV4ZGyOz1pd7cl1pBFH TEURG5WYt8O2PvA4Na5aUV3mITXUPnWRERdudCKWiVRMMczvl7SF0M1HVK03hnr0s6St lBlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:mime-version:subject:message-id:date:to; bh=1V74h6NQiIj86KUQoZg9lkStqEvGamHRhPo5Co5slQ0=; b=DB0OQ1KvdEDzyJb5TomfOzxfYLEMr3GeoBCAK0FZFdlxLREXDGwAMVY99OXJ5tKfOQ 81ze3CiDOiALSXW+LlgVt93Q8E1oGQllMoEL4HWK+DapnaStzFUiLhnNEVpg8muuBLQH MZ4L2B400+0eoIUOOeCfL+WygfnJ23iy0HYIdXEQ39zQbNDed09zDx+bcLegiTsrWr35 8hJoRW3SLsqSTZXf4nl/pScD3HFrNvReQNLRkyhYOd/WOSJ820QCta5jkfE087CAs7rZ 9gX239HNa3nPLj/i8KPmMkQxOrUfHtSku8qzntJNbnptecklmJqQN+Ws207v8NoDBu+B M1Xg== X-Gm-Message-State: AMke39mI8o9nnvv7NBGqBFxIm+i7DAiHE+ww6RKlol+1WxZdNs76wlXQf7nEYzkXaBHTaQ== X-Received: by 10.84.241.138 with SMTP id b10mr19820313pll.32.1487439477944; Sat, 18 Feb 2017 09:37:57 -0800 (PST) Received: from nautilus.championbroadband.com (216-165-246-244.championbroadband.com. [216.165.246.244]) by smtp.gmail.com with ESMTPSA id i15sm5244927pfj.0.2017.02.18.09.37.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Feb 2017 09:37:56 -0800 (PST) From: Matt Wette Content-Type: multipart/alternative; boundary="Apple-Mail=_A118C0A3-D324-47B9-9844-79DF6C0C3EB2" Mime-Version: 1.0 (Mac OS X Mail 10.2 \(3259\)) Subject: scm_c_make_polar broken on APPLE Message-Id: Date: Sat, 18 Feb 2017 09:37:54 -0800 To: bug-guile@gnu.org X-Mailer: Apple Mail (2.3259) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -1.7 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.0 (----) --Apple-Mail=_A118C0A3-D324-47B9-9844-79DF6C0C3EB2 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 numbers.c:scm_c_make_polar in guile-2.1.7 breaks on APPLE (macOS 10.12). Reason: APPLE does not have sincos(), and gcc will optimize sin/cos to = use cexp(), and cexp() does not preserve sign of zero. Patch includes (and attached) for guile-2.1.7. This uses macOS = __sincos(). Example: In scm_c_make_polar, =E2=80=9Cgcc -O2=E2=80=9D turns sin(), cos() into = cexp(), since cexp(i*x) =3D cos(x) + i*sin(x): gcc -O0 =3D> LM4339: movq -32(%rbp), %rax movd %rax, %xmm0 call _sin movd %xmm0, %rax movq %rax, -8(%rbp) LM4340: movq -32(%rbp), %rax movd %rax, %xmm0 call _cos movd %xmm0, %rax movq %rax, -16(%rbp) gcc -O2 =3D> pxor %xmm0, %xmm0 LVL2703: call _cexp I wrote a little C program to show that cexp() does not preserve the = zero-signed-ness: cos,sin: +1.000000 -0.000000 __sincos: +1.000000 -0.000000 cexp: +1.000000 +0.000000 The scm_c_make_polar will use sincos() if available, but macOS does not = have sincos(), it has __sincos(). #include #include #include #include extern double z, p, n; int main() { double complex c; double d, sine, cosine; d =3D z*n; printf(" cos,sin: %+f %+f\n", cos(d), sin(d)); __sincos(d, &sine, &cosine); printf("__sincos: %+f %+f\n", cosine, sine); c =3D cexp(CMPLX(0.0, d)); printf(" cexp: %+f %+f\n", creal(c), cimag(c)); } double z =3D 0.0, p =3D +1.0, n =3D -1.0; --- configure.ac.orig 2017-02-18 08:35:06.000000000 -0800 +++ configure.ac 2017-02-18 08:35:26.000000000 -0800 @@ -1152,8 +1152,9 @@ # asinh, acosh, atanh, trunc - C99 standard, generally not available = on # older systems # sincos - GLIBC extension +# __sincos - APPLE extension # -AC_CHECK_FUNCS(asinh acosh atanh copysign finite sincos trunc) +AC_CHECK_FUNCS(asinh acosh atanh copysign finite sincos __sincos trunc) =20 # C99 specifies isinf and isnan as macros. # HP-UX provides only macros, no functions. --- libguile/numbers.c.patch.labs 2017-02-18 08:31:21.000000000 = -0800 +++ libguile/numbers.c 2017-02-18 08:34:18.000000000 -0800 @@ -9109,6 +9109,8 @@ details. */ #if (defined HAVE_SINCOS) && (defined __GLIBC__) && (defined = _GNU_SOURCE) sincos (ang, &s, &c); +#elif (defined HAVE___SINCOS) + __sincos (ang, &s, &c); #else s =3D sin (ang); c =3D cos (ang); --Apple-Mail=_A118C0A3-D324-47B9-9844-79DF6C0C3EB2 Content-Type: multipart/mixed; boundary="Apple-Mail=_1F9A3EBB-9475-4C82-B9EF-39C4681D7900" --Apple-Mail=_1F9A3EBB-9475-4C82-B9EF-39C4681D7900 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 numbers.c:scm_c_make_polar in guile-2.1.7 breaks on APPLE = (macOS 10.12).

Reason:= APPLE does not have sincos(), and gcc will optimize sin/cos to use = cexp(), and cexp() does not preserve sign of zero.

Patch includes (and = attached) for guile-2.1.7.  This uses macOS __sincos().

Example:
In scm_c_make_polar, =E2=80=9Cgcc -O2=E2=80=9D =  turns sin(), cos() into cexp(), since cexp(i*x) =3D cos(x) + = i*sin(x):

gcc -O0 = =3D>
LM4339:
= movq = -32(%rbp), %rax
= movd = %rax, %xmm0
= call = _sin
= movd = %xmm0, %rax
= movq = %rax, -8(%rbp)
LM4340:
= movq = -32(%rbp), %rax
= movd = %rax, %xmm0
= call = _cos
= movd = %xmm0, %rax
= movq = %rax, -16(%rbp)

gcc -O2 =3D>
pxor %xmm0, %xmm0
LVL2703:
call _cexp

I wrote a little C = program to show that cexp() does not preserve the = zero-signed-ness:

 cos,sin: +1.000000 = -0.000000
__sincos: = +1.000000 -0.000000
    = cexp: +1.000000 +0.000000

The scm_c_make_polar will use = sincos() if available, but macOS does not have sincos(), it has = __sincos().

#include <stdio.h>
#include <stdint.h>
#include <math.h>
#include = <complex.h>

extern double z, p, n;

int main() = {
  double complex c;
  = double d, sine, cosine;

  d =3D z*n;
  printf(" = cos,sin: %+f %+f\n", cos(d), sin(d));
  = __sincos(d, &sine, &cosine);
  = printf("__sincos: %+f %+f\n", cosine, sine);
  c =3D = cexp(CMPLX(0.0, d));
  = printf("    cexp: %+f %+f\n", creal(c), = cimag(c));
}

double z =3D 0.0, p =3D +1.0, n =3D = -1.0;


--- configure.ac.orig = 2017-02-18 08:35:06.000000000 -0800
+++ configure.ac 2017-02-18 08:35:26.000000000 = -0800
@@ -1152,8 +1152,9 = @@
 #   = asinh, acosh, atanh, trunc - C99 standard, generally not available = on
 #   =                     =          older systems
 #   sincos - GLIBC = extension
+#   __sincos - = APPLE extension
 #
-AC_CHECK_FUNCS(asinh acosh atanh copysign finite sincos = trunc)
+AC_CHECK_FUNCS(asinh = acosh atanh copysign finite sincos __sincos trunc)
 
 # C99 specifies isinf and isnan as = macros.
 # HP-UX = provides only macros, no functions.
--- libguile/numbers.c.patch.labs = 2017-02-18 08:31:21.000000000 -0800
+++ libguile/numbers.c 2017-02-18 08:34:18.000000000 = -0800
@@ -9109,6 +9109,8 = @@
      = details.  */
 #if= (defined HAVE_SINCOS) && (defined __GLIBC__) && = (defined _GNU_SOURCE)
  =  sincos (ang, &s, &c);
+#elif (defined HAVE___SINCOS)
+  __sincos (ang, &s, = &c);
 #else
  =  s =3D sin (ang);
  =  c =3D cos (ang);
= --Apple-Mail=_1F9A3EBB-9475-4C82-B9EF-39C4681D7900 Content-Disposition: attachment; filename=sincos.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="sincos.patch" Content-Transfer-Encoding: 7bit --- configure.ac.orig 2017-02-18 08:35:06.000000000 -0800 +++ configure.ac 2017-02-18 08:35:26.000000000 -0800 @@ -1152,8 +1152,9 @@ # asinh, acosh, atanh, trunc - C99 standard, generally not available on # older systems # sincos - GLIBC extension +# __sincos - APPLE extension # -AC_CHECK_FUNCS(asinh acosh atanh copysign finite sincos trunc) +AC_CHECK_FUNCS(asinh acosh atanh copysign finite sincos __sincos trunc) # C99 specifies isinf and isnan as macros. # HP-UX provides only macros, no functions. --- libguile/numbers.c.patch.labs 2017-02-18 08:31:21.000000000 -0800 +++ libguile/numbers.c 2017-02-18 08:34:18.000000000 -0800 @@ -9109,6 +9109,8 @@ details. */ #if (defined HAVE_SINCOS) && (defined __GLIBC__) && (defined _GNU_SOURCE) sincos (ang, &s, &c); +#elif (defined HAVE___SINCOS) + __sincos (ang, &s, &c); #else s = sin (ang); c = cos (ang); --Apple-Mail=_1F9A3EBB-9475-4C82-B9EF-39C4681D7900 Content-Transfer-Encoding: 7bit Content-Type: text/html; charset=us-ascii

--Apple-Mail=_1F9A3EBB-9475-4C82-B9EF-39C4681D7900-- --Apple-Mail=_A118C0A3-D324-47B9-9844-79DF6C0C3EB2-- ------------=_1487711462-25741-1--