summaryrefslogtreecommitdiff
path: root/ext/bcmath/libbcmath/src
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bcmath/libbcmath/src')
-rw-r--r--ext/bcmath/libbcmath/src/bcmath.h3
-rw-r--r--ext/bcmath/libbcmath/src/num2str.c13
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! */