Problems with std::numeric_limits

Ed Smith-Rowland 3dw4rd@verizon.net
Sat Jan 14 05:43:00 GMT 2006


I have to admit I would have been bitten with this myself!!!!
I was right in the middle of putting stuff like this into the special 
functions.
I've been using:
    return std::numeric_limits<_Tp>::quiet_NaN();
    return std::numeric_limits<_Tp>::infinity();
I was going to use epsilon() for type-sensitive tests.

I tend to use a lot of const - although I could take these out.

I guess I am a bit horrified by this:

std::numeric_limits<float>::max() = 3.40282e+38
std::numeric_limits<const float>::max() = 0
std::numeric_limits<double>::max() = 1.79769e+308
std::numeric_limits<const double>::max() = 0
std::numeric_limits<long double>::max() = 1.79769e+308
std::numeric_limits<const long double>::max() = 0

std::numeric_limits<float>::epsilon() = 1.19209e-07
std::numeric_limits<const float>::epsilon() = 0
std::numeric_limits<double>::epsilon() = 2.22045e-16
std::numeric_limits<const double>::epsilon() = 0
std::numeric_limits<long double>::epsilon() = 4.94066e-324
std::numeric_limits<const long double>::epsilon() = 0

This did not correspond to my idea of minimum surprise :oP.

Anyhow,
How do you strip a type of cv qualifications so you can do generic 
mathematics???
I guess std::tr1::remove_cv<_Tp>::type would do it?

Ed Smith-Rowland





More information about the Libstdc++ mailing list