clang can't do complex arithmetic

Roman Divacky rdivacky at freebsd.org
Tue Nov 2 18:49:19 UTC 2010


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 at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-toolchain
> To unsubscribe, send any mail to "freebsd-toolchain-unsubscribe at freebsd.org"


More information about the freebsd-toolchain mailing list