From: David Champion Date: Wed, 22 Nov 2006 23:08:01 +0000 (+0000) Subject: Sort spam scores numerically even when they are in the form of floats X-Git-Tag: mutt-1-5-14-rel~30 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4d27207d7872d6a2eb487cab104b79f2f3c00b0b;p=mutt Sort spam scores numerically even when they are in the form of floats or negative numbers. --- diff --git a/sort.c b/sort.c index 06a44d28..48a5b312 100644 --- 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. */