示例#1
0
 /**
  * @param $number
  * @return bool
  * @throws \Exception
  */
 public static function isFibb($number)
 {
     if (static::isNotValid($number)) {
         throw new \Exception('Number must not be zero or negative.');
     }
     if (gmp_perfect_square(5 * pow($number, 2) + 4) || gmp_perfect_square(5 * pow($number, 2) - 4)) {
         return true;
     }
     return false;
 }
示例#2
0
$prime2 = gmp_nextprime(-1000);
// next prime number greater than -1000
echo gmp_strval($prime1) . "\n";
echo gmp_strval($prime2) . "\n";
// gmp_or
$or1 = gmp_or("0xfffffff2", "4");
echo gmp_strval($or1, 16) . "\n";
$or2 = gmp_or("0xfffffff2", "2");
echo gmp_strval($or2, 16) . "\n";
// gmp_perfect_square
var_dump(gmp_perfect_square("9"));
// 3 * 3, perfect square
var_dump(gmp_perfect_square("7"));
// not a perfect square
// 1234567890 * 1234567890, perfect square
var_dump(gmp_perfect_square("1524157875019052100"));
// gmp_popcount
$pop1 = gmp_init("10000101", 2);
// 3 1's
echo gmp_popcount($pop1) . "\n";
$pop2 = gmp_init("11111110", 2);
// 7 1's
echo gmp_popcount($pop2) . "\n";
// gmp_pow
$pow1 = gmp_pow("2", 31);
echo gmp_strval($pow1) . "\n";
$pow2 = gmp_pow("0", 0);
echo gmp_strval($pow2) . "\n";
$pow3 = gmp_pow("2", -1);
// Negative exp, generates warning
echo gmp_strval($pow3) . "\n";
示例#3
0
<?php

var_dump(gmp_perfect_square(0));
var_dump(gmp_perfect_square("0"));
var_dump(gmp_perfect_square(-1));
var_dump(gmp_perfect_square(1));
var_dump(gmp_perfect_square(16));
var_dump(gmp_perfect_square(17));
var_dump(gmp_perfect_square("1000000"));
var_dump(gmp_perfect_square("1000001"));
$n = gmp_init(100101);
var_dump(gmp_perfect_square($n));
$n = gmp_init(64);
var_dump(gmp_perfect_square($n));
$n = gmp_init(-5);
var_dump(gmp_perfect_square($n));
var_dump(gmp_perfect_square());
var_dump(gmp_perfect_square(array()));
echo "Done\n";