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

gmp_prob_prime

Description

The gmp_prob_prime of GMP for PHP checks if the number is "probably prime".

Syntax

gmp_prob_prime(
    GMP|int|string $num,
    int $repetitions = 10
): int

Parameters

num

The number being checked as a prime. A GMP object, an int or a numeric string.

repetitions

Reasonable values of repetitions vary from 5 to 10 (default being 10); a higher value lowers the probability for a non-prime to pass as a "probable" prime.

A GMP object, an int or a numeric string.

Return

Returns 0, num is not prime. Returns 1, num is probably prime. Returns 2, num is definitely prime.

Examples

1 · num · GMP · not

<?

$num = 4;

$num = gmp_init($num);

$return = gmp_prob_prime($num);

echo $return;
0

2 · num · GMP · probably

<?

$num = 1111111111111111111;

$num = gmp_init($num);

$return = gmp_prob_prime($num);

echo $return;
1

3 · num · GMP · definitely

<?

$num = 3;

$num = gmp_init($num);

$return = gmp_prob_prime($num);

echo $return;
2

4 · num · int · not

<?

$num = 4;

$return = gmp_prob_prime($num);

echo $return;
0

5 · num · int · probably

<?

$num = 1111111111111111111;

$return = gmp_prob_prime($num);

echo $return;
1

6 · num · int · definitely

<?

$num = 3;

$return = gmp_prob_prime($num);

echo $return;
2

7 · num · string · not

<?

$num = "4";

$return = gmp_prob_prime($num);

echo $return;
0

8 · num · string · probably

<?

$num = "1111111111111111111";

$return = gmp_prob_prime($num);

echo $return;
1

9 · num · string · definitely

<?

$num = "3";

$return = gmp_prob_prime($num);

echo $return;
2

10 · repetitions

<?

$num = 1111111111111111111;
$repetitions = 5;

$num = gmp_init($num, $repetitions);

$return = gmp_prob_prime($num);

echo $return;
1