cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
Checking not a number value
Checking not a number value
Nov 23, 2016 at 8:44pm UTC
ajlahmed
(21)
Hi
I have a variable X, this variable sometimes returns not a number (nan). I want to check this variable if it is a not number or a number and make this variable equal to zero if it is not a number (nan). Anyone can help me plz..
Regards
Nov 23, 2016 at 8:51pm UTC
Peter87
(11234)
You can use std::isnan.
http://en.cppreference.com/w/cpp/numeric/math/isnan
Nov 23, 2016 at 9:10pm UTC
ajlahmed
(21)
As I am beginner, can u plz check this code:
if (isnan( double X ))
{
X=0;
}
Nov 23, 2016 at 10:00pm UTC
Peter87
(11234)
1
2
3
4
if
(std::isnan(X)) { X = 0; }
Don't forget to include <cmath>.
Last edited on
Nov 23, 2016 at 10:01pm UTC
Nov 23, 2016 at 10:31pm UTC
ajlahmed
(21)
Okay.
Thanks it is working now.
Topic archived. No new replies allowed.