sort: ensure NaN will not trip over comp_double()

In unlikely event of NaN being compared avoid exception.  If NaN appears in
input data it will be evaluated as equal with any value.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2018-07-23 21:41:59 +01:00
parent 27c70a0efe
commit 5027b50ade
No known key found for this signature in database
GPG key ID: A9553245FDE9B739

View file

@ -40,6 +40,7 @@
#include <config.h>
#include <math.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
@ -118,9 +119,14 @@ int rangecomp(const void *restrict r1, const void *restrict r2)
*/
int comp_double(double f1, double f2)
{
return f1 < f2 ? -1 : f1 > f2 ? 1 : 0;
if (isless(f1, f2))
return -1;
else if (isless(f2, f1))
return 1;
return 0;
}
/*! \brief Compare two range_t by their first_ip.
* \param r1,r2 Pointers to data to compare.
* \return Like strcmp.