[LLVMbugs] [Bug 8532] New: "clang can't do complex arithmetic"

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Nov 2 13:02:55 PDT 2010


http://llvm.org/bugs/show_bug.cgi?id=8532

           Summary: "clang can't do complex arithmetic"
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: FreeBSD
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: ed at 80386.nl
                CC: llvmbugs at cs.uiuc.edu


This is a bug report based on an observation from one of our Clang users at
FreeBSD, Steve Kargl. Complete discussion thread can be found here:

http://lists.freebsd.org/pipermail/freebsd-toolchain/2010-November/000001.html

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.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list