[PATCH] sort: support sorting decimal numbers correctly

From: Jakob Kramer <jakob.kramer_AT_gmx.de>
Date: Sat, 31 Jan 2015 19:12:18 +0100

sorry not to have used strtold from the beginning
---
 sort.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/sort.c b/sort.c
index d46a84b..31c3f7d 100644
--- a/sort.c
+++ b/sort.c
_AT_@ -168,6 +168,7 @@ linecmp(const char **a, const char **b)
 {
 	char *s1, *s2;
 	int res = 0;
+	long double x, y;
 	struct kdlist *node;
 
 	for (node = head; node && res == 0; node = node->next) {
_AT_@ -176,12 +177,15 @@ linecmp(const char **a, const char **b)
 
 		/* if -u is given, don't use default key definition
 		 * unless it is the only one */
-		if (uflag && node == tail && head != tail)
+		if (uflag && node == tail && head != tail) {
 			res = 0;
-		else if (node->keydef.flags & MOD_N)
-			res = strtol(s1, 0, 10) - strtol(s2, 0, 10);
-		else
+		} else if (node->keydef.flags & MOD_N) {
+			x = strtold(s1, NULL);
+			y = strtold(s2, NULL);
+			res = x < y ? -1 : x > y;
+		} else {
 			res = strcmp(s1, s2);
+		}
 
 		if (node->keydef.flags & MOD_R)
 			res = -res;
-- 
1.9.1
--------------050208090504050402060107--
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Sat Jan 31 2015 - 19:24:07 CET