gmp_perfect_square()是PHP中的一个内置函数,用于检查给定的gmp编号是否正确( 多精度 :对于大的数字)是否是一个完美的正方形。
null
语法:
gmp_perfect_square($num)
参数: 该函数接受一个GMP编号 $num 。该参数可以是PHP 5.6及更高版本中的GMP对象,也可以传递数字字符串,前提是可以将该字符串转换为数字。
返回值: 函数返回 符合事实的 如果给定的数字 $num 是一个完美的正方形,否则它会返回 错误的 .
例如:
Input : $num=25 Output : true Input : $num=10 Output : false
下面的程序演示了gmp_perfect_square()函数的用法:
项目1: 下面的程序演示了当gmp编号作为参数传递时,gmp_perfect_square()函数的工作原理。
<?php // PHP program to check the if the // number is perfect square or not // numeric string arguments $num = gmp_init( "1001" , 2); // checks if 9 (1001) is a perfect number or not var_dump(gmp_perfect_square( $num )). "" ; $num = gmp_init( "11001" , 2); // checks if 25 (11001) is a perfect number or not var_dump(gmp_perfect_square( $num )). "" ; $num = gmp_init( "1100" , 2); // checks if 12 (1100) is a perfect number or not var_dump(gmp_perfect_square( $num )); ?> |
输出:
bool(true) bool(true) bool(false)
项目2: 下面的程序演示了当数字字符串作为参数传递时,gmp_perfect_square()的工作原理。
<?php // PHP program to check the if the // number is perfect square or not // numeric string arguments $num = "9" ; // checks if 9 (1001) is a perfect number or not var_dump(gmp_perfect_square( $num )). "" ; $num = "25" ; // checks if 25 (11001) is a perfect number or not var_dump(gmp_perfect_square( $num )). "" ; $num = "12" ; // checks if 12 (1100) is a perfect number or not var_dump(gmp_perfect_square( $num )); ?> |
输出:
bool(true) bool(true) bool(false)
参考: http://php.net/manual/en/function.gmp-perfect-square.php
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END