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运算

方法

abs()

获取绝对值

public static function abs (
    \GMP|string $a
) : \GMP
参数:
名称 说明
a

add()

加法运算

public static function add (
    \GMP|string $a,
    \GMP|string $b
) : \GMP
参数:
名称 说明
a 被加数
b 加数

and()

AND运算

public static function and (
    \GMP|string $a,
    \GMP|string $b
) : \GMP
参数:
名称 说明
a 值1
b 值2

binomial()

二项式系数计算

public static function binomial (
    \GMP|string $n,
    int $k
) : \GMP
参数:
名称 说明
n  
k 整数
返回值:

失败时返回false

clrbit()

清除位索引

public static function clrbit (
    \GMP|string &$a,
    int $index
)
参数:
名称 说明
a  
index 索引,从0开始

cmp()

比较数值

public static function cmp (
    \GMP|string $a,
    \GMP|string $b
) : int
参数:
名称 说明
a 值1
b 值2
返回值:

值1>值2返回1,值1=值2返回0,值1小于值2返回-1

com()

计算数值的补码

public static function com (
    \GMP|string $a
) : \GMP
参数:
名称 说明
a 数值

divQ()

除法运算得商

public static function divQ (
    \GMP|string $a,
    \GMP|string $b,
    int $round = 0
) : \GMP
参数:
名称 说明
a 被除数
b 除数
round 余数处理方法选项

divQr()

除数得商和余

public static function divQr (
    \GMP|string $n,
    \GMP|string $d,
    int $round = 0
) : array
参数:
名称 说明
n 被除数
d 除数
round  
返回值:

余数处理方法选项

divR()

除法运算得余

public static function divR (
    \GMP|string $n,
    \GMP|string $d,
    int $round = 0
) : \GMP
参数:
名称 说明
n 被除数
d 除数
round 余数处理方法选项

div()

除法运算得商

public static function div (
    \GMP|string $a,
    \GMP|string $b,
    int $round = 0
) : \GMP
参数:
名称 说明
a 被除数
b 除数
round 余数处理方法选项

divexact()

精确除数法

public static function divexact (
    \GMP|string $n,
    \GMP|string $d
) : \GMP
参数:
名称 说明
n 被除数
d 除数

export()

导出到二进制字符串

public static function export (
    \GMP $gmpnumber,
    int $word_size = 1,
    int $options = 17
) : string
参数:
名称 说明
gmpnumber  
word_size  
options  
返回值:

失败时返回false

fact()

阶乘

public static function fact (
     $a
) : \GMP
参数:
名称 说明
a  

gcd()

最大公约数

public static function gcd (
     $a,
     $b
) : \GMP
参数:
名称 说明
a  
b  

gcdext()

计算g, s, t,使得a*s + b*t =g =gcd(a,b)。

public static function gcdext (
     $a,
     $b
) : array
参数:
名称 说明
a  
b  
其中gcd是最大公约数。返回各自元素g、s和t的数组。

hamdist()

哈明距离

public static function hamdist (
     $a,
     $b
) : int
参数:
名称 说明
a  
b  

import()

从二进制字符串导入

public static function import (
     $data,
    int $word_size = 1,
    int $options = 17
) : bool|\GMP
参数:
名称 说明
data  
word_size  
options  

init()

创建一个GMP数值

public static function init (
     $number,
    int $base = 0
) : \GMP
参数:
名称 说明
number  
base  

intval()

将数值转化为int类型

public static function intval (
    \GMP|string $gmpnumber
) : int
参数:
名称 说明
gmpnumber  

invert()

逆的模

public static function invert (
     $a,
     $b
) : \GMP
参数:
名称 说明
a  
b  

jacobi()

雅可比符号

public static function jacobi (
     $a,
     $p
) : int
参数:
名称 说明
a  
p  

kronecker()

克罗内克符号

public static function kronecker (
     $a,
     $b
) : int
参数:
名称 说明
a  
b  

lcm()

预期最大公约数

public static function lcm (
     $a,
     $b
) : \GMP
参数:
名称 说明
a  
b  

legendre()

勒让德符号

public static function legendre (
     $a,
     $p
) : int
参数:
名称 说明
a  
p  

mod()

模操作

public static function mod (
     $n,
     $d
) : \GMP
参数:
名称 说明
n  
d  

mul()

乘法运算

public static function mul (
     $a,
     $b
) : \GMP
参数:
名称 说明
a  
b  

neg()

返回一个数字的负值。

public static function neg (
     $a
) : \GMP
参数:
名称 说明
a  

nextprime()

求下一个质数

public static function nextprime (
     $a
) : \GMP
参数:
名称 说明
a  

or()

OR操作

public static function or (
     $a,
     $b
) : \GMP
参数:
名称 说明
a  
b  

perfectPower()

完美幂检查

public static function perfectPower (
     $a
) : bool
参数:
名称 说明
a  

perfectSquare()

完全平方检查

public static function perfectSquare (
     $a
) : bool
参数:
名称 说明
a  

popcount()

种群统计

public static function popcount (
     $a
) : int
参数:
名称 说明
a  

pow()

幂运算

public static function pow (
     $base,
     $exp
) : \GMP
参数:
名称 说明
base  
exp  

powm()

幂运算取模

public static function powm (
     $base,
     $exp,
     $mod
) : \GMP
参数:
名称 说明
base  
exp  
mod  

probPrime()

检查number是否为素数

public static function probPrime (
     $a,
    int $reps = 10
) : int
参数:
名称 说明
a  
reps  

randomBits()

随机数

public static function randomBits (
     $bits
) : \GMP
参数:
名称 说明
bits  

randomRange()

产生范围内随机数

public static function randomRange (
     $min,
     $max
) : \GMP
参数:
名称 说明
min  
max  

randomSeed()

设置随机数种子

public static function randomSeed (
    \GMP|string $seed
) : mixed
参数:
名称 说明
seed  

random()

随机数

public static function random (
    int $limiter = 20
) : \GMP
参数:
名称 说明
limiter  

root()

取n次方根的整数部分

public static function root (
     $a,
     $nth
) : \GMP
参数:
名称 说明
a  
nth  

rootrem()

取n次根的整数部分和余数

public static function rootrem (
    \GMP $a,
     $nth
) : array
参数:
名称 说明
a  
nth  

scan0()

扫描0

public static function scan0 (
     $a,
     $start
) : int
参数:
名称 说明
a  
start  

scan1()

扫描1

public static function scan1 (
     $a,
     $start
) : int
参数:
名称 说明
a  
start  

setbit()

设置二进位

public static function setbit (
     &$a,
     $index,
    bool $set_clear = true
)
参数:
名称 说明
a  
index  
set_clear  

sign()

检查数字的符号。

public static function sign (
     $a
) : int
参数:
名称 说明
a  

sqrt()

计算平方根

public static function sqrt (
     $a
) : \GMP
参数:
名称 说明
a  

sqrtrem()

余数平方根

public static function sqrtrem (
     $a
) : array
参数:
名称 说明
a  

strval()

将数值转化为字符串

public static function strval (
     $gmpnumber,
    int $base = 10
) : string
参数:
名称 说明
gmpnumber  
base  

sub()

减法运算

public static function sub (
     $a,
     $b
) : \GMP
参数:
名称 说明
a  
b  

testbit()

测试是否设置了二进位

public static function testbit (
     $a,
     $index
) : bool
参数:
名称 说明
a  
index  

xor()

XOR运算

public static function xor (
     $a,
     $b
) : \GMP
参数:
名称 说明
a  
b