From: "Tim Davis" <>
Newsgroups: comp.soft-sys.matlab
Subject: Re: floating point calc differences between Matlab and C?
Date: Tue, 31 Mar 2009 21:45:04 +0000 (UTC)
Organization: University of Florida
Lines: 17
Message-ID: <gqu2t0$r3d$>
References: <gqeaq9$56$> <gqec1m$c0$> <gqepkn$s8r$> <gqfcth$o5u$> <gqrp7g$nu0$> <gqs317$8gs$>
Reply-To: "Tim Davis" <>
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: 1238535904 27757 (31 Mar 2009 21:45:04 GMT)
NNTP-Posting-Date: Tue, 31 Mar 2009 21:45:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 45902
Xref: comp.soft-sys.matlab:529181

"Roger Stafford" <> wrote in message ...

>   In the division of complex numbers, you should not expect the error in the real part of the result to be within a bit or so within that real part.  The same can be true with the imaginary part though not at the same time.  All you can hope for is that each of these errors amounts to only a bit or so within the absolute value of the complex result.  If you look at the expressions for the real and imaginary parts, you can see why:
>  real((a+b*i)/(c+d*i)) = (a*c+b*d)/sqrt(c^2+d^2)
>  imag((a+b*i)/(c+d*i)) = (b*c-a*d)/sqrt(c^2+d^2)
> The quantity a*c+b*d or b*c-a*d can be very small compared with the values in a, b, c, and d if a+b*i and c+d*i are nearly orthogonal or nearly parallel, respectively, in the complex plane and thereby lose relative accuracy if this is taken with respect to the real or imaginary results, respectively.  As I say, the errors should be compared with the result's absolute value instead.

Roger brings up the basic problem.  Those expressions are not the best way to do complex division.  See for example Algorithm 116, ACM Transactions on Mathematical Software, by R. L. Smith (1962).  It tries to avoid underflow and overflow.  You can see my implementation of it here:

It's very different than the standard algebraic description.  My guess is that the gcc compiler might have less accurate code for complex division than it could have.

Getting these basic operations (complex multiplication and division) done correctly is a fine art.