Skip to content

<cmath>: can't pass integer types to std::isnan #4747

Description

Describe the bug

std::isnan fails to compile when passed an argument of integer type.

Command-line test case

#include <cmath>
bool b = std::isnan(0);

results in:

/opt/compiler-explorer/windows/10.0.10240.0/ucrt/math.h(403): error C2668: 'fpclassify': ambiguous call to overloaded function
/opt/compiler-explorer/windows/10.0.10240.0/ucrt/math.h(288): note: could be 'int fpclassify(long double) noexcept'
/opt/compiler-explorer/windows/10.0.10240.0/ucrt/math.h(283): note: or       'int fpclassify(double) noexcept'
/opt/compiler-explorer/windows/10.0.10240.0/ucrt/math.h(278): note: or       'int fpclassify(float) noexcept'
/opt/compiler-explorer/windows/10.0.10240.0/ucrt/math.h(403): note: while trying to match the argument list '(int)'
<source>(3): note: see reference to function template instantiation 'bool isnan<int>(_Ty) noexcept' being compiled
        with
        [
            _Ty=int
        ]
Compiler returned: 2

Live on compiler explorer

Expected behavior

<cmath> is required to provide sufficient additional overloads such that std::isnan can be applied to integer types, with the behavior that the integer value is implicitly converted to double (so that std::isnan(0) returns false). This doesn't appear to work under MSVC.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedSomething works now, yay!

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions