"nan c++ example" Code Answer's
You're definitely familiar with the best coding language C++ that developers use to develop their projects and they get all their queries like "nan c++ example" answered properly. Developers are finding an appropriate answer about nan c++ example related to the C++ coding language. By visiting this online portal developers get answers concerning C++ codes question like nan c++ example. Enter your desired code related query in the search bar and get every piece of information about C++ code related question on nan c++ example.
nan c++ example
#include <iostream>
#include <cmath>
using namespace std;
// main() section
int main()
{
double nanValue;
//generating generic NaN value
//by passing an empty string
nanValue = nan("");
//printing the value
cout<<"nanValue: "<<nanValue<<endl;
return 0;
}
cpp nan value
What is NaN ?
NaN, acronym for “Not a Number” is an exception
which usually occurs in the caseswhen an expression
results in a number that can’t be represented.
For example square root of negative numbers.
// C++ code to demonstrate NaN exception
#include<iostream>
#include<cmath> // for sqrt()
using namespace std;
int main()
{
float a = 2, b = -2;
// Prints the number (1.41421)
cout << sqrt(a) << endl;
// Prints "nan" exception
// sqrt(-2) is complex number
cout << sqrt(b) << endl;
return 0;
}
Output:
1.41421
-nan
All those coders who are working on the C++ based application and are stuck on nan c++ example can get a collection of related answers to their query. Programmers need to enter their query on nan c++ example related to C++ code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about nan c++ example for the programmers working on C++ code while coding their module. Coders are also allowed to rectify already present answers of nan c++ example while working on the C++ language code. Developers can add up suggestions if they deem fit any other answer relating to "nan c++ example". Visit this developer's friendly online web community, CodeProZone, and get your queries like nan c++ example resolved professionally and stay updated to the latest C++ updates.