PHP – bcpowmod() 函数
在 PHP 中,bcpowmod() 函数用于将任意精度基数提高到另一个指数数,再减去一个指定模数。bcpowmod() 函数接受三个任意精度数字作为字符串,并在将结果缩放到指定精度后返回基数提高到模数的指数次方。
语法
String bcpowmod($base, $exponent, $modulus, $scale)
参数
bcpowmod() 函数接受四个不同的参数− $base、$exponent、$modulus 和 $scale。
$base− 它表示左操作数。它是字符串类型参数。
$exponent− 它表示表示指数的右操作数编号。它是字符串类型参数。
$modulus− $modulus 参数接受表示模数的操作数。它是字符串类型参数。
$scale− $scale 参数是整数类型参数。它表示结果 (baseexponent%mod) 中小数点后面有多少位数字。其默认值为 0。
返回值
bcpowmod() 函数将结果作为字符串返回。或者,如果模数为 0 或指数为负数,则返回 False。
示例 1
<?php // input numbers with arbitrary precision $base = "5"; $exponent = "7"; $mod = "7"; // calculates the base^exponent % mod $result = bcpowmod($base, $exponent, $mod); echo "Output without scale: ", $result; ?>
输出
Output without scale: 5
示例 2
<?php // input numbers with arbitrary precision $base = "5"; $exponent = "7"; $mod = "7"; //Scale value 4 $scale = 4; // calculates the base^exponent % mod $result = bcpowmod($base, $exponent, $mod, $scale); echo "Output with scale: ", $result; ?>
输出
Output with scale: 5.0000
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP