Tobi Smith
Tobi Smith

Reputation: 63

C++ isnan() won't work in an if-statement?

I am trying to check, if a variable is not a number. I tried to use std::isnan() for that.

Here's the code that I thought would work:

#include <iostream>
#include <cstddef>
#include <cmath>

int main()
{
    int num = 1;
    if (std::isnan(num))
    {
        std::cout << num << " is a Number" << std::endl;
    }
    else
    {
        std::cout << num << " is a Number" << std::endl;
    }
}

The error it is giving is the following:

"fpclassify": Ambiguous call of an overloaded function

I can't understand why that won't work as expected, seen on many websites as examples.

Here's also a screenshot of everything:

Screen

Upvotes: 0

Views: 40

Answers (0)

Related Questions