pollita         Tue Feb  4 14:02:06 2003 EDT

  Modified files:              (Branch: PHP_4_3)
    /php4/ext/bcmath    bcmath.c 
  Log:
  MFH(r-1.48) (Bug#13551)
  
  
Index: php4/ext/bcmath/bcmath.c
diff -u php4/ext/bcmath/bcmath.c:1.39.4.3 php4/ext/bcmath/bcmath.c:1.39.4.4
--- php4/ext/bcmath/bcmath.c:1.39.4.3   Tue Dec 31 11:34:10 2002
+++ php4/ext/bcmath/bcmath.c    Tue Feb  4 14:02:02 2003
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: bcmath.c,v 1.39.4.3 2002/12/31 16:34:10 sebastian Exp $ */
+/* $Id: bcmath.c,v 1.39.4.4 2003/02/04 19:02:02 pollita Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -110,6 +110,20 @@
        php_info_print_table_end();
 }
 
+/* {{{ php_str2num
+   Convert to bc_num detecting scale */
+static void php_str2num(bc_num *num, char *str) {
+       char *p;
+
+       if (!(p = strchr(str, '.'))) {
+               bc_str2num(num, str, 0 TSRMLS_CC);
+               return;
+       }
+
+       bc_str2num(num, str, strlen(p+1) TSRMLS_CC);
+}
+/* }}} */
+
 /* {{{ proto string bcadd(string left_operand, string right_operand [, int scale])
    Returns the sum of two arbitrary precision numbers */
 PHP_FUNCTION(bcadd)
@@ -140,9 +154,10 @@
        bc_init_num(&first TSRMLS_CC);
        bc_init_num(&second TSRMLS_CC);
        bc_init_num(&result TSRMLS_CC);
-       bc_str2num(&first, Z_STRVAL_PP(left), scale TSRMLS_CC);
-       bc_str2num(&second, Z_STRVAL_PP(right), scale TSRMLS_CC);
+       php_str2num(&first, Z_STRVAL_PP(left));
+       php_str2num(&second, Z_STRVAL_PP(right));
        bc_add (first, second, &result, scale);
+       result->n_scale = scale;
        Z_STRVAL_P(return_value) = bc_num2str(result);
        Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value));
        Z_TYPE_P(return_value) = IS_STRING;
@@ -183,9 +198,10 @@
        bc_init_num(&first TSRMLS_CC);
        bc_init_num(&second TSRMLS_CC);
        bc_init_num(&result TSRMLS_CC);
-       bc_str2num(&first, Z_STRVAL_PP(left), scale TSRMLS_CC);
-       bc_str2num(&second, Z_STRVAL_PP(right), scale TSRMLS_CC);
+       php_str2num(&first, Z_STRVAL_PP(left));
+       php_str2num(&second, Z_STRVAL_PP(right));
        bc_sub (first, second, &result, scale);
+       result->n_scale = scale;
        Z_STRVAL_P(return_value) = bc_num2str(result);
        Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value));
        Z_TYPE_P(return_value) = IS_STRING;
@@ -226,9 +242,10 @@
        bc_init_num(&first TSRMLS_CC);
        bc_init_num(&second TSRMLS_CC);
        bc_init_num(&result TSRMLS_CC);
-       bc_str2num(&first, Z_STRVAL_PP(left), scale TSRMLS_CC);
-       bc_str2num(&second, Z_STRVAL_PP(right), scale TSRMLS_CC);
+       php_str2num(&first, Z_STRVAL_PP(left));
+       php_str2num(&second, Z_STRVAL_PP(right));
        bc_multiply (first, second, &result, scale TSRMLS_CC);
+       result->n_scale = scale;
        Z_STRVAL_P(return_value) = bc_num2str(result);
        Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value));
        Z_TYPE_P(return_value) = IS_STRING;
@@ -269,10 +286,11 @@
        bc_init_num(&first TSRMLS_CC);
        bc_init_num(&second TSRMLS_CC);
        bc_init_num(&result TSRMLS_CC);
-       bc_str2num(&first, Z_STRVAL_PP(left), scale TSRMLS_CC);
-       bc_str2num(&second, Z_STRVAL_PP(right), scale TSRMLS_CC);
+       php_str2num(&first, Z_STRVAL_PP(left));
+       php_str2num(&second, Z_STRVAL_PP(right));
        switch (bc_divide (first, second, &result, scale TSRMLS_CC)) {
                case 0: /* OK */
+                       result->n_scale = scale;
                        Z_STRVAL_P(return_value) = bc_num2str(result);
                        Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value));
                        Z_TYPE_P(return_value) = IS_STRING;
@@ -359,9 +377,10 @@
        bc_init_num(&first TSRMLS_CC);
        bc_init_num(&second TSRMLS_CC);
        bc_init_num(&result TSRMLS_CC);
-       bc_str2num(&first, Z_STRVAL_PP(left), scale TSRMLS_CC);
-       bc_str2num(&second, Z_STRVAL_PP(right), scale TSRMLS_CC);
+       php_str2num(&first, Z_STRVAL_PP(left));
+       php_str2num(&second, Z_STRVAL_PP(right));
        bc_raise (first, second, &result, scale TSRMLS_CC);
+       result->n_scale = scale;
        Z_STRVAL_P(return_value) = bc_num2str(result);
        Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value));
        Z_TYPE_P(return_value) = IS_STRING;
@@ -399,8 +418,9 @@
        }
        convert_to_string_ex(left);
        bc_init_num(&result TSRMLS_CC);
-       bc_str2num(&result, Z_STRVAL_PP(left), scale TSRMLS_CC);
+       php_str2num(&result, Z_STRVAL_PP(left));
        if (bc_sqrt (&result, scale TSRMLS_CC) != 0) {
+               result->n_scale = scale;
                Z_STRVAL_P(return_value) = bc_num2str(result);
                Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value));
                Z_TYPE_P(return_value) = IS_STRING;



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to