gmp_sqrt()是PHP中的一个内置函数,用于计算gmp数的平方根( 多精度 :对于大数字)。此函数只返回GMP数平方根的整数部分。
null
语法:
gmp_sqrt ( $num )
参数: 此函数接受GMP编号 $num 作为强制参数,如上述语法所示。该参数可以是PHP 5.6版及更高版本中的GMP对象,也可以传递数字字符串,前提是可以将该字符串转换为数字。
返回值: 此函数返回一个GMP编号,它是作为参数传递给它的GMP编号的平方根。此函数只返回作为参数传递给它的GMP数的平方根的整数部分。
例如:
Input : "9" Output : 3 Input : "24" Output : 4
下面的程序演示了PHP中的gmp_sqrt()函数:
项目1: 当作为GMP数字的数字字符串作为参数传递时,计算GMP数字平方根的程序。
<?php // PHP program to calculate the square root // of a GMP number passed as arguments // strings as GMP numbers $num1 = "9" ; $num2 = "24" ; // calculates the square root of a GMP number $squareRoot = gmp_sqrt( $num1 ); echo $squareRoot . "" ; // calculates the square root of a GMP number $squareRoot = gmp_sqrt( $num2 ); echo $squareRoot . "" ; ?> |
输出:
3 4
项目2: 当GMP编号作为参数传递时,计算GMP编号平方根的程序。
<?php // PHP program to calculate the square root // of a GMP number // creating GMP numbers using gmp_init() $num1 = gmp_init(9, 10); $num2 = gmp_init(24, 10); // calculates the square root of a GMP number $squareRoot = gmp_sqrt( $num1 ); echo $squareRoot . "" ; // calculates the square root of a GMP number $squareRoot = gmp_sqrt( $num2 ); echo $squareRoot . "" ; ?> |
输出:
3 4
参考: http://php.net/manual/en/function.gmp-sqrt.php
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END