PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/bcmath - bcmath.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 193 202 95.5 %
Date: 2014-09-19 Functions: 16 16 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 5                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2014 The PHP Group                                |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 3.01 of the PHP license,      |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.php.net/license/3_01.txt                                  |
      11             :    | If you did not receive a copy of the PHP license and are unable to   |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@php.net so we can mail you a copy immediately.               |
      14             :    +----------------------------------------------------------------------+
      15             :    | Author: Andi Gutmans <andi@zend.com>                                 |
      16             :    +----------------------------------------------------------------------+
      17             : */
      18             : 
      19             : /* $Id$ */
      20             : 
      21             : #ifdef HAVE_CONFIG_H
      22             : #include "config.h"
      23             : #endif
      24             : 
      25             : #include "php.h"
      26             : 
      27             : #if HAVE_BCMATH
      28             : 
      29             : #include "php_ini.h"
      30             : #include "ext/standard/info.h"
      31             : #include "php_bcmath.h"
      32             : #include "libbcmath/src/bcmath.h"
      33             : 
      34             : ZEND_DECLARE_MODULE_GLOBALS(bcmath)
      35             : static PHP_GINIT_FUNCTION(bcmath);
      36             : static PHP_GSHUTDOWN_FUNCTION(bcmath);
      37             : 
      38             : /* {{{ arginfo */
      39             : ZEND_BEGIN_ARG_INFO_EX(arginfo_bcadd, 0, 0, 2)
      40             :         ZEND_ARG_INFO(0, left_operand)
      41             :         ZEND_ARG_INFO(0, right_operand)
      42             :         ZEND_ARG_INFO(0, scale)
      43             : ZEND_END_ARG_INFO()
      44             : 
      45             : ZEND_BEGIN_ARG_INFO_EX(arginfo_bcsub, 0, 0, 2)
      46             :         ZEND_ARG_INFO(0, left_operand)
      47             :         ZEND_ARG_INFO(0, right_operand)
      48             :         ZEND_ARG_INFO(0, scale)
      49             : ZEND_END_ARG_INFO()
      50             : 
      51             : ZEND_BEGIN_ARG_INFO_EX(arginfo_bcmul, 0, 0, 2)
      52             :         ZEND_ARG_INFO(0, left_operand)
      53             :         ZEND_ARG_INFO(0, right_operand)
      54             :         ZEND_ARG_INFO(0, scale)
      55             : ZEND_END_ARG_INFO()
      56             : 
      57             : ZEND_BEGIN_ARG_INFO_EX(arginfo_bcdiv, 0, 0, 2)
      58             :         ZEND_ARG_INFO(0, left_operand)
      59             :         ZEND_ARG_INFO(0, right_operand)
      60             :         ZEND_ARG_INFO(0, scale)
      61             : ZEND_END_ARG_INFO()
      62             : 
      63             : ZEND_BEGIN_ARG_INFO(arginfo_bcmod, 0)
      64             :         ZEND_ARG_INFO(0, left_operand)
      65             :         ZEND_ARG_INFO(0, right_operand)
      66             : ZEND_END_ARG_INFO()
      67             : 
      68             : ZEND_BEGIN_ARG_INFO_EX(arginfo_bcpowmod, 0, 0, 3)
      69             :         ZEND_ARG_INFO(0, x)
      70             :         ZEND_ARG_INFO(0, y)
      71             :         ZEND_ARG_INFO(0, mod)
      72             :         ZEND_ARG_INFO(0, scale)
      73             : ZEND_END_ARG_INFO()
      74             : 
      75             : ZEND_BEGIN_ARG_INFO_EX(arginfo_bcpow, 0, 0, 2)
      76             :         ZEND_ARG_INFO(0, x)
      77             :         ZEND_ARG_INFO(0, y)
      78             :         ZEND_ARG_INFO(0, scale)
      79             : ZEND_END_ARG_INFO()
      80             : 
      81             : ZEND_BEGIN_ARG_INFO_EX(arginfo_bcsqrt, 0, 0, 1)
      82             :         ZEND_ARG_INFO(0, operand)
      83             :         ZEND_ARG_INFO(0, scale)
      84             : ZEND_END_ARG_INFO()
      85             : 
      86             : ZEND_BEGIN_ARG_INFO_EX(arginfo_bccomp, 0, 0, 2)
      87             :         ZEND_ARG_INFO(0, left_operand)
      88             :         ZEND_ARG_INFO(0, right_operand)
      89             :         ZEND_ARG_INFO(0, scale)
      90             : ZEND_END_ARG_INFO()
      91             : 
      92             : ZEND_BEGIN_ARG_INFO(arginfo_bcscale, 0)
      93             :         ZEND_ARG_INFO(0, scale)
      94             : ZEND_END_ARG_INFO()
      95             : 
      96             : /* }}} */
      97             : 
      98             : const zend_function_entry bcmath_functions[] = {
      99             :         PHP_FE(bcadd,                                                                   arginfo_bcadd)
     100             :         PHP_FE(bcsub,                                                                   arginfo_bcsub)
     101             :         PHP_FE(bcmul,                                                                   arginfo_bcmul)
     102             :         PHP_FE(bcdiv,                                                                   arginfo_bcdiv)
     103             :         PHP_FE(bcmod,                                                                   arginfo_bcmod)
     104             :         PHP_FE(bcpow,                                                                   arginfo_bcpow)
     105             :         PHP_FE(bcsqrt,                                                                  arginfo_bcsqrt)
     106             :         PHP_FE(bcscale,                                                                 arginfo_bcscale)
     107             :         PHP_FE(bccomp,                                                                  arginfo_bccomp)
     108             :         PHP_FE(bcpowmod,                                                                arginfo_bcpowmod)
     109             :         PHP_FE_END
     110             : };
     111             : 
     112             : zend_module_entry bcmath_module_entry = {
     113             :         STANDARD_MODULE_HEADER,
     114             :         "bcmath",
     115             :         bcmath_functions,
     116             :         PHP_MINIT(bcmath),
     117             :         PHP_MSHUTDOWN(bcmath),
     118             :         NULL,
     119             :         NULL,
     120             :         PHP_MINFO(bcmath),
     121             :         NO_VERSION_YET,
     122             :         PHP_MODULE_GLOBALS(bcmath),
     123             :         PHP_GINIT(bcmath),
     124             :     PHP_GSHUTDOWN(bcmath),
     125             :         NULL,
     126             :         STANDARD_MODULE_PROPERTIES_EX
     127             : };
     128             : 
     129             : #ifdef COMPILE_DL_BCMATH
     130             : ZEND_GET_MODULE(bcmath)
     131             : #endif
     132             : 
     133             : /* {{{ PHP_INI */
     134             : PHP_INI_BEGIN()
     135             :         STD_PHP_INI_ENTRY("bcmath.scale", "0", PHP_INI_ALL, OnUpdateLongGEZero, bc_precision, zend_bcmath_globals, bcmath_globals)
     136             : PHP_INI_END()
     137             : /* }}} */
     138             : 
     139             : /* {{{ PHP_GINIT_FUNCTION
     140             :  */
     141       20335 : static PHP_GINIT_FUNCTION(bcmath)
     142             : {
     143       20335 :         bcmath_globals->bc_precision = 0;
     144       20335 :         bc_init_numbers(TSRMLS_C);
     145       20335 : }
     146             : /* }}} */
     147             : 
     148             : /* {{{ PHP_GSHUTDOWN_FUNCTION
     149             :  */
     150       20369 : static PHP_GSHUTDOWN_FUNCTION(bcmath)
     151             : {
     152       20369 :         _bc_free_num_ex(&bcmath_globals->_zero_, 1);
     153       20369 :         _bc_free_num_ex(&bcmath_globals->_one_, 1);
     154       20369 :         _bc_free_num_ex(&bcmath_globals->_two_, 1);
     155       20369 : }
     156             : /* }}} */
     157             : 
     158             : /* {{{ PHP_MINIT_FUNCTION
     159             :  */
     160       20335 : PHP_MINIT_FUNCTION(bcmath)
     161             : {
     162       20335 :         REGISTER_INI_ENTRIES();
     163             : 
     164       20335 :         return SUCCESS;
     165             : }
     166             : /* }}} */
     167             : 
     168             : /* {{{ PHP_MSHUTDOWN_FUNCTION
     169             :  */
     170       20369 : PHP_MSHUTDOWN_FUNCTION(bcmath)
     171             : {
     172       20369 :         UNREGISTER_INI_ENTRIES();
     173             : 
     174       20369 :         return SUCCESS;
     175             : }
     176             : /* }}} */
     177             : 
     178             : /* {{{ PHP_MINFO_FUNCTION
     179             :  */
     180         143 : PHP_MINFO_FUNCTION(bcmath)
     181             : {
     182         143 :         php_info_print_table_start();
     183         143 :         php_info_print_table_row(2, "BCMath support", "enabled");
     184         143 :         php_info_print_table_end();
     185         143 :         DISPLAY_INI_ENTRIES();
     186         143 : }
     187             : /* }}} */
     188             : 
     189             : /* {{{ php_str2num
     190             :    Convert to bc_num detecting scale */
     191          72 : static void php_str2num(bc_num *num, char *str TSRMLS_DC)
     192             : {
     193             :         char *p;
     194             : 
     195          72 :         if (!(p = strchr(str, '.'))) {
     196          60 :                 bc_str2num(num, str, 0 TSRMLS_CC);
     197          60 :                 return;
     198             :         }
     199             : 
     200          12 :         bc_str2num(num, str, strlen(p+1) TSRMLS_CC);
     201             : }
     202             : /* }}} */
     203             : 
     204             : /* {{{ proto string bcadd(string left_operand, string right_operand [, int scale])
     205             :    Returns the sum of two arbitrary precision numbers */
     206          13 : PHP_FUNCTION(bcadd)
     207             : {
     208             :         char *left, *right;
     209          13 :         zend_long scale_param = 0;
     210             :         bc_num first, second, result;
     211             :         size_t left_len, right_len;
     212          13 :         int scale = BCG(bc_precision), argc = ZEND_NUM_ARGS();
     213             : 
     214          13 :         if (zend_parse_parameters(argc TSRMLS_CC, "ss|l", &left, &left_len, &right, &right_len, &scale_param) == FAILURE) {
     215           1 :                 return;
     216             :         }
     217             :         
     218          12 :         if (argc == 3) {
     219           5 :                 scale = (int) ((int)scale_param < 0) ? 0 : scale_param;
     220             :         }
     221             : 
     222          12 :         bc_init_num(&first TSRMLS_CC);
     223          12 :         bc_init_num(&second TSRMLS_CC);
     224          12 :         bc_init_num(&result TSRMLS_CC);
     225          12 :         php_str2num(&first, left TSRMLS_CC);
     226          12 :         php_str2num(&second, right TSRMLS_CC);
     227          12 :         bc_add (first, second, &result, scale);
     228             :         
     229          12 :         if (result->n_scale > scale) {
     230           1 :                 result->n_scale = scale;
     231             :         }
     232             :         
     233          12 :         RETVAL_STR(bc_num2str(result));
     234          12 :         bc_free_num(&first);
     235          12 :         bc_free_num(&second);
     236          12 :         bc_free_num(&result);
     237          12 :         return;
     238             : }
     239             : /* }}} */
     240             : 
     241             : /* {{{ proto string bcsub(string left_operand, string right_operand [, int scale])
     242             :    Returns the difference between two arbitrary precision numbers */
     243           4 : PHP_FUNCTION(bcsub)
     244             : {
     245             :         char *left, *right;
     246             :         size_t left_len, right_len;
     247           4 :         zend_long scale_param = 0;
     248             :         bc_num first, second, result;
     249           4 :         int scale = BCG(bc_precision), argc = ZEND_NUM_ARGS();
     250             : 
     251           4 :         if (zend_parse_parameters(argc TSRMLS_CC, "ss|l", &left, &left_len, &right, &right_len, &scale_param) == FAILURE) {
     252           1 :                 return;
     253             :         }
     254             :         
     255           3 :         if (argc == 3) {
     256           2 :                 scale = (int) ((int)scale_param < 0) ? 0 : scale_param;
     257             :         }
     258             : 
     259           3 :         bc_init_num(&first TSRMLS_CC);
     260           3 :         bc_init_num(&second TSRMLS_CC);
     261           3 :         bc_init_num(&result TSRMLS_CC);
     262           3 :         php_str2num(&first, left TSRMLS_CC);
     263           3 :         php_str2num(&second, right TSRMLS_CC);
     264           3 :         bc_sub (first, second, &result, scale);
     265             : 
     266           3 :         if (result->n_scale > scale) {
     267           0 :                 result->n_scale = scale;
     268             :         }
     269             : 
     270           3 :         RETVAL_STR(bc_num2str(result));
     271           3 :         bc_free_num(&first);
     272           3 :         bc_free_num(&second);
     273           3 :         bc_free_num(&result);
     274           3 :         return;
     275             : }
     276             : /* }}} */
     277             : 
     278             : /* {{{ proto string bcmul(string left_operand, string right_operand [, int scale])
     279             :    Returns the multiplication of two arbitrary precision numbers */
     280           5 : PHP_FUNCTION(bcmul)
     281             : {
     282             :         char *left, *right;
     283             :         size_t left_len, right_len;
     284           5 :         zend_long scale_param = 0;
     285             :         bc_num first, second, result;
     286           5 :         int scale = BCG(bc_precision), argc = ZEND_NUM_ARGS();
     287             : 
     288           5 :         if (zend_parse_parameters(argc TSRMLS_CC, "ss|l", &left, &left_len, &right, &right_len, &scale_param) == FAILURE) {
     289           1 :                 return;
     290             :         }
     291             :         
     292           4 :         if (argc == 3) {
     293           1 :                 scale = (int) ((int)scale_param < 0) ? 0 : scale_param;
     294             :         }
     295             :         
     296           4 :         bc_init_num(&first TSRMLS_CC);
     297           4 :         bc_init_num(&second TSRMLS_CC);
     298           4 :         bc_init_num(&result TSRMLS_CC);
     299           4 :         php_str2num(&first, left TSRMLS_CC);
     300           4 :         php_str2num(&second, right TSRMLS_CC);
     301           4 :         bc_multiply (first, second, &result, scale TSRMLS_CC);
     302             : 
     303           4 :         if (result->n_scale > scale) {
     304           0 :                 result->n_scale = scale;
     305             :         }
     306             : 
     307           4 :         RETVAL_STR(bc_num2str(result));
     308           4 :         bc_free_num(&first);
     309           4 :         bc_free_num(&second);
     310           4 :         bc_free_num(&result);
     311           4 :         return;
     312             : }
     313             : /* }}} */
     314             : 
     315             : /* {{{ proto string bcdiv(string left_operand, string right_operand [, int scale])
     316             :    Returns the quotient of two arbitrary precision numbers (division) */
     317           7 : PHP_FUNCTION(bcdiv)
     318             : {
     319             :         char *left, *right;
     320             :         size_t left_len, right_len;
     321           7 :         zend_long scale_param = 0;
     322             :         bc_num first, second, result;
     323           7 :         int scale = BCG(bc_precision), argc = ZEND_NUM_ARGS();
     324             : 
     325           7 :         if (zend_parse_parameters(argc TSRMLS_CC, "ss|l", &left, &left_len, &right, &right_len, &scale_param) == FAILURE) {
     326           1 :                 return;
     327             :         }
     328             :         
     329           6 :         if (argc == 3) {
     330           3 :                 scale = (int) ((int)scale_param < 0) ? 0 : scale_param;
     331             :         }
     332             :         
     333           6 :         bc_init_num(&first TSRMLS_CC);
     334           6 :         bc_init_num(&second TSRMLS_CC);
     335           6 :         bc_init_num(&result TSRMLS_CC);
     336           6 :         php_str2num(&first, left TSRMLS_CC);
     337           6 :         php_str2num(&second, right TSRMLS_CC);
     338             : 
     339           6 :         switch (bc_divide(first, second, &result, scale TSRMLS_CC)) {
     340             :                 case 0: /* OK */
     341           5 :                         if (result->n_scale > scale) {
     342           0 :                                 result->n_scale = scale;
     343             :                         }
     344           5 :                         RETVAL_STR(bc_num2str(result));
     345           5 :                         break;
     346             :                 case -1: /* division by zero */
     347           1 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Division by zero");
     348             :                         break;
     349             :         }
     350             : 
     351           6 :         bc_free_num(&first);
     352           6 :         bc_free_num(&second);
     353           6 :         bc_free_num(&result);
     354           6 :         return;
     355             : }
     356             : /* }}} */
     357             : 
     358             : /* {{{ proto string bcmod(string left_operand, string right_operand)
     359             :    Returns the modulus of the two arbitrary precision operands */
     360           5 : PHP_FUNCTION(bcmod)
     361             : {
     362             :         char *left, *right;
     363             :         size_t left_len, right_len;
     364             :         bc_num first, second, result;
     365             : 
     366           5 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &left, &left_len, &right, &right_len) == FAILURE) {
     367           1 :                 return;
     368             :         }
     369             :         
     370           4 :         bc_init_num(&first TSRMLS_CC);
     371           4 :         bc_init_num(&second TSRMLS_CC);
     372           4 :         bc_init_num(&result TSRMLS_CC);
     373           4 :         bc_str2num(&first, left, 0 TSRMLS_CC);
     374           4 :         bc_str2num(&second, right, 0 TSRMLS_CC);
     375             :         
     376           4 :         switch (bc_modulo(first, second, &result, 0 TSRMLS_CC)) {
     377             :                 case 0:
     378           3 :                         RETVAL_STR(bc_num2str(result));
     379           3 :                         break;
     380             :                 case -1:
     381           1 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Division by zero");
     382             :                         break;
     383             :         }
     384             :         
     385           4 :         bc_free_num(&first);
     386           4 :         bc_free_num(&second);
     387           4 :         bc_free_num(&result);
     388           4 :         return;
     389             : }
     390             : /* }}} */
     391             : 
     392             : /* {{{ proto string bcpowmod(string x, string y, string mod [, int scale])
     393             :    Returns the value of an arbitrary precision number raised to the power of another reduced by a modulous */
     394           6 : PHP_FUNCTION(bcpowmod)
     395             : {
     396             :         char *left, *right, *modulous;
     397             :         size_t left_len, right_len, modulous_len;
     398             :         bc_num first, second, mod, result;
     399           6 :         zend_long scale = BCG(bc_precision);
     400             :         int scale_int;
     401             : 
     402           6 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss|l", &left, &left_len, &right, &right_len, &modulous, &modulous_len, &scale) == FAILURE) {
     403           3 :                 return;
     404             :         }
     405             : 
     406           3 :         bc_init_num(&first TSRMLS_CC);
     407           3 :         bc_init_num(&second TSRMLS_CC);
     408           3 :         bc_init_num(&mod TSRMLS_CC);
     409           3 :         bc_init_num(&result TSRMLS_CC);
     410           3 :         php_str2num(&first, left TSRMLS_CC);
     411           3 :         php_str2num(&second, right TSRMLS_CC);
     412           3 :         php_str2num(&mod, modulous TSRMLS_CC);
     413             : 
     414           3 :         scale_int = (int) ((int)scale < 0) ? 0 : scale;
     415             : 
     416           3 :         if (bc_raisemod(first, second, mod, &result, scale_int TSRMLS_CC) != -1) {
     417           3 :                 if (result->n_scale > scale) {
     418           0 :                         result->n_scale = scale;
     419             :                 }
     420           3 :                 RETVAL_STR(bc_num2str(result));
     421             :         } else {
     422           0 :                 RETVAL_FALSE;
     423             :         }
     424             :         
     425           3 :         bc_free_num(&first);
     426           3 :         bc_free_num(&second);
     427           3 :         bc_free_num(&mod);
     428           3 :         bc_free_num(&result);
     429           3 :         return;
     430             : }
     431             : /* }}} */
     432             : 
     433             : /* {{{ proto string bcpow(string x, string y [, int scale])
     434             :    Returns the value of an arbitrary precision number raised to the power of another */
     435           5 : PHP_FUNCTION(bcpow)
     436             : {
     437             :         char *left, *right;
     438             :         size_t left_len, right_len;
     439           5 :         zend_long scale_param = 0;
     440             :         bc_num first, second, result;
     441           5 :         int scale = BCG(bc_precision), argc = ZEND_NUM_ARGS();
     442             : 
     443           5 :         if (zend_parse_parameters(argc TSRMLS_CC, "ss|l", &left, &left_len, &right, &right_len, &scale_param) == FAILURE) {
     444           1 :                 return;
     445             :         }
     446             :         
     447           4 :         if (argc == 3) {
     448           1 :                 scale = (int) ((int)scale_param < 0) ? 0 : scale_param;
     449             :         }
     450             : 
     451           4 :         bc_init_num(&first TSRMLS_CC);
     452           4 :         bc_init_num(&second TSRMLS_CC);
     453           4 :         bc_init_num(&result TSRMLS_CC);
     454           4 :         php_str2num(&first, left TSRMLS_CC);
     455           4 :         php_str2num(&second, right TSRMLS_CC);
     456           4 :         bc_raise (first, second, &result, scale TSRMLS_CC);
     457             : 
     458           4 :         if (result->n_scale > scale) {
     459           0 :                 result->n_scale = scale;
     460             :         }
     461             : 
     462           4 :         RETVAL_STR(bc_num2str(result));
     463           4 :         bc_free_num(&first);
     464           4 :         bc_free_num(&second);
     465           4 :         bc_free_num(&result);
     466           4 :         return;
     467             : }
     468             : /* }}} */
     469             : 
     470             : /* {{{ proto string bcsqrt(string operand [, int scale])
     471             :    Returns the square root of an arbitray precision number */
     472           6 : PHP_FUNCTION(bcsqrt)
     473             : {
     474             :         char *left;
     475             :         size_t left_len;
     476           6 :         zend_long scale_param = 0;
     477             :         bc_num result;
     478           6 :         int scale = BCG(bc_precision), argc = ZEND_NUM_ARGS();
     479             : 
     480           6 :         if (zend_parse_parameters(argc TSRMLS_CC, "s|l", &left, &left_len, &scale_param) == FAILURE) {
     481           1 :                 return;
     482             :         }
     483             :         
     484           5 :         if (argc == 2) {
     485           1 :                 scale = (int) ((int)scale_param < 0) ? 0 : scale_param;
     486             :         }
     487             : 
     488           5 :         bc_init_num(&result TSRMLS_CC);
     489           5 :         php_str2num(&result, left TSRMLS_CC);
     490             :         
     491           5 :         if (bc_sqrt (&result, scale TSRMLS_CC) != 0) {
     492           4 :                 if (result->n_scale > scale) {
     493           0 :                         result->n_scale = scale;
     494             :                 }
     495           4 :                 RETVAL_STR(bc_num2str(result));
     496             :         } else {
     497           1 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Square root of negative number");
     498             :         }
     499             : 
     500           5 :         bc_free_num(&result);
     501           5 :         return;
     502             : }
     503             : /* }}} */
     504             : 
     505             : /* {{{ proto int bccomp(string left_operand, string right_operand [, int scale])
     506             :    Compares two arbitrary precision numbers */
     507          10 : PHP_FUNCTION(bccomp)
     508             : {
     509             :         char *left, *right;
     510             :         size_t left_len, right_len;
     511          10 :         zend_long scale_param = 0;
     512             :         bc_num first, second;
     513          10 :         int scale = BCG(bc_precision), argc = ZEND_NUM_ARGS();
     514             : 
     515          10 :         if (zend_parse_parameters(argc TSRMLS_CC, "ss|l", &left, &left_len, &right, &right_len, &scale_param) == FAILURE) {
     516           0 :                 return;
     517             :         }
     518             :         
     519          10 :         if (argc == 3) {
     520           7 :                 scale = (int) ((int)scale_param < 0) ? 0 : scale_param;
     521             :         }
     522             : 
     523          10 :         bc_init_num(&first TSRMLS_CC);
     524          10 :         bc_init_num(&second TSRMLS_CC);
     525             : 
     526          10 :         bc_str2num(&first, left, scale TSRMLS_CC);
     527          10 :         bc_str2num(&second, right, scale TSRMLS_CC);
     528          10 :         RETVAL_LONG(bc_compare(first, second));
     529             : 
     530          10 :         bc_free_num(&first);
     531          10 :         bc_free_num(&second);
     532          10 :         return;
     533             : }
     534             : /* }}} */
     535             : 
     536             : /* {{{ proto bool bcscale(int scale)
     537             :    Sets default scale parameter for all bc math functions */
     538           5 : PHP_FUNCTION(bcscale)
     539             : {
     540             :         zend_long new_scale;
     541             :         
     542           5 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &new_scale) == FAILURE) {
     543           0 :                 return;
     544             :         }
     545             : 
     546           5 :         BCG(bc_precision) = ((int)new_scale < 0) ? 0 : new_scale;
     547             : 
     548           5 :         RETURN_TRUE;
     549             : }
     550             : /* }}} */
     551             : 
     552             : 
     553             : #endif
     554             : 
     555             : /*
     556             :  * Local variables:
     557             :  * tab-width: 4
     558             :  * c-basic-offset: 4
     559             :  * End:
     560             :  * vim600: sw=4 ts=4 fdm=marker
     561             :  * vim<600: sw=4 ts=4
     562             :  */

Generated by: LCOV version 1.10

Generated at Fri, 19 Sep 2014 17:11:05 +0000 (2 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.