Mail Archives: cygwin/2009/04/01/14:26:22
--- Mer 1/4/09, Mark J. Reed ha scritto:
> Da: Mark J. Reed=20
> Oggetto: Fwd: complex number
> A: cygwin AT cygwin DOT com
> Data: Mercoled=EC 1 Aprile 2009, 20:47
> On Wed, Apr 1, 2009 at 1:30 PM,
> Corinna Vinschen wrote:
> >
> > > > That's the result of the newlib function
> which is defined
> > > > as
> > > >
> > > > =A0 double
> > > > =A0 cabs(z)
> > > > =A0 struct complex z;
> > > > =A0 {
> > > > =A0 =A0 return hypot(z.x, z.y);
> > > > =A0 }
> > > >
>=20
> That's from the newlib source code, I assume? While the
> function
> cabs() exists inside newlib, and is declared as an extern
> in math.h,
> it's not documented, nor is there a prototype for it or a
> declaration
> of "struct complex" that I can find anywhere in the
> installed headers
> (just the "complex" typedef in the gcc headers, whose
> structure
> doesn't match the above).=A0 l Yet somehow the compiler is
> doing some
> sort of typechecking anyway and rejecting everything I try
> to pass as
> a parameter, so I can't validate the return value of cabs.
>=20
> Did you determine that the C++ std::complex::abs() method
> winds up
> calling cabs() eventually, or was that a guess?=A0 It's
> strange, because
> calling hypot(a, b) directly yields the correct result.
>=20
> --
> Mark J. Reed <markjreed AT gmail DOT com>
Hi Mark,
I suspect the following:
in cygwin there is old (ancient) declaration=20
double cabs()
that probably means any type of argument expecting=20
a struct or a pointer to it.
C++ refuse empty argument list and use its own from
=20
/usr/lib/gcc/i686-pc-cygwin/4.3.2/include/c++/complex
// 26.2.7/3 abs(__z): Returns the magnitude of __z.
template<typename _Tp>
inline _Tp
__complex_abs(const complex<_Tp>& __z)
{
_Tp __x =3D __z.real();
_Tp __y =3D __z.imag();
const _Tp __s =3D std::max(abs(__x), abs(__y));
if (__s =3D=3D _Tp()) // well ...
return __s;
__x /=3D __s;=20
__y /=3D __s;
return __s * sqrt(__x * __x + __y * __y);
}
Regards
Marco
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
- Raw text -