microsoft / microsoft/STL

`<cmath>`: `constexpr` `fpclassify()` rejects signaling NaNs on x86

Open
#6,445 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug compiler
Dominant language
C++
Stars
11.1k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

Description

I could probably work around this in the library by using a bit_cast, but it would be better for the compiler to fix this bug.

D:\GitHub\STL\out\x86>cl
Microsoft (R) C/C++ Optimizing Compiler Version 19.52.36725 for x86 (PREVIEW)
Copyright (C) Microsoft Corporation.  All rights reserved.

usage: cl [ option... ] filename... [ /link linkoption... ]

D:\GitHub\STL\out\x86>type meow.cpp
#include <cassert>
#include <cmath>
#include <limits>

#ifndef _M_IX86
static_assert(false, "Use x86 to repro this failure!");
#endif

constexpr bool test() {
    assert(std::fpclassify(std::numeric_limits<double>::signaling_NaN()) == FP_NAN);
    return true;
}

int main() {
    static_assert(test());
}
D:\GitHub\STL\out\x86>cl /EHsc /nologo /W4 /std:c++latest /Zc:cmath meow.cpp
meow.cpp
meow.cpp(15): error C2131: expression did not evaluate to a constant
D:\GitHub\STL\out\x86\out\inc\__msvc_math.hpp(321): note: failure was caused by a library call raising a floating-point exception
meow.cpp(15): note: the call stack of the evaluation (the oldest call first) is
meow.cpp(15): note: while evaluating function 'bool test(void)'
meow.cpp(10): note: while evaluating function 'int _Msvc_math::fpclassify(double) noexcept'

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the meow.cpp reproducer and run the shown x86 cl command using /std:c++latest and /Zc:cmath. Inspect the constexpr evaluation path reported through __msvc_math.hpp:321 and determine why signaling_NaN() causes a floating-point exception. Done means the static_assert succeeds for x86 without that constant-evaluation failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.