EN
C++ - minimum and maximum double value
7
points
In this short article, we would like to show how to get in C++ minimal and maximal double value.
Quick solution:
// #include <limits>
double min = std::numeric_limits<double>::min(); // minimum positive value
double max = std::numeric_limits<double>::max(); // maximum positive value
double lowest = std::numeric_limits<double>::lowest(); // minimum negative value
Practical example
In the below example we use numeric_limits API that provides current max and min values.
#include <limits>
#include <iostream>
using namespace std;
int main()
{
double min = numeric_limits<double>::min(); // minimum positive value
double max = numeric_limits<double>::max(); // maximum positive value
double lowest = std::numeric_limits<double>::lowest(); // minimum negative value
cout << "min: " << min << endl; // min: 2.22507e-308
cout << "max: " << max << endl; // max: 1.79769e+308
cout << "lowest: " << lowest << endl; // lowest: -1.79769e+308
return 0;
}
Output:
min: 2.22507e-308
max: 1.79769e+308
lowest: -1.79769e+308