numeric-limits

Templates and std::numeric_limits

I have a class called Atomic which is basically an _Atomic_word plus methods that call the gcc atomic builtins. class Atomic{ mutable volatile _Atomic_word value_; public: Atomic(int value = 0): value_(value) {} **** blah blah **** }; I would like std::numeric_limits<Atomic> to instantiate to std::numeric_limits<underly...

maximum value of int

is there any code to find the maximum value of integer (which is acccording to the compiler) in c/c++ like Integer.MaxValue function in java ...

warning C4003 and errors C2589 and C2059 on: x = std::numeric_limits<int>::max();

This line works correctly in a small test program, but in the program for which I want it, I get the following compiler complaints: #include <limits> x = std::numeric_limits<int>::max(); c:\...\x.cpp(192) : warning C4003: not enough actual parameters for macro 'max' c:\...\x.cpp(192) : error C2589: '(' : illegal token on right side of...

Looping on a closed range

How would you fix this code? template <typename T> void closed_range(T begin, T end) { for (T i = begin; i <= end; ++i) { // do something } } T is constrained to be an integer type, can be the wider of such types and can be signed or unsigned begin can be numeric_limits<T>::min() end can be numeric_limits<T>::max() (i...

Why is FLT_MIN equal to zero?

limits.h specifies limits for non-floating point math types, e.g. INT_MIN and INT_MAX. These values are the most negative and most positive values that you can represent using an int. In float.h, there are definitions for FLT_MIN and FLT_MAX. If you do the following: NSLog(@"%f %f", FLT_MIN, FLT_MAX); You get the following output: F...