mirror of
https://github.com/php/php-src.git
synced 2026-03-24 08:12:21 +01:00
@@ -110,6 +110,8 @@ int bc_compare(bc_num n1, bc_num n2);
|
||||
|
||||
char bc_is_zero(bc_num num);
|
||||
|
||||
char bc_is_zero_for_scale(bc_num num, int scale);
|
||||
|
||||
char bc_is_near_zero(bc_num num, int scale);
|
||||
|
||||
char bc_is_neg(bc_num num);
|
||||
|
||||
@@ -50,7 +50,7 @@ zend_string
|
||||
int index, signch;
|
||||
|
||||
/* Allocate the string memory. */
|
||||
signch = num->n_sign != PLUS; /* Number of sign chars. */
|
||||
signch = num->n_sign != PLUS && !bc_is_zero_for_scale(num, MIN(num->n_scale, scale)); /* Number of sign chars. */
|
||||
if (scale > 0)
|
||||
str = zend_string_alloc(num->n_len + scale + signch + 1, 0);
|
||||
else
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
/* In some places we need to check if the number NUM is zero. */
|
||||
|
||||
char
|
||||
bc_is_zero (bc_num num)
|
||||
bc_is_zero_for_scale (bc_num num, int scale)
|
||||
{
|
||||
int count;
|
||||
char *nptr;
|
||||
@@ -49,7 +49,7 @@ bc_is_zero (bc_num num)
|
||||
if (num == BCG(_zero_)) return TRUE;
|
||||
|
||||
/* Initialize */
|
||||
count = num->n_len + num->n_scale;
|
||||
count = num->n_len + scale;
|
||||
nptr = num->n_value;
|
||||
|
||||
/* The check */
|
||||
@@ -60,3 +60,9 @@ bc_is_zero (bc_num num)
|
||||
else
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
char
|
||||
bc_is_zero (bc_num num)
|
||||
{
|
||||
return bc_is_zero_for_scale(num, num->n_scale);
|
||||
}
|
||||
|
||||
16
ext/bcmath/tests/bug78238.phpt
Normal file
16
ext/bcmath/tests/bug78238.phpt
Normal file
@@ -0,0 +1,16 @@
|
||||
--TEST--
|
||||
Bug #78238 (BCMath returns "-0")
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
var_dump(bcadd("0", "-0.1"));
|
||||
|
||||
$a = bcmul("0.9", "-0.1", 1);
|
||||
$b = bcmul("0.90", "-0.1", 1);
|
||||
var_dump($a, $b);
|
||||
?>
|
||||
--EXPECT--
|
||||
string(1) "0"
|
||||
string(3) "0.0"
|
||||
string(3) "0.0"
|
||||
Reference in New Issue
Block a user