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
Links
GMP
- gmp_abs
- gmp_add
- gmp_and
- gmp_binomial
- gmp_clrbit
- gmp_cmp
- gmp_com
- gmp_div
- gmp_div_q
- gmp_div_qr
- gmp_div_r
- gmp_divexact
- gmp_export
- gmp_fact
- gmp_gcd
- gmp_gcdext
- gmp_hamdist
- gmp_import
- gmp_init
- gmp_intval
- gmp_invert
- gmp_jacobi
- gmp_kronecker
- gmp_lcm
- gmp_legendre
- gmp_mod
- gmp_mul
- gmp_neg
- gmp_nextprime
- gmp_or
- gmp_perfect_power
- gmp_perfect_square
- gmp_popcount
- gmp_pow
- gmp_powm
- gmp_random_bits
- gmp_random_range
- gmp_random_seed
- gmp_root
- gmp_rootrem
- gmp_scan0
- gmp_scan1
- gmp_setbit
- gmp_sign
- gmp_sqrt
- gmp_sqrtrem
- gmp_strval
- gmp_sub
- gmp_testbit
- gmp_xor