Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'll double check - maybe the checking code only gets called when a custom comparator is provided, not the default < which would be used there.


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.


> 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.


or the aptly-named -funsafe-math-optimizations... fun and safe math optimizations, what could go wrong :^p


Neat, TIL. Thanks!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: