• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP bcsqrt函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中bcsqrt函数的典型用法代码示例。如果您正苦于以下问题:PHP bcsqrt函数的具体用法?PHP bcsqrt怎么用?PHP bcsqrt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了bcsqrt函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: stddev

/**
 * Compute standard deviation.
 *
 * @param array $a The array of data to find the standard deviation for.
 * Note that all values of the array will be cast to float.
 * @param bool $is_sample [Optional] Indicates if $a represents a sample of the
 * population (otherwise its the population); Defaults to false.
 * @return string|bool The standard deviation or false on error.
 */
function stddev(array $a, $is_sample = false)
{
    if (math_count($a) < 2) {
        trigger_error("The array has too few elements", E_USER_NOTICE);
        return false;
    }
    return bcsqrt(variance($a, $is_sample));
}
开发者ID:faozimipa,项目名称:PHP-Math,代码行数:17,代码来源:functions.php


示例2: generator

 /**
  * Generate a valid prime based on which php is used. Slower than the Prime generator.
  * @return \Generator
  */
 public static function generator()
 {
     $primes = ['2'];
     $currentNumber = '2';
     (yield '2');
     while (true) {
         ++$currentNumber;
         $unitNumber = (int) substr($currentNumber, -1);
         if (($currentNumber & 1) === 0) {
             continue;
         }
         $squareRoot = bcsqrt($currentNumber);
         $foundPrimeDivisor = false;
         foreach ($primes as $prime) {
             if (bccomp($prime, $squareRoot) === 1) {
                 break;
             }
             if (bcmod($currentNumber, $prime) === '0') {
                 $foundPrimeDivisor = true;
                 break;
             }
         }
         if (!$foundPrimeDivisor) {
             $primes[] = $currentNumber;
             (yield $currentNumber);
         }
     }
 }
开发者ID:tomzx,项目名称:project-euler,代码行数:32,代码来源:BigPrime.php


示例3: _bcpi

 protected function _bcpi($precision)
 {
     $num = 0;
     $k = 0;
     bcscale($precision + 3);
     $limit = ($precision + 3) / 14;
     while ($k < $limit) {
         $num = bcadd($num, bcdiv(bcmul(bcadd('13591409', bcmul('545140134', $k)), bcmul(bcpow(-1, $k), $this->_bcfact(6 * $k))), bcmul(bcmul(bcpow('640320', 3 * $k + 1), bcsqrt('640320')), bcmul($this->_bcfact(3 * $k), bcpow($this->_bcfact($k), 3)))));
         ++$k;
     }
     return bcdiv(1, bcmul(12, $num), $precision);
 }
开发者ID:uafrica,项目名称:delayed-jobs,代码行数:12,代码来源:ArkWorker.php


示例4: make

 public function make($value)
 {
     $n = $value;
     $factors = array();
     for ($divisor = 2; $n > 1 && $divisor <= bcsqrt($n); $divisor++) {
         for (; bcmod($n, $divisor) == 0; $n = bcdiv($n, $divisor)) {
             $factors[] = $divisor;
         }
     }
     if ($n > 1) {
         $factors[] = $n;
     }
     return $factors;
 }
开发者ID:viniciusferreira,项目名称:daily,代码行数:14,代码来源:Factors.php


示例5: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $items = explode('.', $input->getArgument('item'));
     $pointName = $items[0];
     $x1 = $items[1];
     $y1 = $items[2];
     $x2 = $items[3];
     $y2 = $items[4];
     // Used for mocking heavy execution.
     $sum = 0;
     for ($i = 1; $i <= 30000000; $i++) {
         $sum += $i;
     }
     $distance = bcsqrt(pow($x2 - $x1, 2) + pow($y2 - $y1, 2));
     $data = sprintf('Point %s: %s', $pointName, (string) $distance);
     file_put_contents(__DIR__ . '/../../../output/Point' . $pointName, print_r($data, 1), FILE_APPEND);
 }
开发者ID:vdrizheruk,项目名称:php-subprocess-example,代码行数:17,代码来源:SubProcessCommand.php


示例6: calcPi

 /**
  * Get decimal expansion of PI using Gauss-Lagendre algorithm.
  *
  * @link https://github.com/natmchugh/pi/blob/master/gauss-legendre.php
  * @link http://en.wikipedia.org/wiki/Calculate_pi#Modern_algorithms
  * @param $precision
  * @return string
  */
 public static function calcPi($precision)
 {
     $limit = ceil(log($precision) / log(2)) - 1;
     bcscale($precision + 6);
     $a = 1;
     $b = bcdiv(1, bcsqrt(2));
     $t = 1 / 4;
     $p = 1;
     for ($n = 0; $n < $limit; $n++) {
         $x = bcdiv(bcadd($a, $b), 2);
         $y = bcsqrt(bcmul($a, $b));
         $t = bcsub($t, bcmul($p, bcpow(bcsub($a, $x), 2)));
         $a = $x;
         $b = $y;
         $p = bcmul(2, $p);
     }
     return bcdiv(bcpow(bcadd($a, $b), 2), bcmul(4, $t), $precision);
 }
