diff options
author | Christoph M. Becker <cmbecker69@gmx.de> | 2017-09-18 15:04:44 +0200 |
---|---|---|
committer | Christoph M. Becker <cmbecker69@gmx.de> | 2017-09-18 15:21:22 +0200 |
commit | 73af7a847c5f08d32802d41fc45ed4b01ec9fb9c (patch) | |
tree | 528ea68ade394772d0640509eab2104cefb24efe /ext/bcmath/libbcmath/src | |
parent | f63bfea105cd2d1285a1189c197d8371cad5f403 (diff) | |
parent | 870ed5106d6274905b5aa4341429deef12c92e55 (diff) | |
download | php-git-73af7a847c5f08d32802d41fc45ed4b01ec9fb9c.tar.gz |
Merge branch 'pull-request/2742'
* pull-request/2742:
Fixed bug #66364 (BCMath bcmul ignores scale parameter)
Diffstat (limited to 'ext/bcmath/libbcmath/src')
-rw-r--r-- | ext/bcmath/libbcmath/src/bcmath.h | 3 | ||||
-rw-r--r-- | ext/bcmath/libbcmath/src/num2str.c | 13 |
2 files changed, 10 insertions, 6 deletions
diff --git a/ext/bcmath/libbcmath/src/bcmath.h b/ext/bcmath/libbcmath/src/bcmath.h index f0ab49fc52..78868edcb3 100644 --- a/ext/bcmath/libbcmath/src/bcmath.h +++ b/ext/bcmath/libbcmath/src/bcmath.h @@ -110,7 +110,7 @@ _PROTOTYPE(void bc_init_num, (bc_num *num)); _PROTOTYPE(void bc_str2num, (bc_num *num, char *str, int scale)); -_PROTOTYPE(zend_string *bc_num2str, (bc_num num)); +_PROTOTYPE(zend_string *bc_num2str_ex, (bc_num num, int scale)); _PROTOTYPE(void bc_int2num, (bc_num *num, int val)); @@ -155,5 +155,6 @@ _PROTOTYPE(void bc_out_of_memory, (void)); #define bc_new_num(length, scale) _bc_new_num_ex((length), (scale), 0) #define bc_free_num(num) _bc_free_num_ex((num), 0) +#define bc_num2str(num) bc_num2str_ex((num), (num->n_scale)) #endif diff --git a/ext/bcmath/libbcmath/src/num2str.c b/ext/bcmath/libbcmath/src/num2str.c index c72a924933..7316d32a14 100644 --- a/ext/bcmath/libbcmath/src/num2str.c +++ b/ext/bcmath/libbcmath/src/num2str.c @@ -41,8 +41,9 @@ /* Convert a numbers to a string. Base 10 only.*/ zend_string -*bc_num2str (num) +*bc_num2str_ex (num, scale) bc_num num; + int scale; { zend_string *str; char *sptr; @@ -51,8 +52,8 @@ zend_string /* Allocate the string memory. */ signch = ( num->n_sign == PLUS ? 0 : 1 ); /* Number of sign chars. */ - if (num->n_scale > 0) - str = zend_string_alloc(num->n_len + num->n_scale + signch + 1, 0); + if (scale > 0) + str = zend_string_alloc(num->n_len + scale + signch + 1, 0); else str = zend_string_alloc(num->n_len + signch, 0); if (str == NULL) bc_out_of_memory(); @@ -67,11 +68,13 @@ zend_string *sptr++ = BCD_CHAR(*nptr++); /* Now the fraction. */ - if (num->n_scale > 0) + if (scale > 0) { *sptr++ = '.'; - for (index=0; index<num->n_scale; index++) + for (index=0; index<scale && index<num->n_scale; index++) *sptr++ = BCD_CHAR(*nptr++); + for (index = num->n_scale; index<scale; index++) + *sptr++ = BCD_CHAR(0); } /* Terminate the string and return it! */ |