Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The future of fpclassify.hpp #548

Open
jzmaddock opened this issue Feb 21, 2021 · 1 comment
Open

The future of fpclassify.hpp #548

jzmaddock opened this issue Feb 21, 2021 · 1 comment

Comments

@jzmaddock
Copy link
Collaborator

I'm opening this as a place for discussion really.

We currently have boost::math::fpclassify/isnan/isinf/isnormal etc which began life as workarounds for C++03 compilers, but they have another role: for IEEE conforming types they work even in the presence of -ffast-math.

Now, I have some dim recollection, that gcc/clang used to replace say std::isnan(x) with a literal false even with just -O3. And that we had some very inscrutable bug reports caused by this. However, that appears not to be the case with current releases, so perhaps this has been fixed/changed?

So... I'm undecided whether the boost functions should become synonyms for the std ones, but just wanted to flag the issue.

@NAThompson
Copy link
Collaborator

NAThompson commented Feb 21, 2021

Yeah replacing std::isnan(x) with false is the worst!

Here's a godbolt to play around with the compiler flags.

Summarizing:

  • gcc 10.2: -O3 -ffast-math -> std::isnan(x) always is false. However, the flag is -O3 -ffast-math -fno-finite-math-only gets the correct behavior.
  • icc appears to get it right no matter what the flag is.
  • clang 11 does the "wrong" thing with -O3 -ffast-math, and does the "right" thing with -O3 as well as -O3 -ffast-math -fno-finite-math-only .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants