bcpowmod() - bc数学函数(任意精度数学)
bcpowmod()
(PHP 5, PHP 7)
Raise an arbitrary precision number to another, reduced by a specified modulus
说明
bcpowmod(string $base,string $exponent,string $modulus[,int $scale= 0]): stringUse the fast-exponentiation method to raise$baseto the power$exponentwith respect to the modulus$modulus.
参数
$baseThe base, as an integral string(i.e. the scale has to be zero).
$exponentThe exponent, as an non-negative, integral string(i.e. the scale has to be zero).
$modulusThe modulus, as an integral string(i.e. the scale has to be zero).
$scale此可选参数用于设置结果中小数点后的小数位数。也可通过使用bcscale()来设置全局默认的小数位数,用于所有函数。
返回值
Returns the result as a string, or NULL
if$modulusis0or$exponentis negative.
注释
Note:Because this method uses the modulus operation, numbers which are not positive integers may give unexpected results.
范例
The following two statements are functionally identical. The bcpowmod() version however, executes in less time and can accept larger parameters.
参见
bcpow()
任意精度数字的乘方bcmod()
对一个任意精度数字取模
I found a better way to emulate bcpowmod on PHP 4, which works with very big numbers too: function powmod($m,$e,$n) { if (intval(PHP_VERSION)>4) { return(bcpowmod($m,$e,$n)); } else { $r=""; while ($e!="0") { $t=bcmod($e,"4096"); $r=substr("000000000000".decbin(intval($t)),-12).$r; $e=bcdiv($e,"4096"); } $r=preg_replace("!^0+!","",$r); if ($r=="") $r="0"; $m=bcmod($m,$n); $erb=strrev($r); $q="1"; $a[0]=$m; for ($i=1;$i
鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com
图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!