本文整理汇总了PHP中sqrt函数的典型用法代码示例。如果您正苦于以下问题:PHP sqrt函数的具体用法?PHP sqrt怎么用?PHP sqrt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sqrt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: CreateOnePlanetRecord
/**
* 2Moons
* Copyright (C) 2012 Jan Kröpke
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package 2Moons
* @author Jan Kröpke <info@2moons.cc>
* @copyright 2012 Jan Kröpke <info@2moons.cc>
* @license http://www.gnu.org/licenses/gpl.html GNU GPLv3 License
* @version 1.7.3 (2013-05-19)
* @info $Id: CreateOnePlanetRecord.php 2640 2013-03-23 19:23:26Z slaver7 $
* @link http://2moons.cc/
*/
function CreateOnePlanetRecord($Galaxy, $System, $Position, $Universe, $PlanetOwnerID, $PlanetName, $HomeWorld = false, $AuthLevel = 0, $Iron, $Gold, $Crystal, $Elyrium, $iPlanetCount)
{
global $LNG;
$CONF = Config::getAll(NULL, $Universe);
if (Config::get('max_galaxy') < $Galaxy || 1 > $Galaxy) {
throw new Exception("Access denied for CreateOnePlanetRecord.php.<br>Try to create a planet at position:" . $Galaxy . ":" . $System . ":" . $Position);
}
if (Config::get('max_system') < $System || 1 > $System) {
throw new Exception("Access denied for CreateOnePlanetRecord.php.<br>Try to create a planet at position:" . $Galaxy . ":" . $System . ":" . $Position);
}
if (Config::get('max_planets') < $Position || 1 > $Position) {
throw new Exception("Access denied for CreateOnePlanetRecord.php.<br>Try to create a planet at position:" . $Galaxy . ":" . $System . ":" . $Position);
}
if (CheckPlanetIfExist($Galaxy, $System, $Position, $Universe)) {
return false;
}
$tp = 0;
if ($iPlanetCount >= 3) {
$tp = 1;
}
$FieldFactor = Config::get('planet_factor');
require 'includes/PlanetData.php';
$Pos = ceil($Position / (Config::get('max_planets') / count($PlanetData)));
$TMax = $PlanetData[$Pos]['temp'];
$TMin = $TMax - 40;
$Fields = $PlanetData[$Pos]['fields'] * Config::get('planet_factor');
$Types = $PlanetData[$Pos]['image'];
$Name = !empty($PlanetName) ? $GLOBALS['DATABASE']->sql_escape($PlanetName) : $LNG['type_planet'][1];
$GLOBALS['DATABASE']->query("INSERT INTO " . PLANETS . " SET\n\t\t\t\tname = '" . $Name . "',\n\t\t\t\tuniverse = " . $Universe . ",\n\t\t\t\tid_owner = " . $PlanetOwnerID . ",\n\t\t\t\tgalaxy = " . $Galaxy . ",\n\t\t\t\tsystem = " . $System . ",\n\t\t\t\tplanet = " . $Position . ",\n\t\t\t\tlast_update = " . TIMESTAMP . ",\n\t\t\t\tplanet_type = '1',\n\t\t\t\tcolo_metal = " . $Iron . ",\n\t\t\t\tcolo_crystal = " . $Gold . ",\n\t\t\t\tcolo_deut = " . $Crystal . ",\n\t\t\t\tcolo_elyrium = " . $Elyrium . ",\n\t\t\t\tteleport_portal = " . $tp . ",\n\t\t\t\timage = '" . $Types . "',\n\t\t\t\tdiameter = " . floor(1000 * sqrt($Fields)) . ",\n\t\t\t\tfield_max = " . ($HomeWorld ? Config::get('initial_fields') : floor($Fields)) . ",\n\t\t\t\ttemp_min = " . $TMin . ",\n\t\t\t\ttemp_max = " . $TMax . ",\n\t\t\t\tmetal = " . Config::get('metal_start') . ",\n\t\t\t\tmetal_perhour = " . Config::get('metal_basic_income') . ",\n\t\t\t\tcrystal = " . Config::get('crystal_start') . ",\n\t\t\t\tcrystal_perhour = " . Config::get('crystal_basic_income') . ",\n\t\t\t\tdeuterium = " . Config::get('deuterium_start') . ",\n\t\t\t\tdeuterium_perhour = " . Config::get('deuterium_basic_income') . ",\n\t\t\t\telyrium = " . Config::get('deuterium_start') . ",\n\t\t\t\telyrium_perhour = " . Config::get('deuterium_basic_income') . ";");
return $GLOBALS['DATABASE']->GetInsertID();
}
示例2: roundedRect
public function roundedRect($xPosition, $yPosition, $width, $height, $round, $style = '')
{
$k = $this->k;
$hp = $this->h;
if ($style == 'F') {
$op = 'f';
} elseif ($style == 'FD' || $style == 'DF') {
$op = 'B';
} else {
$op = 'S';
}
$MyArc = 4 / 3 * (sqrt(2) - 1);
$this->_out(sprintf('%.2F %.2F m', ($xPosition + $round) * $k, ($hp - $yPosition) * $k));
$xc = $xPosition + $width - $round;
$yc = $yPosition + $round;
$this->_out(sprintf('%.2F %.2F l', $xc * $k, ($hp - $yPosition) * $k));
$this->arcFunction($xc + $round * $MyArc, $yc - $round, $xc + $round, $yc - $round * $MyArc, $xc + $round, $yc);
$xc = $xPosition + $width - $round;
$yc = $yPosition + $height - $round;
$this->_out(sprintf('%.2F %.2F l', ($xPosition + $width) * $k, ($hp - $yc) * $k));
$this->arcFunction($xc + $round, $yc + $round * $MyArc, $xc + $round * $MyArc, $yc + $round, $xc, $yc + $round);
$xc = $xPosition + $round;
$yc = $yPosition + $height - $round;
$this->_out(sprintf('%.2F %.2F l', $xc * $k, ($hp - ($yPosition + $height)) * $k));
$this->arcFunction($xc - $round * $MyArc, $yc + $round, $xc - $round, $yc + $round * $MyArc, $xc - $round, $yc);
$xc = $xPosition + $round;
$yc = $yPosition + $round;
$this->_out(sprintf('%.2F %.2F l', $xPosition * $k, ($hp - $yc) * $k));
$this->arcFunction($xc - $round, $yc - $round * $MyArc, $xc - $round * $MyArc, $yc - $round, $xc, $yc - $round);
$this->_out($op);
}
示例3: isprime
function isprime($x)
{
if ($x < 2) {
return false;
}
if ($x < 4) {
return true;
}
if ($x == 5) {
return true;
}
if ($x % 2 == 0) {
return false;
}
if ($x % 5 == 0) {
return false;
}
if (($x + 1) % 6 != 0) {
if (($x - 1) % 6 != 0) {
return false;
}
}
$lim = sqrt($x) + 1.0;
for ($y = 3; $y < $lim; $y += 2) {
if ($x % $y == 0) {
return false;
}
}
return true;
}
示例4: relationDraw
/**
* draws relation links and arrows shows foreign key relations
*
* @param boolean $showColor Whether to use one color per relation or not
* @param integer $i The id of the link to draw
*
* @global object $pdf The current PDF document
*
* @access public
*
* @return void
*
* @see PMA_Schema_PDF
*/
public function relationDraw($showColor, $i)
{
global $pdf;
if ($showColor) {
$d = $i % 6;
$j = ($i - $d) / 6;
$j = $j % 4;
$j++;
$case = array(array(1, 0, 0), array(0, 1, 0), array(0, 0, 1), array(1, 1, 0), array(1, 0, 1), array(0, 1, 1));
list($a, $b, $c) = $case[$d];
$e = 1 - ($j - 1) / 6;
$pdf->SetDrawColor($a * 255 * $e, $b * 255 * $e, $c * 255 * $e);
} else {
$pdf->SetDrawColor(0);
}
$pdf->setLineWidthScale(0.2);
$pdf->lineScale($this->xSrc, $this->ySrc, $this->xSrc + $this->srcDir * $this->wTick, $this->ySrc);
$pdf->lineScale($this->xDest + $this->destDir * $this->wTick, $this->yDest, $this->xDest, $this->yDest);
$pdf->setLineWidthScale(0.1);
$pdf->lineScale($this->xSrc + $this->srcDir * $this->wTick, $this->ySrc, $this->xDest + $this->destDir * $this->wTick, $this->yDest);
/*
* Draws arrows ->
*/
$root2 = 2 * sqrt(2);
$pdf->lineScale($this->xSrc + $this->srcDir * $this->wTick * 0.75, $this->ySrc, $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick, $this->ySrc + $this->wTick / $root2);
$pdf->lineScale($this->xSrc + $this->srcDir * $this->wTick * 0.75, $this->ySrc, $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick, $this->ySrc - $this->wTick / $root2);
$pdf->lineScale($this->xDest + $this->destDir * $this->wTick / 2, $this->yDest, $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick, $this->yDest + $this->wTick / $root2);
$pdf->lineScale($this->xDest + $this->destDir * $this->wTick / 2, $this->yDest, $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick, $this->yDest - $this->wTick / $root2);
$pdf->SetDrawColor(0);
}
示例5: dist
/**
* see class description
*
* @param array $A
* Either a vector or a collection of tokens to be transformed to a vector
* @param array $B
* Either a vector or a collection of tokens to be transformed to a vector
* @return float The euclidean distance between $A and $B
*/
public function dist(&$A, &$B)
{
if (is_int(key($A))) {
$v1 = array_count_values($A);
} else {
$v1 =& $A;
}
if (is_int(key($B))) {
$v2 = array_count_values($B);
} else {
$v2 =& $B;
}
$r = array();
foreach ($v1 as $k => $v) {
$r[$k] = $v;
}
foreach ($v2 as $k => $v) {
if (isset($r[$k])) {
$r[$k] -= $v;
} else {
$r[$k] = $v;
}
}
return sqrt(array_sum(array_map(function ($x) {
return $x * $x;
}, $r)));
}
示例6: __construct
/**
* CholeskyDecomposition
*
* Class constructor - decomposes symmetric positive definite matrix
* @param mixed Matrix square symmetric positive definite matrix
*/
public function __construct($A = null)
{
if ($A instanceof Matrix) {
$this->L = $A->getArray();
$this->m = $A->getRowDimension();
for ($i = 0; $i < $this->m; ++$i) {
for ($j = $i; $j < $this->m; ++$j) {
for ($sum = $this->L[$i][$j], $k = $i - 1; $k >= 0; --$k) {
$sum -= $this->L[$i][$k] * $this->L[$j][$k];
}
if ($i == $j) {
if ($sum >= 0) {
$this->L[$i][$i] = sqrt($sum);
} else {
$this->isspd = false;
}
} else {
if ($this->L[$i][$i] != 0) {
$this->L[$j][$i] = $sum / $this->L[$i][$i];
}
}
}
for ($k = $i + 1; $k < $this->m; ++$k) {
$this->L[$i][$k] = 0.0;
}
}
} else {
throw new Exception(JAMAError(ArgumentTypeException));
}
}
示例7: getPerpendicularDistance
/**
* @param Coordinate $point
* @param Line $line
*
* @return float
*/
public function getPerpendicularDistance(Coordinate $point, Line $line)
{
$ellipsoid = $point->getEllipsoid();
$ellipsoidRadius = $ellipsoid->getArithmeticMeanRadius();
$firstLinePointLat = $this->deg2radLatitude($line->getPoint1()->getLat());
$firstLinePointLng = $this->deg2radLongitude($line->getPoint1()->getLng());
$firstLinePointX = $ellipsoidRadius * cos($firstLinePointLng) * sin($firstLinePointLat);
$firstLinePointY = $ellipsoidRadius * sin($firstLinePointLng) * sin($firstLinePointLat);
$firstLinePointZ = $ellipsoidRadius * cos($firstLinePointLat);
$secondLinePointLat = $this->deg2radLatitude($line->getPoint2()->getLat());
$secondLinePointLng = $this->deg2radLongitude($line->getPoint2()->getLng());
$secondLinePointX = $ellipsoidRadius * cos($secondLinePointLng) * sin($secondLinePointLat);
$secondLinePointY = $ellipsoidRadius * sin($secondLinePointLng) * sin($secondLinePointLat);
$secondLinePointZ = $ellipsoidRadius * cos($secondLinePointLat);
$pointLat = $this->deg2radLatitude($point->getLat());
$pointLng = $this->deg2radLongitude($point->getLng());
$pointX = $ellipsoidRadius * cos($pointLng) * sin($pointLat);
$pointY = $ellipsoidRadius * sin($pointLng) * sin($pointLat);
$pointZ = $ellipsoidRadius * cos($pointLat);
$normalizedX = $firstLinePointY * $secondLinePointZ - $firstLinePointZ * $secondLinePointY;
$normalizedY = $firstLinePointZ * $secondLinePointX - $firstLinePointX * $secondLinePointZ;
$normalizedZ = $firstLinePointX * $secondLinePointY - $firstLinePointY * $secondLinePointX;
$length = sqrt($normalizedX * $normalizedX + $normalizedY * $normalizedY + $normalizedZ * $normalizedZ);
$normalizedX /= $length;
$normalizedY /= $length;
$normalizedZ /= $length;
$thetaPoint = $normalizedX * $pointX + $normalizedY * $pointY + $normalizedZ * $pointZ;
$length = sqrt($pointX * $pointX + $pointY * $pointY + $pointZ * $pointZ);
$thetaPoint /= $length;
$distance = abs(M_PI / 2 - acos($thetaPoint));
return $distance * $ellipsoidRadius;
}
示例8: calc_distance
function calc_distance($r1, $a1, $r2, $a2)
{
assert($r1 >= 0);
assert($a1 >= 0 && $a1 <= 360000);
assert($r2 >= 0);
assert($a2 >= 0 && $a2 <= 360000);
// First, calculate X1,Y1 and X2,Y2, the coordinates inside the
// (virtual) galaxy grid
$Y1 = $r1 * cos(deg2rad($a1 / 1000));
// RADS! Which in fact, doesn't mind
// since all points are virtual
$X1 = $r1 * sin(deg2rad($a1 / 1000));
$Y2 = $r2 * cos(deg2rad($a2 / 1000));
$X2 = $r2 * sin(deg2rad($a2 / 1000));
// Get the (absolute) delta of the 2 points
$DX = abs($X1 - $X2);
$DY = abs($Y1 - $Y2);
// Pythagoras says: c^2 = a^2 + b^2. At least, he used to say, he's dead now...
$c = sqrt($DX * $DX + $DY * $DY);
// round ($c, 4); // PHP >= 4.0.4??
$c = $c * 1000;
// Keep 3 digits after the comma
$c = round($c);
// Round it
$c = $c / 1000;
// And back with those digits...
return $c;
// Return schuine zijde
}
示例9: Prime
function Prime($n)
{
$count = 0;
$primeNumber = 0;
if ($n < 2) {
if ($n == 1) {
$count = 1;
$primeNumber = 2;
}
} else {
$count = 2;
$primeNumber = 3;
}
for ($k = 5; $count < $n; $k += 2) {
if (($k + 1) % 6 == 0 || ($k - 1) % 6 == 0) {
$isTrivial = True;
$limit = ceil(sqrt($k));
for ($i = 5; $i <= $limit; $i += 2) {
if ($k % $i == 0) {
$isTrivial = False;
break;
}
}
if ($isTrivial) {
$count++;
$primeNumber = $k;
}
}
}
return $primeNumber;
}
示例10: Calc
public function Calc()
{
$this->icalculated = true;
$n = count($this->ix);
$sx2 = 0;
$sy2 = 0;
$sxy = 0;
$sx = 0;
$sy = 0;
for ($i = 0; $i < $n; ++$i) {
$sx2 += $this->ix[$i] * $this->ix[$i];
$sy2 += $this->iy[$i] * $this->iy[$i];
$sxy += $this->ix[$i] * $this->iy[$i];
$sx += $this->ix[$i];
$sy += $this->iy[$i];
}
if ($n * $sx2 - $sx * $sx > __LR_EPSILON) {
$this->ib = ($n * $sxy - $sx * $sy) / ($n * $sx2 - $sx * $sx);
$this->ia = ($sy - $this->ib * $sx) / $n;
$sx = $this->ib * ($sxy - $sx * $sy / $n);
$sy2 = $sy2 - $sy * $sy / $n;
$sy = $sy2 - $sx;
$this->iDet = $sx / $sy2;
$this->iCorr = sqrt($this->iDet);
if ($n > 2) {
$this->iStdErr = sqrt($sy / ($n - 2));
} else {
$this->iStdErr = NAN;
}
} else {
$this->ib = 0;
$this->ia = 0;
}
}
示例11: inverse
public function inverse($p)
{
$lon;
$lat;
$p->x = ($p->x - $this->x0) / $this->a;
/* descale and de-offset */
$p->y = ($p->y - $this->y0) / $this->a;
$p->x /= $this->k0;
$p->y /= $this->k0;
if ($rho = sqrt($p->x * $p->x + $p->y * $p->y)) {
$c = 2.0 * atan2($rho, $this->R2);
$sinc = sin($c);
$cosc = cos($c);
$lat = asin($cosc * $this->sinc0 + $p->y * $sinc * $this->cosc0 / $rho);
$lon = atan2($p->x * $sinc, $rho * $this->cosc0 * $cosc - $p->y * $this->sinc0 * $sinc);
} else {
$lat = $this->phic0;
$lon = 0.0;
}
$p->x = $lon;
$p->y = $lat;
Proj4php::$proj['gauss']->inverse->apply($this, array($p));
$p->x = Proj4php::$common->adjust_lon($p->x + $this->long0);
/* adjust longitude to CM */
return $p;
}
示例12: testWorks
/**
* @depends testDiLog
*/
public function testWorks()
{
$partitions = array();
for ($i = 1; $i <= 100; $i++) {
$partitions[$i] = new Partition(array('treatment' => "{$i}", 'size' => 1));
}
$treatments = array();
for ($i = 0; $i < 100; $i++) {
$treatments[$i] = 0;
}
$n = 100000;
$p = 0.01;
for ($i = 0; $i < $n; $i++) {
$key = uniqid('', true);
$treatment = Splitter::getTreatment($key, 32126754, $partitions);
$treatments[(int) $treatment - 1]++;
}
$mean = $n * $p;
$stddev = sqrt($mean * (1 - $p));
$min = (int) ($mean - 4 * $stddev);
$max = (int) ($mean + 4 * $stddev);
$range = range($min, $max);
for ($i = 0; $i < count($treatments); $i++) {
$message = "Value: " . $treatments[$i] . " is out of range " . print_r($range, true);
$this->assertTrue(in_array($treatments[$i], $range), $message);
}
}
示例13: __construct
/**
* Create a Distance object
*
* @param string latitude of first point
* @param string longitude of first point
* @param string latitude2 of second point
* @param string longitude2 of second point
* @param bool True if the distance is in Kms, otherwise returns Miles
*/
public function __construct($latitude = 0, $longitude = 0, $latitude2 = 0, $longitude2 = 0, $in_kms = TRUE)
{
$EARTH_RADIUS_MILES = 3963;
// Miles
$miles2kms = 1.609;
$dist = 0;
// Convert degrees to radians
$latitude = $latitude * M_PI / 180;
$longitude = $longitude * M_PI / 180;
$latitude2 = $latitude2 * M_PI / 180;
$longitude2 = $longitude2 * M_PI / 180;
if ($latitude != $latitude2 || $longitude != $longitude2) {
// The two points are not the same
$dist = sin($latitude) * sin($latitude2) + cos($latitude) * cos($latitude2) * cos($longitude2 - $longitude);
// Safety check
if ($dist > 0) {
$sqrt = sqrt(1 - $dist * $dist);
if ($sqrt > 0) {
$dist = $EARTH_RADIUS_MILES * (-1 * atan($dist / $sqrt) + M_PI / 2);
}
}
}
if ($in_kms) {
$dist = $dist * $miles2kms;
}
$this->dist = round($dist, 2);
}
示例14: ClippingRoundedRect
function ClippingRoundedRect($x, $y, $w, $h, $r, $outline = false)
{
$k = $this->k;
$hp = $this->h;
$op = $outline ? 'S' : 'n';
$MyArc = 4 / 3 * (sqrt(2) - 1);
$this->_out(sprintf('q %.2F %.2F m', ($x + $r) * $k, ($hp - $y) * $k));
$xc = $x + $w - $r;
$yc = $y + $r;
$this->_out(sprintf('%.2F %.2F l', $xc * $k, ($hp - $y) * $k));
$this->_Arc($xc + $r * $MyArc, $yc - $r, $xc + $r, $yc - $r * $MyArc, $xc + $r, $yc);
$xc = $x + $w - $r;
$yc = $y + $h - $r;
$this->_out(sprintf('%.2F %.2F l', ($x + $w) * $k, ($hp - $yc) * $k));
$this->_Arc($xc + $r, $yc + $r * $MyArc, $xc + $r * $MyArc, $yc + $r, $xc, $yc + $r);
$xc = $x + $r;
$yc = $y + $h - $r;
$this->_out(sprintf('%.2F %.2F l', $xc * $k, ($hp - ($y + $h)) * $k));
$this->_Arc($xc - $r * $MyArc, $yc + $r, $xc - $r, $yc + $r * $MyArc, $xc - $r, $yc);
$xc = $x + $r;
$yc = $y + $r;
$this->_out(sprintf('%.2F %.2F l', $x * $k, ($hp - $yc) * $k));
$this->_Arc($xc - $r, $yc - $r * $MyArc, $xc - $r * $MyArc, $yc - $r, $xc, $yc - $r);
$this->_out(' W ' . $op);
}
示例15: codesword_sd_ohlc
function codesword_sd_ohlc($real, $period = 20)
{
$std_dev = [];
$k = 2;
//the standard deviation multiplier
$ctr = 0;
for ($i = $period - 1; $i < count($real); $i++) {
//get the mean/average
$sum = 0;
for ($j = 0; $j < $period; $j++) {
$temp = $i - $j;
$sum += $real[$temp][4];
}
$fMean = $sum / $period;
//compute the variance
$fVariance = 0;
for ($j = 0; $j < $period; $j++) {
$temp = $i - $j;
$fVariance += pow($real[$temp][4] - $fMean, 2);
}
$fVariance = $fVariance / $period;
//timestamp value
$std_dev[$ctr][0] = $real[$i][0];
//mean value
$std_dev[$ctr][1] = $fMean;
//standard deviation value
$std_dev[$ctr][2] = round(sqrt($fVariance), 4);
$ctr++;
}
return $std_dev;
}