What is NaN ?
NaN, acronym for “Not a Number” is an exception which usually occurs in the cases when an expression results in a number that can’t be represented. For example square root of negative numbers.
How to check for NaN ?
Method 1 : Using compare (“==”) operator.
In this method we check if a number is complex by comparing it with itself. If the result is true, then the number is not complex i.e., real. But if result is false, then “nan” is returned, i.e the number is complex.
Its a real number Its NaN
Method 2 : Using inbuilt function “isnan()”.
Another way to check for NaN is by using “isnan()” function, this function returns true if a number is complex else it returns false.
Its a real number Its NaN
This article is contributed by Manjeet Singh .If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Check if linked list is sorted (Iterative and Recursive)
- Check if given Preorder, Inorder and Postorder traversals are of same tree | Set 2
- Self assignment check in assignment operator
- How to check whether a number is in the range[low, high] using one comparison ?
- Quickly check if two STL vectors contain same elements or not
- Check if a key is present in a C++ map or unordered_map
- Check input character is alphabet, digit or special character
- Check for integer overflow on multiplication
- Check all the elements in an array are even using library in C++
- Check if a string can be formed from another string using given constraints
- C program to Check Whether a Number is Positive or Negative or Zero
- Program to check if two strings are same or not
- C program to check if a given string is Keyword or not
- Program to check if an Array is Palindrome or not using STL in C++
- Tr0ll 3 Walkthrough of Check the Flag or CTF Problem
- C++ program to check whether a String is a Pangram or not
- Quick way to check if all the characters of a string are same
- Check if X can give change to every person in the Queue
- Check if a given graph is Bipartite using DFS
- Pointers in C and C++ | Set 1 (Introduction, Arithmetic and Array)