Date: Tue, 2 Nov 2010 19:32:35 +0100 From: Roman Divacky <rdivacky@freebsd.org> To: Steve Kargl <sgk@troutmask.apl.washington.edu> Cc: freebsd-toolchain@freebsd.org Subject: Re: clang can't do complex arithmetic Message-ID: <20101102183235.GA36920@freebsd.org> In-Reply-To: <20101102033421.GA49157@troutmask.apl.washington.edu> References: <20101102033421.GA49157@troutmask.apl.washington.edu>
next in thread | previous in thread | raw e-mail | index | archive | help
this reproduces with TOT clang/llvm. Can you please file a bug against clang? http://llvm.org/bugs/ they generally fix things very fast. thank you! On Mon, Nov 01, 2010 at 08:34:21PM -0700, Steve Kargl wrote: > 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 > _______________________________________________ > freebsd-toolchain@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-toolchain > To unsubscribe, send any mail to "freebsd-toolchain-unsubscribe@freebsd.org"
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20101102183235.GA36920>