]> granicus.if.org Git - php/commitdiff
@Fix min/max behaviour (Thies)
authorStig Bakken <ssb@php.net>
Tue, 9 Nov 1999 07:59:50 +0000 (07:59 +0000)
committerStig Bakken <ssb@php.net>
Tue, 9 Nov 1999 07:59:50 +0000 (07:59 +0000)
#Andrei: I left the convert_to_long() in there, it doesn't really make
#much of a difference.

ext/standard/basic_functions.c

index 3c96046675791be007434a69c9e0082791d75cfd..79419db65e3971915631682df968b39fb3e5adb5 100644 (file)
@@ -738,47 +738,28 @@ static int array_data_compare(const void *a, const void *b)
 {
        Bucket *f;
        Bucket *s;
+       pval result;
        pval *first;
        pval *second;
-       double dfirst, dsecond;
-
        f = *((Bucket **) a);
        s = *((Bucket **) b);
-
        first = *((pval **) f->pData);
        second = *((pval **) s->pData);
 
-       if ((first->type == IS_LONG || first->type == IS_DOUBLE) &&
-               (second->type == IS_LONG || second->type == IS_DOUBLE)) {
-               if (first->type == IS_LONG) {
-                       dfirst = (double) first->value.lval;
-               } else {
-                       dfirst = first->value.dval;
-               }
-               if (second->type == IS_LONG) {
-                       dsecond = (double) second->value.lval;
-               } else {
-                       dsecond = second->value.dval;
-               }
-               if (dfirst < dsecond) {
-                       return -1;
-               } else if (dfirst == dsecond) {
-                       return 0;
-               } else {
-                       return 1;
-               }
-       }
-       if ((first->type == IS_LONG || first->type == IS_DOUBLE) &&
-               second->type == IS_STRING) {
+    if (compare_function(&result, first, second) == FAILURE) {
+        return 0;
+    } 
+
+       convert_to_long(&result);
+       if (result.value.lval < 0) {
                return -1;
-       } else if ((first->type == IS_STRING) &&
-                          (second->type == IS_LONG || second->type == IS_DOUBLE)) {
+       } else if (result.value.lval > 0) {
                return 1;
+       } else {
+               return 0;
        }
-       if (first->type == IS_STRING && second->type == IS_STRING) {
-               return strcmp(first->value.str.val, second->value.str.val);
-       }
-       return 0;                                       /* Anything else is equal as it can't be compared */
 }
 
 static int array_reverse_data_compare(const void *a, const void *b)