File tree Expand file tree Collapse file tree 4 files changed +27
-3
lines changed Expand file tree Collapse file tree 4 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -110,6 +110,8 @@ int bc_compare(bc_num n1, bc_num n2);
110
110
111
111
char bc_is_zero (bc_num num );
112
112
113
+ char bc_is_zero_for_scale (bc_num num , int scale );
114
+
113
115
char bc_is_near_zero (bc_num num , int scale );
114
116
115
117
char bc_is_neg (bc_num num );
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ zend_string
50
50
int index , signch ;
51
51
52
52
/* Allocate the string memory. */
53
- signch = num -> n_sign != PLUS ; /* Number of sign chars. */
53
+ signch = num -> n_sign != PLUS && ! bc_is_zero_for_scale ( num , MIN ( num -> n_scale , scale )) ; /* Number of sign chars. */
54
54
if (scale > 0 )
55
55
str = zend_string_alloc (num -> n_len + scale + signch + 1 , 0 );
56
56
else
Original file line number Diff line number Diff line change 40
40
/* In some places we need to check if the number NUM is zero. */
41
41
42
42
char
43
- bc_is_zero (bc_num num )
43
+ bc_is_zero_for_scale (bc_num num , int scale )
44
44
{
45
45
int count ;
46
46
char * nptr ;
@@ -49,7 +49,7 @@ bc_is_zero (bc_num num)
49
49
if (num == BCG (_zero_ )) return TRUE;
50
50
51
51
/* Initialize */
52
- count = num -> n_len + num -> n_scale ;
52
+ count = num -> n_len + scale ;
53
53
nptr = num -> n_value ;
54
54
55
55
/* The check */
@@ -60,3 +60,9 @@ bc_is_zero (bc_num num)
60
60
else
61
61
return TRUE;
62
62
}
63
+
64
+ char
65
+ bc_is_zero (bc_num num )
66
+ {
67
+ return bc_is_zero_for_scale (num , num -> n_scale );
68
+ }
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Bug #78238 (BCMath returns "-0")
3
+ --EXTENSIONS--
4
+ bcmath
5
+ --FILE--
6
+ <?php
7
+ var_dump (bcadd ("0 " , "-0.1 " ));
8
+
9
+ $ a = bcmul ("0.9 " , "-0.1 " , 1 );
10
+ $ b = bcmul ("0.90 " , "-0.1 " , 1 );
11
+ var_dump ($ a , $ b );
12
+ ?>
13
+ --EXPECT--
14
+ string(1) "0"
15
+ string(3) "0.0"
16
+ string(3) "0.0"
You can’t perform that action at this time.
0 commit comments