Skip to content

Commit 1a7bf16

Browse files
committed
Ran wrong tests, fixed bug in impl; simplified
1 parent bb55290 commit 1a7bf16

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

ext/standard/string.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1223,9 +1223,17 @@ PHPAPI void php_implode(const zend_string *delim, zval *arr, zval *return_value)
12231223

12241224
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(arr), tmp) {
12251225
if (Z_TYPE_P(tmp) == IS_LONG) {
1226+
double val = Z_LVAL_P(tmp);
12261227
*++strptr = NULL;
12271228
((zend_long *) (strings + numelems))[strptr - strings] = Z_LVAL_P(tmp);
1228-
len += (int) log10(Z_LVAL_P(tmp) < 0 ? -100 * ((double) Z_LVAL_P(tmp) - 0.001) : 10 * ((double) Z_LVAL_P(tmp) + 0.01));
1229+
if (val < 0) {
1230+
val = -10 * val;
1231+
}
1232+
if (val < 10) {
1233+
len++;
1234+
} else {
1235+
len += (int) log10(10 * (double) val);
1236+
}
12291237
} else {
12301238
*++strptr = zval_get_string(tmp);
12311239
len += (*strptr)->len;

0 commit comments

Comments
 (0)