GMP数学扩展¶
| 属性 | 值 |
|---|---|
| 命名空间 | fize\math |
| 类名 | Gmp |
| 方法: |
|---|
| 方法名 | 说明 |
|---|---|
| abs() | 获取绝对值 |
| add() | 加法运算 |
| and() | AND运算 |
| binomial() | 二项式系数计算 |
| clrbit() | 清除位索引 |
| cmp() | 比较数值 |
| com() | 计算数值的补码 |
| divQ() | 除法运算得商 |
| divQr() | 除数得商和余 |
| divR() | 除法运算得余 |
| div() | 除法运算得商 |
| divexact() | 精确除数法 |
| export() | 导出到二进制字符串 |
| fact() | 阶乘 |
| gcd() | 最大公约数 |
| gcdext() | 计算g, s, t,使得a*s + b*t =g =gcd(a,b)。 |
| hamdist() | 哈明距离 |
| import() | 从二进制字符串导入 |
| init() | 创建一个GMP数值 |
| intval() | 将数值转化为int类型 |
| invert() | 逆的模 |
| jacobi() | 雅可比符号 |
| kronecker() | 克罗内克符号 |
| lcm() | 预期最大公约数 |
| legendre() | 勒让德符号 |
| mod() | 模操作 |
| mul() | 乘法运算 |
| neg() | 返回一个数字的负值。 |
| nextprime() | 求下一个质数 |
| or() | OR操作 |
| perfectPower() | 完美幂检查 |
| perfectSquare() | 完全平方检查 |
| popcount() | 种群统计 |
| pow() | 幂运算 |
| powm() | 幂运算取模 |
| probPrime() | 检查number是否为素数 |
| randomBits() | 随机数 |
| randomRange() | 产生范围内随机数 |
| randomSeed() | 设置随机数种子 |
| random() | 随机数 |
| root() | 取n次方根的整数部分 |
| rootrem() | 取n次根的整数部分和余数 |
| scan0() | 扫描0 |
| scan1() | 扫描1 |
| setbit() | 设置二进位 |
| sign() | 检查数字的符号。 |
| sqrt() | 计算平方根 |
| sqrtrem() | 余数平方根 |
| strval() | 将数值转化为字符串 |
| sub() | 减法运算 |
| testbit() | 测试是否设置了二进位 |
| xor() | XOR运算 |
方法¶
add()¶
加法运算
public static function add (
\GMP|string $a,
\GMP|string $b
) : \GMP
| 参数: |
|
|---|
and()¶
AND运算
public static function and (
\GMP|string $a,
\GMP|string $b
) : \GMP
| 参数: |
|
|---|
binomial()¶
二项式系数计算
public static function binomial (
\GMP|string $n,
int $k
) : \GMP
| 参数: |
|
||||||
|---|---|---|---|---|---|---|---|
| 返回值: | 失败时返回false |
clrbit()¶
清除位索引
public static function clrbit (
\GMP|string &$a,
int $index
)
| 参数: |
|
|---|
cmp()¶
比较数值
public static function cmp (
\GMP|string $a,
\GMP|string $b
) : int
| 参数: |
|
||||||
|---|---|---|---|---|---|---|---|
| 返回值: | 值1>值2返回1,值1=值2返回0,值1小于值2返回-1 |
divQ()¶
除法运算得商
public static function divQ (
\GMP|string $a,
\GMP|string $b,
int $round = 0
) : \GMP
| 参数: |
|
|---|
divQr()¶
除数得商和余
public static function divQr (
\GMP|string $n,
\GMP|string $d,
int $round = 0
) : array
| 参数: |
|
||||||||
|---|---|---|---|---|---|---|---|---|---|
| 返回值: | 余数处理方法选项 |
divR()¶
除法运算得余
public static function divR (
\GMP|string $n,
\GMP|string $d,
int $round = 0
) : \GMP
| 参数: |
|
|---|
div()¶
除法运算得商
public static function div (
\GMP|string $a,
\GMP|string $b,
int $round = 0
) : \GMP
| 参数: |
|
|---|
divexact()¶
精确除数法
public static function divexact (
\GMP|string $n,
\GMP|string $d
) : \GMP
| 参数: |
|
|---|
export()¶
导出到二进制字符串
public static function export (
\GMP $gmpnumber,
int $word_size = 1,
int $options = 17
) : string
| 参数: |
|
||||||||
|---|---|---|---|---|---|---|---|---|---|
| 返回值: | 失败时返回false |
gcdext()¶
计算g, s, t,使得a*s + b*t =g =gcd(a,b)。
public static function gcdext (
$a,
$b
) : array
| 参数: |
|
|---|
其中gcd是最大公约数。返回各自元素g、s和t的数组。
import()¶
从二进制字符串导入
public static function import (
$data,
int $word_size = 1,
int $options = 17
) : bool|\GMP
| 参数: |
|
|---|
init()¶
创建一个GMP数值
public static function init (
$number,
int $base = 0
) : \GMP
| 参数: |
|
|---|
intval()¶
将数值转化为int类型
public static function intval (
\GMP|string $gmpnumber
) : int
| 参数: |
|
|---|
probPrime()¶
检查number是否为素数
public static function probPrime (
$a,
int $reps = 10
) : int
| 参数: |
|
|---|
randomSeed()¶
设置随机数种子
public static function randomSeed (
\GMP|string $seed
) : mixed
| 参数: |
|
|---|
setbit()¶
设置二进位
public static function setbit (
&$a,
$index,
bool $set_clear = true
)
| 参数: |
|
|---|
strval()¶
将数值转化为字符串
public static function strval (
$gmpnumber,
int $base = 10
) : string
| 参数: |
|
|---|