By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
 446,194 Members | 847 Online
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,194 IT Pros & Developers. It's quick & easy.

# NaN question

 P: n/a How do i write an if statement that checks the results of a operation to see if its nan (not a number) or not? *using g++, a linux complier* I tried double x; if (x == nan) { code here } but nan isnt a built in defined varible. I cant say: if (x == 0) because that means it holds a value of a number. I am performing a complex mathimatical equation on diffrent variables and need to create a if statement for the times that my equation returns NaN. Thanks! -Cephas Jul 22 '05 #1
Share this Question
3 Replies

 P: n/a "Cephas" wrote in message news:59************************@posting.google.com ... How do i write an if statement that checks the results of a operation to see if its nan (not a number) or not? *using g++, a linux complier* I tried double x; if (x == nan) { code here } but nan isnt a built in defined varible. I cant say: if (x == 0) because that means it holds a value of a number. I am performing a complex mathimatical equation on diffrent variables and need to create a if statement for the times that my equation returns NaN. Thanks! -Cephas there should be an isnan or isNaN function kicking around somewhere that you can use to test a given value Tom Jul 22 '05 #2

 P: n/a ce******@lycos.com (Cephas) wrote in message news:<59************************@posting.google.co m>... How do i write an if statement that checks the results of a operation to see if its nan (not a number) or not? *using g++, a linux complier* //... #include //... if( isnan(0/0) ) cout << "0/0 = nan" << endl; else cout << "0/0 = " << (0/0) << endl; Try man isnan for isinf() and finite(). Jul 22 '05 #3

 P: n/a "Cephas" wrote in message news:59************************@posting.google.com ... In the C header math.h (or cmath in C++) there is a macro called isnan. Jul 22 '05 #4

### This discussion thread is closed

Replies have been disabled for this discussion.