开发者ID:ralfeggert,项目名称:zftool,代码行数:26,代码来源:CpuPerformance.php


示例7: filter

 /**
  * @param array $map
  */
 public function filter(array $map)
 {
     $this->size = bcsqrt(count($map));
     $intermediateArray = $filteredArray = [];
     foreach (range(0, $this->size) as $x) {
         foreach (range(0, $this->size) as $y) {
             $index = $x + $y * $this->size;
             $intermediateArray[$index] = $this->computeXFilteredValue($map, $x, $y);
         }
     }
     foreach (range(0, $this->size) as $x) {
         foreach (range(0, $this->size) as $y) {
             $index = $x + $y * $this->size;
             $filteredArray[$index] = $this->computeYFilteredValue($intermediateArray, $x, $y);
         }
     }
     return $filteredArray;
 }
开发者ID:Myloth,项目名称:dominus,代码行数:21,代码来源:GaussianFilter.php


示例8: bcpi

function bcpi($precision)
{
    $limit = ceil(log($precision) / log(2)) - 1;
    bcscale($precision + 6);
    $a = 1;
    $b = bcdiv(1, bcsqrt(2));
    $t = 1 / 4;
    $p = 1;
    while ($n < $limit) {
        $x = bcdiv(bcadd($a, $b), 2);
        $y = bcsqrt(bcmul($a, $b));
        $t = bcsub($t, bcmul($p, bcpow(bcsub($a, $x), 2)));
        $a = $x;
        $b = $y;
        $p = bcmul(2, $p);
        ++$n;
    }
    return bcdiv(bcpow(bcadd($a, $b), 2), bcmul(4, $t), $precision);
}
开发者ID:exakat,项目名称:exakat,代码行数:19,代码来源:Extbcmath.01.php


示例9: next_prime

 function next_prime()
 {
     while (true) {
         $this->count = bcadd($this->count, '1');
         $sqrt = bcsqrt($this->count);
         $numfactors = 0;
         for ($factor = 1; $factor < $sqrt; $factor++) {
             $remainder = bcmod($this->count, $factor);
             if ($remainder == 0) {
                 $numfactors++;
             }
             if ($numfactors == 2) {
                 break;
                 // Not prime
             }
         }
         if ($numfactors < 2) {
             return $this->count;
         }
     }
 }
开发者ID:hemantshekhawat,项目名称:Snippets,代码行数:21,代码来源:prime.php


示例10: _sqrt

 public static function _sqrt($operand, $scale = 50)
 {
     if (function_exists("bcsqrt")) {
         return bcsqrt(ilMath::exp2dec($operand), $scale);
     } else {
         $res = sqrt($operand);
         if (is_numeric($scale)) {
             $res = round($res, $scale);
         }
         return $res;
     }
 }
开发者ID:Walid-Synakene,项目名称:ilias,代码行数:12,代码来源:class.ilMath.php


示例11: setValue

 /**
  * Set a new value
  *
  * @param  $value  mixed  - Value as string, integer, real or float
  * @param  $type   type   - OPTIONAL a Zend_Measure_Number Type
  * @param  $locale locale - OPTIONAL a Zend_Locale Type
  * @throws Zend_Measure_Exception
  */
 public function setValue($value, $type, $locale = false)
 {
     if (empty($locale)) {
         $locale = $this->_Locale;
     }
     if (empty(self::$_UNITS[$type])) {
         throw Zend::exception('Zend_Measure_Exception', 'unknown type of number:' . $type);
     }
     switch ($type) {
         case 'Number::BINARY':
             preg_match('/[01]+/', $value, $ergebnis);
             $value = $ergebnis[0];
             break;
         case 'Number::TERNARY':
             preg_match('/[012]+/', $value, $ergebnis);
             $value = $ergebnis[0];
             break;
         case 'Number::QUATERNARY':
             preg_match('/[0123]+/', $value, $ergebnis);
             $value = $ergebnis[0];
             break;
         case 'Number::QUINARY':
             preg_match('/[01234]+/', $value, $ergebnis);
             $value = $ergebnis[0];
             break;
         case 'Number::SENARY':
             preg_match('/[012345]+/', $value, $ergebnis);
             $value = $ergebnis[0];
             break;
         case 'Number::SEPTENARY':
             preg_match('/[0123456]+/', $value, $ergebnis);
             $value = $ergebnis[0];
             break;
         case 'Number::OCTAL':
             preg_match('/[01234567]+/', $value, $ergebnis);
             $value = $ergebnis[0];
             break;
         case 'Number::NONARY':
             preg_match('/[012345678]+/', $value, $ergebnis);
             $value = $ergebnis[0];
             break;
         case 'Number::DUODECIMAL':
             preg_match('/[0123456789AB]+/', strtoupper($value), $ergebnis);
             $value = $ergebnis[0];
             break;
         case 'Number::HEXADECIMAL':
             preg_match('/[0123456789ABCDEF]+/', strtoupper($value), $ergebnis);
             $value = $ergebnis[0];
             break;
         case 'Number::ROMAN':
             preg_match('/[IVXLCDM_]+/', strtoupper($value), $ergebnis);
             $value = $ergebnis[0];
             break;
         default:
             try {
                 $value = Zend_Locale_Format::getInteger($value, $locale);
             } catch (Exception $e) {
                 throw Zend::exception('Zend_Measure_Exception', $e->getMessage());
             }
             if (bccomp($value, 0) < 0) {
                 $value = bcsqrt(bcpow($value, 2));
             }
             break;
     }
     parent::setValue($value, $type, $locale);
     parent::setType($type);
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:75,代码来源:Number.php


示例12: 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);
 }
