isfinite() error

If I try using isfinite() in my code anywhere i get an error saying C2668 'fpclassify': ambiguous call to overloaded function.
I'm using visual studio.
How could I fix this?
Hello YogurtMan,

You could start by showing your code.

Did you include the "cmath" header file?

What value did you use for the parameter?

Andy

Edit:
Last edited on
Any code with isfinite() gives the same error
Example:
1
2
3
4
5
6
7
#include <iostream>
#include <cmath>

int main()
{
    bool a = isfinite(1);
}

I get the error regardless of using the cmath header or not.
1
2
3
4
5
6
7
8
#include <iostream>
#include <cmath>

int main()
{
    std::cout << std::isfinite(1) << '\n';
    std::cout << std::isfinite(INFINITY) << '\n';
}

Hello YogurtMan,

When I look at http://www.cplusplus.com/reference/cmath/isfinite/ it shows 3 overloaded functions for "float", double" and "long double", but nothing for an "int".

When I tested the function with an "int" I received the error that you first mentioned. When tested with a double it worked fine.

You need the "cmath" header file because that is where isfinite() comes from.

Try using a floating point number and see what happens.

Not sure what number would return "false" and everything I tried returned "true".

Andy
Not sure what number would return "false"

Floating point types can represent some values that aren't numbers. Those are
- positive and negative infinities
- representations of Not-a-Number (NaNs)
Last edited on
You've encountered a library bug - whichever library you're using is missing overloads for integral types. The documentation on this site is also wrong, although Cppreference has it right, specifying the presence of overload(s) of std::isfinite for every integral type:
https://en.cppreference.com/w/cpp/numeric/math/isfinite

These overloads are specified by the standard document:
http://www.eel.is/c++draft/cmath.syn#2

You're using Visual Studio, right? I'm pretty sure Andy is.

In the upcoming week, I'll look into addressing this issue in Microsoft's C++ standard library if it's not fixed already. I assume the problem extends through the whole of <cmath>.
Last edited on
not as much a bug as a different interpretation of the standard. Based on a lib-ext discussion last year, the way MS saw it is that the more specific clause [c.math.fpclass]/1 "Each function is overloaded for the three floating-point types" wins over the more generic clause [cmath.syn]/2 "there shall be additional overloads sufficient to ensure", while GCC saw it the opposite way.
Last edited on
@mbozzi,

Thank you for the input.

Yes YogurtMan said he uses VS and I use the 2017 Community version.

Further investigation lead me to the "corecrt_math.h" which appears to be set up to deal with only "float", "double" and "long double".

In the beginning I was more focused on the error than thinking about what Microsoft has left out, but I am seeing this to be more of a problem than I first realized.

I do understand that the reference section here is out of date. I should start using "cppreference.com" more often.

Andy
No errors or warnings now with VS 2019:
1
2
3
4
5
6
7
#include <iostream>
#include <cmath>

int main()
{
   bool a = isfinite(1.0);  // <----- explicitly use a floating point number (double), 1 is an integer
}

MS borked the C function to not allow for integers.

@mbozzi, with the latest VS 2019 update 16.5.1 this is still an "issue."
ah, here's Microsoft's issue about it https://github.com/microsoft/STL/issues/519
not as much a bug as a different interpretation of the standard

Okay, I see. Thanks @Cubbi.
Registered users can post here. Sign in or register to post.