2 // $Id: bcpowmod.php,v 1.1 2007/07/02 04:19:55 terrafrost Exp $
\r
9 * @package PHP_Compat
\r
10 * @license LGPL - http://www.gnu.org/licenses/lgpl.html
\r
11 * @copyright 2004-2007 Aidan Lister <aidan@php.net>, Arpad Ray <arpad@php.net>
\r
12 * @link http://php.net/function.bcpowmod
\r
13 * @author Sara Golemon <pollita@php.net>
\r
14 * @version $Revision: 1.1 $
\r
16 * @require PHP 4.0.0 (user_error)
\r
18 function php_compat_bcpowmod($x, $y, $modulus, $scale = 0)
\r
21 if (!is_scalar($x)) {
\r
22 user_error('bcpowmod() expects parameter 1 to be string, ' .
\r
23 gettype($x) . ' given', E_USER_WARNING);
\r
27 if (!is_scalar($y)) {
\r
28 user_error('bcpowmod() expects parameter 2 to be string, ' .
\r
29 gettype($y) . ' given', E_USER_WARNING);
\r
33 if (!is_scalar($modulus)) {
\r
34 user_error('bcpowmod() expects parameter 3 to be string, ' .
\r
35 gettype($modulus) . ' given', E_USER_WARNING);
\r
39 if (!is_scalar($scale)) {
\r
40 user_error('bcpowmod() expects parameter 4 to be integer, ' .
\r
41 gettype($scale) . ' given', E_USER_WARNING);
\r
46 while (bccomp($y, '0')) {
\r
47 if (bccomp(bcmod($y, '2'), '0')) {
\r
48 $t = bcmod(bcmul($t, $x), $modulus);
\r
49 $y = bcsub($y, '1');
\r
52 $x = bcmod(bcmul($x, $x), $modulus);
\r
53 $y = bcdiv($y, '2');
\r
61 if (!function_exists('bcpowmod')) {
\r
62 function bcpowmod($x, $y, $modulus, $scale = 0)
\r
64 return php_compat_bcpowmod($x, $y, $modulus, $scale);
\r