Why does numeric_limits::min return a negative value for int, but positive values for e.g. float and double?
#include<iostream>
#include<limits>
using namespace std;
int main() {
cout << "int: " << numeric_limits<int>::min() << " "
<< "float: " << numeric_limits<float>::min() << " "
<< "double: " << numeric_limits<double>::min() << "\n";
return 0;
}
Output:
int: -2147483648 float: 1.17549e-38 double: 2.22507e-308
From cppreference:
Returns the minimum finite value representable by the numeric type T.
For floating-point types with denormalization, min returns the minimum positive normalized value. Note that this behavior may be unexpected, especially when compared to the behavior of min for integral types. To find the value that has no values less than it, use
numeric_limits::lowest
.min is only meaningful for bounded types and for unbounded unsigned types, that is, types that represent an infinite set of negative values have no meaningful minimum.