nan()
Anonymous contributor
Anonymous contributor3 total contributions
Anonymous contributor
Published Nov 17, 2022
Contribute to Docs
The nan()
function returns a quiet NaN
(not a number) value of type double
.
Syntax
nan(x)
The x
argument is a character string that can be used by library implementations to distinguish different NaN
values.
Example
The following example uses the nan()
function to return a NaN
value:
#include <iostream>#include <cmath>using namespace std;int main() {double number1 = 1.0;double number2 = nan("");if (isnan(number1)) {cout << "number1 is not a number";}if (isnan(number2)) {cout << "number2 is not a number";}return 0;}
This produces the following output:
number2 is not a number
Codebyte Example
The following example is runnable and uses the nan()
function to return a NaN
value:
All contributors
- Anonymous contributorAnonymous contributor3 total contributions
- Anonymous contributor
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.