In the C++ Standard Library the value std::numeric_limits<T>::max()
is specified as a function. Further properties of a specific type are given as constants (likestd::numeric_limits<T>::is_signed
). All constants that are of type T
are given as functions, whereas all other constants are given as, well, constant values.
What's the rationale behind that?
std::numeric_limits::max(): The std::numeric_limits<T>::max() function is used to get the maximum finite value representable by the numeric type T. All arithmetic types are valid for type T.
std::numeric_limits ::digits in C++ with Example Return Value: The function std::numeric_limits<T>::digits returns the number of radix digits that the type can represent without loss of precision.
The C++ Standard Library header <limits> includes <climits> , which includes <limits. h> . Microsoft C also permits the declaration of sized integer variables, which are integral types of size 8-, 16-, 32- or 64-bits. For more information on sized integers in C, see Sized Integer Types.
Machine Epsilon is a machine-dependent floating point value that provides an upper bound on relative error due to rounding in floating point arithmetic. Mathematically, for each floating point type, it is equivalent to the difference between 1.0 and the smallest representable value that is greater than 1.0.
To expand on Neil's remark, std::numeric_limit<T>
is available for any number type including floating point numbers, and if you dig through the comp.lang.c++ thread, you'll see the mention that it might not be possible to define the static variables for floating point values.
So, for consistency they decided to put both integral and floating points behind methods.
It will change with C++0x, so there's hope.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With