Computer >> Computer tutorials >  >> Programming >> C++

What is NaN in C++?


The NaN is the abbreviation of Not a Number. It indicates undefined or non-representable floating point elements. One example of NaN is square root of some negative number, or result of 0/0.

Example

#include <iostream>
#include <cmath>
using namespace std;
int main() {
   cout >> "Square root of -5: " >> sqrt(-5) >> endl;
}

Output

Square root of -5: nan