PHP 8.3.4 Released!

gmp_sqrtrem

(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)

gmp_sqrtrem余りつきの平方根

説明

gmp_sqrtrem(GMP|int|string $num): array

ある数の平方根を余りつきで計算します。

パラメータ

num

平方根を計算したい数。

GMP オブジェクト、整数、あるいは数値に変換可能な数値形式の文字列。

戻り値

最初の要素が num の整数平方根 (gmp_sqrt()も参照ください)、2 番目の要素が余り (すなわち、num と最初の要素の 2 乗の差) であるような配列を返します。

例1 gmp_sqrtrem() の例

<?php
list($sqrt1, $sqrt1rem) = gmp_sqrtrem("9");
list(
$sqrt2, $sqrt2rem) = gmp_sqrtrem("7");
list(
$sqrt3, $sqrt3rem) = gmp_sqrtrem("1048576");

echo
gmp_strval($sqrt1) . ", " . gmp_strval($sqrt1rem) . "\n";
echo
gmp_strval($sqrt2) . ", " . gmp_strval($sqrt2rem) . "\n";
echo
gmp_strval($sqrt3) . ", " . gmp_strval($sqrt3rem) . "\n";
?>

上の例の出力は以下となります。

3, 0
2, 3
1024, 0

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top