
Boost : 
From: lums_at_[hidden]
Date: 20011101 15:25:43
 In boost_at_y..., nbecker_at_f... wrote:
> In the current gcc, norm of complex is defined in terms of abs. I
> believe the definition should be changed to:
>
> norm(z) = sqr(real(z)) + sqr (imag (z))
>
> My reasons are:
>
> 1. More efficient
> 2. Works for complex<int> (important in DSP)
> 3. Possibly more accurate
>
> I have started a discussion on gcc_at_g... on this subject. I'm
> wondering if any of you have an opinion.
This definition doesn't look correct (and has accuracy problems).
Mathematically, the norm of a complex number should be
norm(z) = sqrt( sqr(real(z)) + sqr(imag(z)) )
For maximal accuracy, the standard approach is something like the
following:
if (abs(real(z)) > abs(imag(z))) {
norm(z) = real(z) * sqrt(1 + sqr(imag(z))/sqr(real(z)))
} else {
norm(z) = imag(z) * sqrt(1 + sqr(real(z))/sqr(imag(z)))
}
(This is all to be taken as pseudo code.)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk