Languages
[Edit]
EN

C++ - minimum and maximum double value

7 points
Created by:
Walter
586

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

 

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
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