]> granicus.if.org Git - php/commitdiff
Added support for libbcmath's bc_raisemod function as bc_powmod()
authorSara Golemon <pollita@php.net>
Tue, 10 Dec 2002 19:04:27 +0000 (19:04 +0000)
committerSara Golemon <pollita@php.net>
Tue, 10 Dec 2002 19:04:27 +0000 (19:04 +0000)
ext/bcmath/bcmath.c
ext/bcmath/php_bcmath.h

index 2a8b346c8921cab82bba14bee8586518883f7303..00b266ff7be88384e4709cdbacec75244d41c96a 100644 (file)
@@ -42,6 +42,7 @@ function_entry bcmath_functions[] = {
        PHP_FE(bcsqrt,                                                                  NULL)
        PHP_FE(bcscale,                                                                 NULL)
        PHP_FE(bccomp,                                                                  NULL)
+       PHP_FE(bc_powmod,                                                               NULL)
        {NULL, NULL, NULL}
 };
 
@@ -329,6 +330,38 @@ PHP_FUNCTION(bcmod)
 }
 /* }}} */
 
+/* {{{ proto string bc_powmod(string x, string y, string mod [, int scale])
+   Returns the value of an arbitrary precision number raised to the power of another reduced by a modulous */
+PHP_FUNCTION(bc_powmod)
+{
+       char *left, *right, *modulous;
+       int left_len, right_len, modulous_len;
+       bc_num first, second, mod, result;
+       int scale=bc_precision;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_C, "sss|l", &left, &left_len, &right, &right_len, &modulous, &modulous_len, &scale) == FAILURE) {
+               WRONG_PARAM_COUNT;
+       }
+
+       bc_init_num(&first TSRMLS_CC);
+       bc_init_num(&second TSRMLS_CC);
+       bc_init_num(&mod TSRMLS_CC);
+       bc_init_num(&result TSRMLS_CC);
+       bc_str2num(&first, left, scale TSRMLS_CC);
+       bc_str2num(&second, right, scale TSRMLS_CC);
+       bc_str2num(&mod, modulous, scale TSRMLS_CC);
+       bc_raisemod(first, second, mod, &result, scale TSRMLS_CC);
+       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;
+       bc_free_num(&first);
+       bc_free_num(&second);
+       bc_free_num(&mod);
+       bc_free_num(&result);
+       return;
+}
+/* }}} */
+
 /* {{{ proto string bcpow(string x, string y [, int scale])
    Returns the value of an arbitrary precision number raised to the power of another */
 PHP_FUNCTION(bcpow)
index 35299d3cc9d5abf77b0f2d86b7f32d6191a824a3..f7036a4bbdad7b80ac5446eba889daf85c023a06 100644 (file)
@@ -60,6 +60,7 @@ PHP_FUNCTION(bcpow);
 PHP_FUNCTION(bcsqrt);
 PHP_FUNCTION(bccomp);
 PHP_FUNCTION(bcscale);
+PHP_FUNCTION(bc_powmod);
 
 #else