C++ is nan
doubel a = 0 ;
bool isnan_a = std::isnan(a) || std::isnan(-a);
C++ is nan
doubel a = 0 ;
bool isnan_a = std::isnan(a) || std::isnan(-a);
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
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us