|
Boost Users : |
Subject: Re: [Boost-users] [STL] Is there a std::abs<>() function?
From: Max (loadcom_at_[hidden])
Date: 2008-12-23 19:34:28
Hello Anteru,
Yes, there exist several overloads of abs() functions or similar
but some of them with different name, say fabs, fabsf, etc.
This make it impossible to use it in generic code.
More specifically, I've ever written this code
cout << std::abs<int>(-1) << endl;
but, to my very surprise, I get 0!
I have
#include <cmath>
#include <cstdlib>
I'm using VS2003SP1 under WinXP_SP1
Thanks
B/Rgds
Max
----- Original Message -----
From: Anteru
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] [STL] Is there a std::abs<>() function?
Date: 2008-12-23 19:00:56
Max schrieb:
> Hello,
>
> It's strange to me that there seems not to be a std::abs<>() function
> in STL, with it I can write code like this:
>
> double d = std::abs(-1.0);
> int i = std::abs(-1);
>
> Does anybody else have the same feeling?
#include
double d = std::abs (-1.0);
cmath pulls the standard math functions into the std namespace, and adds
a few overloads.
See for example:
http://www.dinkumware.com/manuals/?manual=compleat&page=math.html#abs
Cheers,
Anteru
-------------------------------------------------------------------
ÐÂÀ˿ռ䡪¡ªÓëÅóÓÑ¿ªÐÄ·ÖÏíÍøÂçÐÂÉú»î£¡(http://space.sina.com.cn/ )
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net