Пример #1
0
 /**
  * Tests $num on primality. Returns true, if $num is strong pseudoprime.
  * Else returns false.
  *
  * @param string $num
  * @return bool
  * @access private
  */
 function isPrime($num)
 {
     return bi_is_prime($num) ? true : false;
 }
Пример #2
0
*/
$c = bi_pow($a, 4);
echo 'pow($a, 4) = [', bi_to_str($c), "]<br/>\n";
// argument of bi_fact() must have integer type (not BIG_INT)
$c = bi_fact(100);
echo '100! = [', bi_to_str($c), "]<br/>\n";
$c = bi_sqrt($a);
echo 'sqrt($a) = [', bi_to_str($c), "]<br/>\n";
$c = bi_sqrt_rem($a);
echo 'sqrt_rem($a) = [', bi_to_str($c), "]<br/>\n";
$c = bi_gcd($a, $b);
echo 'GCD($a, $b) = [', bi_to_str($c), "]<br/>\n";
// Miller-Rabin primality test of $a
echo 'miller_test($a, $b) = ', bi_miller_test($a, $b), "<br/>\n";
// primality test of $a
echo 'is_prime($a) = ', bi_is_prime($a), "<br/>\n";
// Jacobi symbol ($a|$b)
echo 'jacobi($a, $b) = ', bi_jacobi($a, $b), "<br/>\n";
$c = bi_div_extended($a, $b);
echo '$a = $b * ', bi_to_str($c[0]), ' + ', bi_to_str($c[1]), "<br/>\n";
$c = bi_gcd_extended($a, $b);
echo 'abs($a) * ', bi_to_str($c[1]), ' + abs($b) * ', bi_to_str($c[2]), ' = ', bi_to_str($c[0]), "<br/>\n";
// serialize $a into sequence of bytes
$str = bi_serialize($a);
echo '$str = serialize($a) = [', base64_encode($str), "]<br/>\n";
// unserialize $a from sequence of bytes
$a = bi_unserialize($str);
echo 'unserialize($str) = [', bi_to_str($a), "]<br/>\n";
// show package info
var_dump(bi_info());
echo 'the list of all functions in BIG_INT module:', "<br/>\n";