From: Stig Bakken Date: Tue, 9 Nov 1999 07:59:50 +0000 (+0000) Subject: @Fix min/max behaviour (Thies) X-Git-Tag: php-4.0b3_RC2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fdc6d630dbc86c2729b6f72318a4c0d1ee63b453;p=php @Fix min/max behaviour (Thies) #Andrei: I left the convert_to_long() in there, it doesn't really make #much of a difference. --- diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 3c96046675..79419db65e 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -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)