PHP gmp_com()函数用法介绍

2021年3月12日13:50:48 发表评论 728 次浏览

gmp_com()是PHP中的内置函数, 用于计算一个人的补语GMP编号(GNU多重精度:适用于大数)。

语法如下:

gmp_com($num)

参数:此功能接受GMP编号$ num作为上述语法中所示的必需参数。此参数可以是PHP 5.6和更高版本中的GMP对象, 或者也可以传递数字字符串, 只要可以将该字符串转换为数字即可。

返回值:此函数返回一个GMP编号, 该编号是作为参数传递给它的GMP编号的补码。

例子:

Input : gmp_com("1235")
Output : -1236

Input : gmp_com("1234")
Output : -1235

下面的程序说明了PHP中的gmp_com()函数:

程序1:将数字字符串作为GMP数字作为参数传递时, 计算GMP数字的补码的程序。

<?php
// PHP program to calculate the one's complement
// of a GMP number passed as arguments 
  
// strings as GMP numbers 
$num = "1345" ;
  
// calculate the one's complement of a GMP number
$res = gmp_com( $num );
  
echo $res ;
  
?>

输出如下:

-1346

程式2:当GMP编号作为参数传递时, 用于计算GMP编号的补码的程序。

<?php
// PHP program to calculate the one's complement
// of a GMP number passed as arguments 
  
// creating GMP numbers using gmp_init()
$num = gmp_init(132);
  
// calculate the one's complement of a GMP number
$res = gmp_com( $num );
  
echo $res ;
  
?>

输出如下:

-133

参考:

http://php.net/manual/en/function.gmp-com.php


木子山

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: