|
From: | Matt Wette |
Subject: | Re: GNU Guile 2.1.6 released (beta) [numbers.c] |
Date: | Fri, 20 Jan 2017 11:01:45 -0800 |
SCM +#ifdef __APPLE__ +__attribute__((optimize("O0"))) +#endif scm_c_make_polar (double mag, double ang) 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; Incidentally, the above program will not compile on my machine w/ gcc-6.3.0. “gcc -std=c11” or “gcc -std=c99” will not recognize the standard macro CMPLX(). |
[Prev in Thread] | Current Thread | [Next in Thread] |