18
18
#include "private.h"
19
19
#include <stddef.h>
20
20
21
- void bc_round (bc_num num , zend_long precision , zend_long mode , bc_num * result )
21
+ /* Returns the scale of the value after rounding. */
22
+ size_t bc_round (bc_num num , zend_long precision , zend_long mode , bc_num * result )
22
23
{
23
24
/* clear result */
24
25
bc_free_num (result );
@@ -43,19 +44,19 @@ void bc_round(bc_num num, zend_long precision, zend_long mode, bc_num *result)
43
44
case PHP_ROUND_HALF_ODD :
44
45
case PHP_ROUND_TOWARD_ZERO :
45
46
* result = bc_copy_num (BCG (_zero_ ));
46
- return ;
47
+ return 0 ;
47
48
48
49
case PHP_ROUND_CEILING :
49
50
if (num -> n_sign == MINUS ) {
50
51
* result = bc_copy_num (BCG (_zero_ ));
51
- return ;
52
+ return 0 ;
52
53
}
53
54
break ;
54
55
55
56
case PHP_ROUND_FLOOR :
56
57
if (num -> n_sign == PLUS ) {
57
58
* result = bc_copy_num (BCG (_zero_ ));
58
- return ;
59
+ return 0 ;
59
60
}
60
61
break ;
61
62
@@ -67,7 +68,7 @@ void bc_round(bc_num num, zend_long precision, zend_long mode, bc_num *result)
67
68
68
69
if (bc_is_zero (num )) {
69
70
* result = bc_copy_num (BCG (_zero_ ));
70
- return ;
71
+ return 0 ;
71
72
}
72
73
73
74
/* If precision is -3, it becomes 1000. */
@@ -78,7 +79,7 @@ void bc_round(bc_num num, zend_long precision, zend_long mode, bc_num *result)
78
79
}
79
80
(* result )-> n_value [0 ] = 1 ;
80
81
(* result )-> n_sign = num -> n_sign ;
81
- return ;
82
+ return 0 ;
82
83
}
83
84
84
85
/* Just like bcadd('1', '1', 4) becomes '2.0000', it pads with zeros at the end if necessary. */
@@ -90,7 +91,7 @@ void bc_round(bc_num num, zend_long precision, zend_long mode, bc_num *result)
90
91
(* result )-> n_sign = num -> n_sign ;
91
92
memcpy ((* result )-> n_value , num -> n_value , num -> n_len + num -> n_scale );
92
93
}
93
- return ;
94
+ return precision ;
94
95
}
95
96
96
97
/*
@@ -222,7 +223,12 @@ void bc_round(bc_num num, zend_long precision, zend_long mode, bc_num *result)
222
223
}
223
224
224
225
check_zero :
225
- if (bc_is_zero (* result )) {
226
- (* result )-> n_sign = PLUS ;
226
+ {
227
+ size_t scale = (* result )-> n_scale ;
228
+ if (bc_is_zero (* result )) {
229
+ (* result )-> n_sign = PLUS ;
230
+ (* result )-> n_scale = 0 ;
231
+ }
232
+ return scale ;
227
233
}
228
234
}
0 commit comments