Topic: Defect Report: TR1/C++0x: fabs(complex<T>) redundant / wrongly


Author: petebecker@acm.org (Pete Becker)
Date: Mon, 25 Sep 2006 16:43:01 GMT
Raw View
Stefan Gro=DFe Pawig wrote:
>=20
> If on the other hand the intention was to provide the intended
> functionality of C99,

That was the intention. Code written for C99 should be easily portable=20
to C++. So I think you're right: the return type of fabs(const=20
complex<T>&) for C++ should be T.

> fabs() should be either declared deprecated
> or (for C++0X) removed from the standard, since the functionality
> is already provided by the corresponding overloads of abs().
>=20

That's a bit too drastic, since it would mean that C code using fabs=20
would have to be modified.

--=20

 -- Pete

Author of "The Standard C++ Library Extensions: a Tutorial and=20
Reference." For more information about this book, see=20
www.petebecker.com/tr1book.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: petebecker@acm.org (Pete Becker)
Date: Tue, 26 Sep 2006 02:30:08 GMT
Raw View
Stefan Gro=DFe Pawig wrote:
> petebecker@acm.org (Pete Becker) wrote:
>=20
> Nevertheless, if the return type of fabs(const complex<T>&) is
> changed from complex<T> to T, this leaves us with two functions
> that do exactly the same:
>   T abs(const complex<T>&)  and
>   T fabs(const complex<T>&).
>=20

Yes, but that's already the case for most of the math functions. The one=20
that takes double is overloaded to take float, double, and long double,=20
and we provide the C-compatible ones whose names end with f and l. For=20
example, in C++ we have:

 float cosf(float)
 float cos(float)
 double cos(double)
 long double cos(long double)
 long double cosl(long double)

The ones that take the same argument types do exactly the same thing.=20
That's so that C code will be easier to port to C++, and so that C++=20
code can take advantage of function overloading.

--=20

 -- Pete

Author of "The Standard C++ Library Extensions: a Tutorial and=20
Reference." For more information about this book, see=20
www.petebecker.com/tr1book.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]