Code behaves differently if compiled with MSVC vs GCC
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
Research direction
Reproduce the sample with MSVC 19 and GCC 12, then compare include/boost/numeric/interval/detail/c99sub_rounding_control.hpp with include/boost/numeric/interval/detail/msvc_rounding_control.hpp. Review how each platform configures floating-point rounding and exception controls, and determine the intended cross-platform behavior before changing either implementation.
Written by the indexing model from the issue text.
Description
VS 19 vs GCC 12
If you build and run the following sample with both compilers:
#include <fenv.h>
#include <iostream>
#pragma warning(push)
#pragma warning(disable : 4702)
#include <boost/numeric/interval.hpp>
#pragma warning(pop)
/// An interval of doubles [lower,upper)
using Interval = boost::numeric::interval<double,boost::numeric::interval_lib::policies<boost::numeric::interval_lib::rounded_math<double>,boost::numeric::interval_lib::checking_strict<double>>>;
/// An interval from -DBL_MAX to +DBL_MAX
const inline Interval InfiniteInterval =
Interval(std::numeric_limits<double>::lowest(), std::numeric_limits<double>::max());
int main(void)
{
#ifdef _WIN32
unsigned int current_word = 0;
_controlfp_s(¤t_word, 0, _MCW_EM);
#else
feenableexcept(FE_ALL_EXCEPT);
#endif
auto i = InfiniteInterval;
boost::numeric::width(i);
std::cerr << "The end" << std::endl;
}
You will see how it fails with FP exception on linux, but never fails on windows.
The reason is simple:
On linux we adjust only rounding mode https://github.com/boostorg/interval/blob/2eda7413ac16dd4158005446438daf8a7e435dd9/include/boost/numeric/interval/detail/c99sub_rounding_control.hpp#L27
But on windows in addition to rounding we also mask all the FP exceptions (turn off corresponding flags) https://github.com/boostorg/interval/blob/2eda7413ac16dd4158005446438daf8a7e435dd9/include/boost/numeric/interval/detail/msvc_rounding_control.hpp#L93 because we use _MCW_EM | _MCW_RC instead of _MCW_RC only.
Shouldn't both systems set the same FP settings? If yes - what should they adjust? Both systems should adjust rounding only, or both should adjust rounding and exception masking?
If we only want to change rounding control bits - it is enough to remove _MCW_EM | part of that line and both systems will throw FP exception.
- Dominant language
- C++
- Stars
- 31
- Forks
- 49
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 3
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from boostorg/interval
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 5/5 Over a week Newbie friendliness 10/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
All issues in boostorg/interval
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
espressif/esp-matter#1874 ·
-
cudev: Fix MSVC build failures with 64-bit integers (int64_t/uint64_t) in vec_traits.hppPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
opencv/opencv_contrib#4231 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
MiSTer-devel/Main_MiSTer#1341 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
linux-test-project/lcov#552 ·
Maintainers usually reply within 1 day