开发者ID:Esleelkartea,项目名称:kz-adeada-talleres-electricos-,代码行数:28,代码来源:IntegerOp.php


示例13: is_prime

	private static function is_prime($number){

		$limit = round(bcsqrt($number));
		
		$counter = 2;

		while ($counter <= $limit){

			if (bcmod($number, $counter) == 0){
				return true;
			}

			$counter ++;
		}
		return false;
	}
开发者ID:amitjoy,项目名称:Bank_of_Munchen,代码行数:16,代码来源:Generators.util.php


示例14: distance_in_feet

 /**
  * Provides the approximate distance in feet between two points.
  *
  * @param $lat1
  * @param $lat2
  * @param $long1
  * @param $long2
  * @return float
  */
 function distance_in_feet($lat1, $lat2, $long1, $long2, $scale = 6)
 {
     bcscale($scale);
     $r = 20902231;
     //feet
     $rlat1 = deg2rad($lat1);
     $rlat2 = deg2rad($lat2);
     $rdlat = deg2rad($lat2 - $lat1);
     $rdlong = deg2rad($long2 - $long1);
     $a = sin(bcdiv($rdlat, 2)) * sin(bcdiv($rdlat, 2)) + cos($rlat1) * cos($rlat2) * sin(bcdiv($rdlong, 2)) * sin(bcdiv($rdlong, 2));
     $c = bcmul(2, atan2(bcsqrt($a), bcsqrt(1 - $a)));
     return (double) ($r * $c);
 }
开发者ID:rogue780,项目名称:geo-helpers,代码行数:22,代码来源:helpers.php


示例15: sqrt

 /**
  * Returns the square root of this number
  *
  * @param  integer $scale  The number of places after the decimal - overrides the scale for this number
  * @return fNumber  The square root
  */
 public function sqrt($scale = NULL)
 {
     $scale = $this->fixScale($scale);
     if ($this->sign() == -1) {
         throw new fProgrammerException('This number, %s, can not have the square root calculated since it is a negative number', $this->value);
     }
     if (function_exists('bcsqrt')) {
         $value = bcsqrt($this->value, $scale);
         return new fNumber($value, $scale);
     }
     // Pure PHP implementation
     $parts = explode('.', $this->value);
     $integer = substr($parts[0], 1);
     $fraction = isset($parts[1]) ? $parts[1] : '';
     if (strlen($integer) % 2 == 1) {
         $integer = '0' . $integer;
     }
     if (strlen($fraction) % 2 == 1) {
         $fraction .= '0';
     }
     $after_decimal = strlen($fraction) / 2;
     $number = $integer . $fraction;
     $i = 0;
     $remainder = '0';
     $p = '0';
     $len = strlen($number);
     $len += $scale * 2 - $after_decimal > 0 ? $scale * 2 - $after_decimal : 0;
     while ($i < $len) {
         if ($i < strlen($number)) {
             $c = substr($number, $i, 2);
         } else {
             $c = '00';
             $after_decimal++;
         }
         if (!self::isZero($remainder)) {
             $c = $remainder . $c;
         }
         $x = -1;
         $p2 = self::performMul($p, '2');
         do {
             $x++;
         } while (self::cmp(self::performMul($p2 . $x, $x), $c) <= 0);
         $x--;
         $y = self::performMul($p2 . $x, $x);
         $p = $p ? $p . $x : $x;
         $remainder = self::performSub($c, $y);
         $i += 2;
     }
     if (strlen($p) <= $after_decimal) {
         $p = $p[0] . str_pad(substr($p, 1), $after_decimal + 1, '0', STR_PAD_LEFT);
     }
     $integer = substr($p, 0, strlen($p) - $after_decimal);
     $fraction = substr($p, strlen($p) - $after_decimal);
     $fraction = strlen($fraction) ? '.' . $fraction : '';
     $p = $integer . $fraction;
     $p = self::setScale($p, $scale);
     $p = self::stripLeadingZeroes($p);
     return new fNumber($p);
 }
