예제 #1
0
파일: example.php 프로젝트: garybulin/php7
echo '1 / $a (mod $modulus) = [', bi_to_str($c), "]<br/>\n";
$c = bi_sqrmod($a, $modulus);
echo 'sqr($a) (mod $modulus) = [', bi_to_str($c), "]<br/>\n";
echo 'cmp($a, $b) (mod $modulus) = ', bi_cmpmod($a, $b, $modulus), "<br/>\n";
/*
    other functions
*/
echo '<h3>other functions</h3>' . "\n";
/*
    attention: second parameter of bi_pow() must have 
    integer type (not BIG_INT!)
*/
$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";
예제 #2
0
<?php

$two = bi_from_str('2');
$four = bi_add($two, $two);
// Use bi_to_str() to get strings from big_int resources
print bi_to_str($four);
// prints 4
// Computing large factorials very quickly
$factorial = bi_fact(20);