summaryrefslogtreecommitdiff
path: root/ext/bcmath
diff options
context:
space:
mode:
authorSara Golemon <pollita@php.net>2002-12-10 19:04:27 +0000
committerSara Golemon <pollita@php.net>2002-12-10 19:04:27 +0000
commit51c9f2c64bf3f07c227de612c6d48e9b6c874b66 (patch)
treee476a155cdd2776744abd80ce588c78a13c13080 /ext/bcmath
parent91a6272972badd9a36e57e68d77b6631647354f4 (diff)
downloadphp-git-51c9f2c64bf3f07c227de612c6d48e9b6c874b66.tar.gz
Added support for libbcmath's bc_raisemod function as bc_powmod()
Diffstat (limited to 'ext/bcmath')
-rw-r--r--ext/bcmath/bcmath.c33
-rw-r--r--ext/bcmath/php_bcmath.h1
2 files changed, 34 insertions, 0 deletions
diff --git a/ext/bcmath/bcmath.c b/ext/bcmath/bcmath.c
index 2a8b346c89..00b266ff7b 100644
--- a/ext/bcmath/bcmath.c
+++ b/ext/bcmath/bcmath.c
@@ -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)
diff --git a/ext/bcmath/php_bcmath.h b/ext/bcmath/php_bcmath.h
index 35299d3cc9..f7036a4bbd 100644
--- a/ext/bcmath/php_bcmath.h
+++ b/ext/bcmath/php_bcmath.h
@@ -60,6 +60,7 @@ PHP_FUNCTION(bcpow);
PHP_FUNCTION(bcsqrt);
PHP_FUNCTION(bccomp);
PHP_FUNCTION(bcscale);
+PHP_FUNCTION(bc_powmod);
#else