3 ms·
MSVC and GCC's standard libraries implementations both have a debug mode which has been checking that for almost two decades.
by jcelerier 5y ago
MSVC and GCC's standard libraries implementations both have a debug mode which has been checking that for almost two decades.
- forrestthewoods 5y agoAre you sure about that? I just ran an MSVC test that calls std::sort on a std::vector<float> containing a variety of values including infinity, negative infinity, and NaN. I compiled and ran under debug mode. There were no errors or exceptions. The end result was extremely incorrect. Maybe there's some extra flag to turn on even more tests. I've always found MSVC STL to be completely impossible to use in debug mode for any real project.
- jcelerier 5y agoI'll double check - maybe the checking code only gets called when a custom comparator is provided, not the default < which would be used there.
- jcelerier 5y agoAfter double check: std::sort(<some floats with NaNs>); indeed does not assert, what does assert (with a nice "invalid comparator" message in MSVC) is std::sort(..., [] (float a, float b) { return a <= b; }); std::sort(..., [] (float a, float b) { return true; }); or anything else that is not a correct < implementation. I'd assume they don't want to introduce a check for the FP case as it would break pretty much all the code on earth which assumes that NaNs and Infs do not exist.
- forrestthewoods 5y agoNeat, TIL. Thanks!
- account42 5y ago> I'd assume they don't want to introduce a check for the FP case as it would break pretty much all the code on earth which assumes that NaNs and Infs do not exist. There are even compile flags that let the compiler assume that as well - some of them as benign sounding as -ffast-math or -Ofast.
- jcelerier 5y agoor the aptly-named -funsafe-math-optimizations... fun and safe math optimizations, what could go wrong :^p