Languages
[Edit]
EN

C++ - minimum and maximum double value

7 points
Created by:
Walter
316

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 value
double max = std::numeric_limits<double>::max();  // maximum 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 value
    double max = numeric_limits<double>::max();  // maximum value

    cout << "min: " << min << endl;
    cout << "max: " << max << endl;

    return 0;
}

Output:

min: 2.22507e-308
max: 1.79769e+308

 

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join