X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_51 X-Spam-Check-By: sourceware.org Message-ID: <18485.99838.qm@web25008.mail.ukl.yahoo.com> Date: Wed, 1 Apr 2009 19:26:04 +0000 (GMT) From: Marco Atzeri Subject: R: Fwd: complex number To: cygwin AT cygwin DOT com, "Mark J. Reed" MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com --- 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 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 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/