How does sorting algorithms sort containers and ranges of floats?

  c++, floating-point, sorting

Since comparing floats is evil then if I have a container of floats and I sort it using some standard library sorting algorithm like std::sort then how does the algorithm sort them?

std::vector<float> vf{2.4f, 1.05f, 1.05f, 2.39f};
std::sort( vf.begin(), vf.end() );
  • So does the algorithm compare 1.05f and 1.05f?

  • Does it internally uses something like: std::fabs( 1.05f - 1.05f ) < 0.1;?

  • Does this apply too to containers of doubles? Thank you!

Source: Windows Questions C++

LEAVE A COMMENT