本文整理汇总了PHP中gmp_sqrt函数的典型用法代码示例。如果您正苦于以下问题:PHP gmp_sqrt函数的具体用法?PHP gmp_sqrt怎么用?PHP gmp_sqrt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了gmp_sqrt函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sqrt
/**
* @param string $left_operand
* @param string $right_operand
* @return string
*/
public function sqrt($operand)
{
$result = gmp_sqrt($operand);
return gmp_strval($result);
}
示例2: var_dump
<?php
var_dump(gmp_strval(gmp_sqrt(-2)));
var_dump(gmp_strval(gmp_sqrt("-2")));
var_dump(gmp_strval(gmp_sqrt("0")));
var_dump(gmp_strval(gmp_sqrt("2")));
var_dump(gmp_strval(gmp_sqrt("144")));
$n = gmp_init(0);
var_dump(gmp_strval(gmp_sqrt($n)));
$n = gmp_init(-144);
var_dump(gmp_strval(gmp_sqrt($n)));
$n = gmp_init(777);
var_dump(gmp_strval(gmp_sqrt($n)));
var_dump(gmp_sqrt($n, 1));
var_dump(gmp_sqrt());
var_dump(gmp_sqrt(array()));
echo "Done\n";
示例3: switch
/**
* Returns the (integer) square root of a Math_Integer number
*
* @param object Math_Integer $int1
* @return object Math_Integer on success, PEAR_Error otherwise
* @access public
*/
function &sqrt(&$int1)
{
/*{{{*/
if (PEAR::isError($err = Math_IntegerOp::_validInt($int1))) {
return $err;
}
switch (MATH_INTLIB) {
/*{{{*/
case 'gmp':
$tmp = gmp_strval(gmp_sqrt($int1->getValue()));
break;
case 'bcmath':
$tmp = bcsqrt(-1, $int1->getValue());
break;
case 'std':
$tmp = intval(sqrt($int1->getValue()));
break;
}
/*}}}*/
return new Math_Integer($tmp);
}
示例4: bcsqrt
function bcsqrt($x)
{
return gmp_strval(gmp_sqrt($x));
}
示例5: gmp_init
$a = gmp_init("0xff");
echo gmp_strval($a), ' -> 0b', gmp_strval($a, 2), "\n";
gmp_setbit($a, 0, false);
// clear bit at index 0
echo gmp_strval($a), ' -> 0b', gmp_strval($a, 2), "\n";
// gmp_sign
echo gmp_sign("500") . "\n";
// positive
echo gmp_sign("-500") . "\n";
// negative
echo gmp_sign("0") . "\n";
// zero
// gmp_sqrt
$sqrt1 = gmp_sqrt("9");
$sqrt2 = gmp_sqrt("7");
$sqrt3 = gmp_sqrt("1524157875019052100");
echo gmp_strval($sqrt1) . "\n";
echo gmp_strval($sqrt2) . "\n";
echo gmp_strval($sqrt3) . "\n";
// gmp_sqrtrem
list($sqrt1, $sqrt1rem) = gmp_sqrtrem("9");
list($sqrt2, $sqrt2rem) = gmp_sqrtrem("7");
list($sqrt3, $sqrt3rem) = gmp_sqrtrem("1048576");
echo gmp_strval($sqrt1) . ", " . gmp_strval($sqrt1rem) . "\n";
echo gmp_strval($sqrt2) . ", " . gmp_strval($sqrt2rem) . "\n";
echo gmp_strval($sqrt3) . ", " . gmp_strval($sqrt3rem) . "\n";
// gmp_strval
$a = gmp_init("0x41682179fbf5");
printf("Decimal: %s, 36-based: %s" . PHP_EOL, gmp_strval($a), gmp_strval($a, 36));
// gmp_sub
$sub = gmp_sub("281474976710656", "4294967296");
示例6: Sqr
public function Sqr($left)
{
return $this->string(gmp_sqrt($left));
}
示例7: sqrt
/**
* Get the square route
*
* @access public
* @return self
*/
public function sqrt()
{
$result = gmp_sqrt($this->getRawValue());
return static::factory($result);
}
示例8: sqrt
/**
* @param string $left_operand
* @param string $right_operand
* @return string
*/
public function sqrt($operand)
{
return gmp_strval(gmp_sqrt($operand));
}
示例9: primeFactors
/**
* Return all prime factors of this number
*
* The keys (prime factors) will be strings
* The values (exponents will be integers
*
* Adapted from http://www.thatsgeeky.com/2011/03/prime-factoring-with-php/
*
* @return array [primeFactor => exponent,...]
*/
public function primeFactors()
{
$number = $this->cloneValue();
$divisor = 2;
$zero = gmp_init(0);
$one = gmp_init(1);
$dmax = gmp_sqrt($number);
$factors = array();
$sieve = array_fill(1, intval(gmp_strval($dmax)), 1);
do {
$rFlag = false;
while (gmp_cmp(gmp_mod($number, $divisor), $zero) == 0) {
$factors[$divisor] = isset($factors[$divisor]) ? $factors[$divisor] + 1 : 1;
$number = gmp_div_q($number, $divisor);
$rFlag = true;
}
if ($rFlag) {
$dmax = gmp_sqrt($number);
}
if (gmp_cmp($number, $one) > 0) {
for ($i = $divisor; gmp_cmp($i, $dmax) <= 0; $i += $divisor) {
$sieve[$i] = 0;
}
do {
$divisor++;
} while (gmp_cmp($divisor, $dmax) < 0 && $sieve[$divisor] != 1);
if (gmp_cmp($divisor, $dmax) > 0) {
$key = gmp_strval($number);
$factors[$key] = isset($factors[$key]) ? $factors[$key] + 1 : 1;
}
}
} while (gmp_cmp($number, $one) > 0 && gmp_cmp($divisor, $dmax) <= 0);
return $factors;
}
示例10: sqrt
/**
* Calculates & returns the integer portion of the square root.
*
* @param string $a The first number.
* @return string
*/
public function sqrt($a)
{
return gmp_strval(gmp_sqrt($a));
}