From owner-freebsd-toolchain@FreeBSD.ORG Tue Nov 2 03:34:21 2010 Return-Path: Delivered-To: freebsd-toolchain@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BDD891065693 for ; Tue, 2 Nov 2010 03:34:21 +0000 (UTC) (envelope-from sgk@troutmask.apl.washington.edu) Received: from troutmask.apl.washington.edu (troutmask.apl.washington.edu [128.208.78.105]) by mx1.freebsd.org (Postfix) with ESMTP id 9CDE38FC17 for ; Tue, 2 Nov 2010 03:34:21 +0000 (UTC) Received: from troutmask.apl.washington.edu (localhost.apl.washington.edu [127.0.0.1]) by troutmask.apl.washington.edu (8.14.4/8.14.4) with ESMTP id oA23YLsA049245 for ; Mon, 1 Nov 2010 20:34:21 -0700 (PDT) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.14.4/8.14.4/Submit) id oA23YLBS049244 for freebsd-toolchain@freebsd.org; Mon, 1 Nov 2010 20:34:21 -0700 (PDT) (envelope-from sgk) Date: Mon, 1 Nov 2010 20:34:21 -0700 From: Steve Kargl To: freebsd-toolchain@freebsd.org Message-ID: <20101102033421.GA49157@troutmask.apl.washington.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.3i Subject: clang can't do complex arithmetic X-BeenThere: freebsd-toolchain@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Maintenance of FreeBSD's integrated toolchain List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Nov 2010 03:34:21 -0000 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 #include #include 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