当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


PHP gmp_legendre()用法及代码示例


gmp_legendre()函数是PHP中的内置函数,该函数计算作为参数传递给函数的两个GMP数字(GNU多精度:对于大数)的Legendre符号,并将其返回。 $num2必须为正数和奇数。

用法:

gmp_legendre( $num1, $num2 )

使用的参数:
该函数接受两个强制性参数$num1和$num2,如上面的语法所示。这些参数可以是PHP 5.6和更高版本中的GMP对象,或者可以将数字字符串传递给函数,前提是可以将这些字符串转换为数字。


返回值:
此函数返回一个GMP数字(在PHP 5.5和更低版本中)或一个GMP对象(在PHP 5.6和更高版本中),这是两个数字的Legendre符号。

例子:

Input : $num1 = 2, $num2 = 3
Output : -1

Input : $num1 = 6, $num2 = 15
Output : 0

下面的程序将说明gmp_legendre()函数:

程序1:

<?php 
// PHP program to calculate the 
// legendre of two GMP numbers 
$num1 = 13; 
$num2 = 9907; 
  
//Display the result 
echo gmp_legendre($num1, $num2);  
?>

输出

1

程序2:

<?php 
// PHP program to calculate the 
// legendre of two GMP numbers 
  
// creating GMP numbers using gmp_init() 
$num1 = gmp_init("124567812"); 
$num2 = gmp_init("271290907"); 
  
//Display the result 
echo gmp_legendre($num1, $num2);  
?>

输出

-1

参考:http://php.net/manual/en/function.gmp-legendre.php



相关用法


注:本文由纯净天空筛选整理自RICHIK BHATTACHARJEE大神的英文原创作品 PHP | gmp_legendre() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。