Sort spam scores numerically even when they are in the form of floats
authorDavid Champion <dgc@uchicago.edu>
Wed, 22 Nov 2006 23:08:01 +0000 (23:08 +0000)
committerDavid Champion <dgc@uchicago.edu>
Wed, 22 Nov 2006 23:08:01 +0000 (23:08 +0000)
or negative numbers.

sort.c

diff --git a/sort.c b/sort.c
index 06a44d28d16c5d48cb60aca42e1680211403b7c0..48a5b312025307f402acf34b82c30e22c06d9f55 100644 (file)
--- a/sort.c
+++ b/sort.c
@@ -160,6 +160,7 @@ int compare_spam (const void *a, const void *b)
   char   *aptr, *bptr;
   int     ahas, bhas;
   int     result = 0;
+  double  difference;
 
   /* Firstly, require spam attributes for both msgs */
   /* to compare. Determine which msgs have one.     */
@@ -183,8 +184,11 @@ int compare_spam (const void *a, const void *b)
   /* Both have spam attrs. */
 
   /* preliminary numeric examination */
-  result = (strtoul((*ppa)->env->spam->data, &aptr, 10) -
-            strtoul((*ppb)->env->spam->data, &bptr, 10));
+  difference = (strtod((*ppa)->env->spam->data, &aptr) -
+                strtod((*ppb)->env->spam->data, &bptr));
+
+  /* map double into comparison (-1, 0, or 1) */
+  result = (difference < 0.0 ? -1 : difference > 0.0 ? 1 : 0);
 
   /* If either aptr or bptr is equal to data, there is no numeric    */
   /* value for that spam attribute. In this case, compare lexically. */