3 ms·
After double check: std::sort(<some floats with NaNs>); indeed does not assert, what does assert (with a nice "invalid comparator" message in MSVC) is
by jcelerier 5y ago
After 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