This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: this seems to lost (complex norm, abs)
- To: Theodore Papadopoulo <Theodore dot Papadopoulo at sophia dot inria dot fr>
- Subject: Re: this seems to lost (complex norm, abs)
- From: Philip Martin <philip_martin at ntlworld dot com>
- Date: 20 Sep 2001 20:12:53 +0100
- Cc: lfarkas at mindmaker dot hu, STDC++ <libstdc++ at sources dot redhat dot com>
- References: <200109201810.f8KIA7M03044@mururoa.inria.fr>
Theodore Papadopoulo <Theodore.Papadopoulo@sophia.inria.fr> writes:
> First the norm of a complex<T> is not a T when T is integer.
Yes it is. This isn't maths, its C++. For example
int mass = 3;
int velocity = 4;
int kinetic_energy = mass * velocity * velocity / 2;
might all have different dimensions but can all be integers.
That said I can't see any circumstances when the following is less
accurate or more prone to overflow, and it is always more efficient:
2001-09-20 Philip Martin <philip_martin@nltworld.com>
* include/bits/std_complex.h: don't use abs() in norm()
--- libstdc++-v3/include/bits/std_complex.h Wed Aug 15 14:11:42 2001
+++ libstdc++-v3-new/include/bits/std_complex.h Thu Sep 20 19:28:54 2001
@@ -421,8 +421,7 @@
inline _Tp
norm(const complex<_Tp>& __z)
{
- _Tp __res = abs(__z);
- return __res * __res;
+ return __z.real() * __z.real() + __z.imag() * __z.imag();
}
template<typename _Tp>