summaryrefslogtreecommitdiff
path: root/Zend/zend_operators.c
diff options
context:
space:
mode:
authorZeev Suraski <zeev@php.net>2000-05-17 17:08:25 +0000
committerZeev Suraski <zeev@php.net>2000-05-17 17:08:25 +0000
commit760a17729e0709288f31dc6689a1576269c8e746 (patch)
treeffba1d8a08cea04e19f4b61f5118bf99c4013bf1 /Zend/zend_operators.c
parent4a4d185637d7e1fb0903df635e73dc451e3649c6 (diff)
downloadphp-git-760a17729e0709288f31dc6689a1576269c8e746.tar.gz
Normalize results of compare_function()
Diffstat (limited to 'Zend/zend_operators.c')
-rw-r--r--Zend/zend_operators.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c
index cb641d8e04..f8357a900d 100644
--- a/Zend/zend_operators.c
+++ b/Zend/zend_operators.c
@@ -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;