diff options
author | Jim Meyering <jim@meyering.net> | 1999-05-22 12:52:14 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1999-05-22 12:52:14 +0000 |
commit | 9e48e223db6152a714ae651a505f963f3f3801d6 (patch) | |
tree | d7d5221fbdbd09b5953ccd22c7104b399e378188 /src | |
parent | 59b22bd05824b05fb37ba52187e26b82dfd7236e (diff) | |
download | coreutils-9e48e223db6152a714ae651a505f963f3f3801d6.tar.xz |
(general_numcompare): Put exceptional cases
first, not last, to be consistent with -M.
Diffstat (limited to 'src')
-rw-r--r-- | src/sort.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/src/sort.c b/src/sort.c index 7dd0ac6ef..f8f0467c1 100644 --- a/src/sort.c +++ b/src/sort.c @@ -460,7 +460,6 @@ zaptemp (const char *name) } #ifdef ENABLE_NLS -/* Initialize the character class tables. */ static int struct_month_cmp (const void *m1, const void *m2) @@ -532,6 +531,8 @@ memcoll (char *s1, int s1len, char *s2, int s2len) #endif /* NLS */ +/* Initialize the character class tables. */ + static void inittables (void) { @@ -1076,21 +1077,21 @@ general_numcompare (const char *sa, const char *sb) double a = strtod (sa, &ea); double b = strtod (sb, &eb); - /* Put conversion errors at the end of the collating sequence. */ + /* Put conversion errors at the start of the collating sequence. */ if (sa == ea) - return eb - sb; + return sb == eb ? 0 : -1; if (sb == eb) - return -1; - - /* Put NaNs after numbers but before conversion errors; sort them by - internal bit-pattern, for lack of a more portable alternative. - Don't test specially for the case where a is a NaN but b is not, - since the conditional at the end of this function does the right - thing for that case. */ - if (b != b) - return a == a ? -1 : memcmp ((char *) &a, (char *) &b, sizeof a); - - return a < b ? -1 : a != b; + return 1; + + /* Sort numbers in the usual way, where -0 == +0. Put NaNs after + conversion errors but before numbers; sort them by internal + bit-pattern, for lack of a more portable alternative. */ + return (a < b ? -1 + : a > b ? 1 + : a == b ? 0 + : b == b ? -1 + : a == a ? 1 + : memcmp ((char *) &a, (char *) &b, sizeof a)); } /* Return an integer in 1..12 of the month name S with length LEN. |