mirror of
https://github.com/php/php-src.git
synced 2024-11-26 03:16:33 +08:00
Normalize results of compare_function()
This commit is contained in:
parent
4a4d185637
commit
760a17729e
@ -42,6 +42,9 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define NORMALIZE_BOOL(n) \
|
||||
((n) ? (((n)>0) ? 1 : -1) : 0)
|
||||
|
||||
#if WITH_BCMATH
|
||||
#include "ext/bcmath/number.h"
|
||||
#endif
|
||||
@ -959,7 +962,7 @@ ZEND_API int compare_function(zval *result, zval *op1, zval *op2)
|
||||
zendi_convert_to_boolean(op1, op1_copy, result);
|
||||
zendi_convert_to_boolean(op2, op2_copy, result);
|
||||
result->type = IS_LONG;
|
||||
result->value.lval = op1->value.lval - op2->value.lval;
|
||||
result->value.lval = NORMALIZE_BOOL(op1->value.lval-op2->value.lval);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@ -968,13 +971,14 @@ ZEND_API int compare_function(zval *result, zval *op1, zval *op2)
|
||||
|
||||
if (op1->type == IS_LONG && op2->type == IS_LONG) {
|
||||
result->type = IS_LONG;
|
||||
result->value.lval = op1->value.lval - op2->value.lval;
|
||||
result->value.lval = NORMALIZE_BOOL(op1->value.lval-op2->value.lval);
|
||||
return SUCCESS;
|
||||
}
|
||||
if ((op1->type == IS_DOUBLE || op1->type == IS_LONG)
|
||||
&& (op2->type == IS_DOUBLE || op2->type == IS_LONG)) {
|
||||
result->value.dval = (op1->type == IS_LONG ? (double) op1->value.lval : op1->value.dval) - (op2->type == IS_LONG ? (double) op2->value.lval : op2->value.dval);
|
||||
result->type = IS_DOUBLE;
|
||||
result->value.lval = NORMALIZE_BOOL(result->value.dval);
|
||||
result->type = IS_LONG;
|
||||
return SUCCESS;
|
||||
}
|
||||
if ((op1->type==IS_ARRAY || op1->type==IS_OBJECT)
|
||||
@ -1351,6 +1355,7 @@ ZEND_API void zendi_smart_strcmp(zval *result, zval *s1, zval *s2)
|
||||
str2num(&first,s1->value.str.val,100); /* this scale should do */
|
||||
str2num(&second,s2->value.str.val,100); /* ditto */
|
||||
result->value.lval = bc_compare(first,second);
|
||||
result->value.lval = NORMALIZE_BOOL(result->value.lval);
|
||||
result->type = IS_LONG;
|
||||
free_num(&first);
|
||||
free_num(&second);
|
||||
@ -1363,13 +1368,16 @@ ZEND_API void zendi_smart_strcmp(zval *result, zval *s1, zval *s2)
|
||||
dval2 = strtod(s2->value.str.val, NULL);
|
||||
}
|
||||
result->value.dval = dval1 - dval2;
|
||||
result->type = IS_DOUBLE;
|
||||
result->value.lval = NORMALIZE_BOOL(result->value.dval);
|
||||
result->type = IS_LONG;
|
||||
} else { /* they both have to be long's */
|
||||
result->value.lval = lval1 - lval2;
|
||||
result->value.lval = NORMALIZE_BOOL(result->value.lval);
|
||||
result->type = IS_LONG;
|
||||
}
|
||||
} else {
|
||||
result->value.lval = zend_binary_zval_strcmp(s1, s2);
|
||||
result->value.lval = NORMALIZE_BOOL(result->value.lval);
|
||||
result->type = IS_LONG;
|
||||
}
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user