Date: Mon, 1 Nov 2010 20:34:21 -0700 From: Steve Kargl <sgk@troutmask.apl.washington.edu> To: freebsd-toolchain@freebsd.org Subject: clang can't do complex arithmetic Message-ID: <20101102033421.GA49157@troutmask.apl.washington.edu>
index | next in thread | raw e-mail
It seems that clang can't do complex arithmetic.
Not to worry gcc in base can't do it either.
/*
* The C99 standard intends x+I*y to be used for this, but x+I*y is
* currently unusable because gcc introduces many overflow,
* underflow, sign and efficiency bugs by rewriting I*y as
* (0.0+I)*(y+0.0*I) and laboriously computing the full complex product.
* In particular, I*Inf is corrupted to NaN+I*Inf, and I*-0 is corrupted
* to -0.0+I*0.0.
*/
#include <complex.h>
#include <math.h>
#include <stdio.h>
int main(void) {
double complex z;
double x, y;
x = 0.;
y = 1. / x;
x = copysign(x, -1.);
/* z = 0 + i (-0) */
z = I * x;
printf("z = 0 + i (-0) = %e + i (%e)\n", creal(z), cimag(z));
/* z = 0 + i Inf */
z = I * y;
printf("z = 0 + i Inf = %e + i %e\n", creal(z), cimag(z));
}
troutmask:sgk[204] clang -o z z.c -lm && ./z
z = 0 + i (-0) = -0.000000e+00 + i (0.000000e+00)
z = 0 + i Inf = nan + i inf
If I read Annex G in n1256.pdf correctly, the z = I*inf = NaN + I inf
is going to really bad things because the NaN is going to propagate
if z is used in further computations. Annex G says z is an infinity.
--
Steve
home |
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20101102033421.GA49157>
