nan()
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 contributor
Contribute to Docs
- 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.
Learn C++ on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn C++
Learn C++ — a versatile programming language that’s important for developing software, games, databases, and more.Beginner Friendly11 hours