From: Matt Wette <matt.wette@gmail.com>
To: 25785@debbugs.gnu.org
Subject: bug#25785: scm_c_make_polar broken on APPLE
Date: Sat, 18 Feb 2017 09:37:54 -0800 [thread overview]
Message-ID: <E9380031-ED2A-48A5-BB52-B09E192B3912@gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 2368 bytes --]
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, “gcc -O2” turns sin(), cos() into cexp(), since cexp(i*x) = cos(x) + i*sin(x):
gcc -O0 =>
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 =>
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 = z*n;
printf(" cos,sin: %+f %+f\n", cos(d), sin(d));
__sincos(d, &sine, &cosine);
printf("__sincos: %+f %+f\n", cosine, sine);
c = cexp(CMPLX(0.0, d));
printf(" cexp: %+f %+f\n", creal(c), cimag(c));
}
double z = 0.0, p = +1.0, n = -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 = sin (ang);
c = cos (ang);
[-- Attachment #2.1: Type: text/html, Size: 14246 bytes --]
[-- Attachment #2.2: sincos.patch --]
[-- Type: application/octet-stream, Size: 920 bytes --]
--- 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);
[-- Attachment #2.3: Type: text/html, Size: 546 bytes --]
next reply other threads:[~2017-02-18 17:37 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-18 17:37 Matt Wette [this message]
2017-02-18 21:30 ` bug#25785: scm_c_make_polar broken Matt Wette
2017-02-21 21:10 ` bug#25785: scm_c_make_polar broken on APPLE Andy Wingo
2017-02-21 21:10 ` Andy Wingo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E9380031-ED2A-48A5-BB52-B09E192B3912@gmail.com \
--to=matt.wette@gmail.com \
--cc=25785@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).