This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

R: Fwd: complex number


--- Mer 1/4/09, Mark J. Reed  ha scritto:

> Da: Mark J. Reed 
> Oggetto: Fwd: complex number
> A: cygwin@cygwin.com
> Data: Mercoledì 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
> > > >
> > > > ? double
> > > > ? cabs(z)
> > > > ? struct complex z;
> > > > ? {
> > > > ? ? return hypot(z.x, z.y);
> > > > ? }
> > > >
> 
> 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).? 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.
> 
> Did you determine that the C++ std::complex::abs() method
> winds up
> calling cabs() eventually, or was that a guess?? It's
> strange, because
> calling hypot(a, b) directly yields the correct result.
> 
> --
> Mark J. Reed <markjreed@gmail.com>

Hi Mark,
I suspect the following:

in cygwin  there is old (ancient) declaration 
double cabs()

that probably means any type of argument expecting 
a struct or a pointer to it.

C++ refuse empty argument list and use its own from
 
/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 = __z.real();
      _Tp __y = __z.imag();
      const _Tp __s = std::max(abs(__x), abs(__y));
      if (__s == _Tp())  // well ...
        return __s;
      __x /= __s; 
      __y /= __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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]