I have some trouble understanding the following code:
double a = -1000;
double b = numeric_limits<double>::min();
if (a < b)
{
cout << "why?";
}
And the output is:
why?
How can -1000
be lower than numeric_limits<double>::min()
?
The C++ double can hold floating-point values of up to 15 digits taking up a space of 8 bytes in the memory. The range of the values that can be stored in a double type variable is 1.7E - 308 to 1.7E + 308.
Numeric limits type. Provides information about the properties of arithmetic types (either integral or floating-point) in the specific platform for which the library compiles. This class template is specialized for every fundamental arithmetic type, with its members describing the properties of type T .
Data types that supports std::numeric_limits() in C++ std::numeric_limits<int>::max() gives the maximum possible value we can store in type int. std::numeric_limits<unsigned int>::max()) gives the maximum possible value we can store in type unsigned int.
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. Header File: #include<limits>
It is because numeric_limits<double>::min();
is the lowest positive number expressible in double floating-point precision, not the most negative number.
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