HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

gmp_sqrtrem

Description

The gmp_sqrtrem of GMP for PHP calculates the square root with the remainder.

Syntax

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

Parameters

num

The number being square rooted.

A GMP object, an int or a numeric string.

Return

Returns an array where the first element is the integer square root of num and the second is the remainder (i.e., the difference between num and the first element squared).

Examples

1 · num · GMP

<?

$num = 8;

$num = gmp_init($num);

$return = gmp_sqrtrem($num);

var_dump($return);
array(2) {
  [0]=>
  object(GMP)#2 (1) {
    ["num"]=>
    string(1) "2"
  }
  [1]=>
  object(GMP)#3 (1) {
    ["num"]=>
    string(1) "4"
  }
}

2 · num · int

<?

$num = 8;

$return = gmp_sqrtrem($num);

var_dump($return);
array(2) {
  [0]=>
  object(GMP)#1 (1) {
    ["num"]=>
    string(1) "2"
  }
  [1]=>
  object(GMP)#2 (1) {
    ["num"]=>
    string(1) "4"
  }
}

3 · num · string

<?

$num = "8";

$return = gmp_sqrtrem($num);

var_dump($return);
array(2) {
  [0]=>
  object(GMP)#1 (1) {
    ["num"]=>
    string(1) "2"
  }
  [1]=>
  object(GMP)#2 (1) {
    ["num"]=>
    string(1) "4"
  }
}