开发者ID:gopalgrover23,项目名称:flourish-classes,代码行数:65,代码来源:fNumber.php


示例16: sqrt

 public static function sqrt($val, $scale = null)
 {
     $scale = static::getScale($scale);
     return bcsqrt($val, $scale);
 }
开发者ID:danhunsaker,项目名称:bcmath,代码行数:5,代码来源:BC.php


示例17: sqrt

 /**
  * Performs a square root operation with the given number.
  *
  * @return BigNumber
  */
 public function sqrt()
 {
     $newValue = bcsqrt($this->getValue(), $this->getScale());
     return $this->assignValue($newValue);
 }
开发者ID:phpmath,项目名称:bignumber,代码行数:10,代码来源:BigNumber.php


示例18: bcsqrt

<?php

echo bcsqrt('-9');
开发者ID:badlamer,项目名称:hhvm,代码行数:3,代码来源:bcsqrt_error1.php


示例19: performCalc

 /**
  * Function which performs calculation.
  * @param  string|integer|float|boolean $number1 See bcCalc description
  * @param  string $action See bcCalc description
  * @param  string|integer|float|boolean $number2 See bcCalc description
  * @param  boolean $round See bcCalc description
  * @param  integer $decimals See bcCalc description
  * @param  integer $precision See bcCalc description
  * @return integer|float|boolean
  */
 private static function performCalc($number1, $action, $number2, $round, $decimals, $precision)
 {
     $result = null;
     $compare = false;
     switch ($action) {
         case '+':
             $result = self::$blnBcmath ? bcadd($number1, $number2, $precision) : $number1 + $number2;
             break;
         case '-':
             $result = self::$blnBcmath ? bcsub($number1, $number2, $precision) : $number1 - $number2;
             break;
         case '*':
             $result = self::$blnBcmath ? bcmul($number1, $number2, $precision) : $number1 * $number2;
             break;
         case 'sqrt':
             $result = self::$blnBcmath ? bcsqrt($number1, $precision) : sqrt($number1);
             break;
         case '/':
             if ($number2 > 0) {
                 if (self::$blnBcmath) {
                     $result = bcdiv($number1, $number2, $precision);
                     // string, or NULL if right_operand is 0
                 } else {
                     if ($number2 != 0) {
                         $result = $number1 / $number2;
                     }
                 }
             }
             if (!isset($result)) {
                 $result = 0;
             }
             break;
         case '%':
             if (self::$blnBcmath) {
                 $result = bcmod($number1, $number2);
                 // string, or NULL if modulus is 0.
             } else {
                 if ($number2 != 0) {
                     $result = $number1 % $number2;
                 }
             }
             if (!isset($result)) {
                 $result = 0;
             }
             break;
         case '=':
             $compare = true;
             if (self::$blnBcmath) {
                 $result = bccomp($number1, $number2, $precision);
                 // returns int 0, 1 or -1
             } else {
                 $result = $number1 == $number2 ? 0 : ($number1 > $number2 ? 1 : -1);
             }
             break;
     }
     if (isset($result)) {
         if ($compare === false) {
             if ($round === true) {
                 $result = round(floatval($result), $decimals);
                 if ($decimals === 0) {
                     $result = (int) $result;
                 }
             } else {
                 $result = intval($result) == $result ? intval($result) : floatval($result);
             }
         }
         return $result;
     }
     return false;
 }
开发者ID:nystudio107,项目名称:seomatic,代码行数:80,代码来源:Maths.php


示例20: sqrt

 /**
  * Calculates the square root of the operand
  *
  * @param string $operand The operand, as a string.
  * @param integer $precision The optional scale parameter is used to set the number of digits after the decimal place
  * @return string Return the square root of the operand.
  */
 public static function sqrt($operand, $precision = null)
 {
     return self::clean(is_null($precision) ? bcsqrt($operand) : bcsqrt($operand, $precision));
 }
开发者ID:poef,项目名称:ariadne,代码行数:11,代码来源:Math.php



注:本文中的bcsqrt函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP bcsub函数代码示例发布时间:2022-05-24
下一篇:
PHP bcscale函数代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap