Exemplo n.º 1
0
 private function calDistance($from = 1, $to = 2)
 {
     $x = self::$pos[$from][0] - self::$pos[$to][0];
     $y = self::$pos[$from][1] - self::$pos[$to][1];
     $key = "{$x}->{$y}";
     if (!isset(self::$dis_cache[$key])) {
         self::$dis_cache[$key] = round(hypot(abs($x), abs($y)), 2);
         //近似计算
     }
     return self::$dis_cache[$key];
 }
Exemplo n.º 2
0
 /**
  * @param $y
  * @return $this
  * @desc 计算直角三角形的斜边长度。
  */
 public function hypot($y)
 {
     $this->current = hypot($this->toDouble(), doubleval($y));
     return $this;
 }
Exemplo n.º 3
0
 public function distance(Point $other)
 {
     return hypot($this->x - $other->x, $this->y - $other->y);
 }
Exemplo n.º 4
0
<?php

define("MAX_64Bit", 9223372036854775807);
define("MAX_32Bit", 2147483647);
define("MIN_64Bit", -9223372036854775807 - 1);
define("MIN_32Bit", -2147483647 - 1);
$longVals = array(MAX_64Bit, MIN_64Bit, MAX_32Bit, MIN_32Bit, MAX_64Bit - MAX_32Bit, MIN_64Bit - MIN_32Bit, MAX_32Bit + 1, MIN_32Bit - 1, MAX_32Bit * 2, MAX_32Bit * 2 + 1, MAX_32Bit * 2 - 1, MAX_64Bit - 1, MAX_64Bit + 1, MIN_64Bit + 1, MIN_64Bit - 1);
$otherVals = array(0, 1, -1, 7, 9, 65, -44, MAX_32Bit, MIN_32Bit, MAX_64Bit, MIN_64Bit);
foreach ($longVals as $longVal) {
    foreach ($otherVals as $otherVal) {
        echo "--- testing: {$longVal}, {$otherVal} ---\n";
        var_dump(hypot($longVal, $otherVal));
    }
}
?>
===DONE===
Exemplo n.º 5
0
 /**
  * Method to calculate the points and data of a triangle.
  *
  * @param  array $point
  * @param  array $center
  * @param  int   $quad
  * @return array
  */
 protected function getTriangle($point, $center, $quad)
 {
     $tri = array();
     switch ($quad) {
         case 1:
             $tri['side1'] = $point['x'] - $center['x'];
             $tri['side2'] = abs($point['y'] - $center['y']);
             break;
         case 2:
             $tri['side1'] = $center['x'] - $point['x'];
             $tri['side2'] = abs($point['y'] - $center['y']);
             break;
         case 3:
             $tri['side1'] = $center['x'] - $point['x'];
             $tri['side2'] = abs($center['y'] - $point['y']);
             break;
         case 4:
             $tri['side1'] = $point['x'] - $center['x'];
             $tri['side2'] = abs($center['y'] - $point['y']);
             break;
     }
     $tri['hypot'] = round(hypot($tri['side1'], $tri['side2']));
     $tri['angle1'] = round(rad2deg(asin($tri['side2'] / $tri['hypot'])));
     $tri['angle2'] = round(rad2deg(asin($tri['side1'] / $tri['hypot'])));
     return $tri;
 }
 /**
  * @param float $x A number
  * @param float $y A number
  * @param float $z_ Optional variable list of additional numbers
  * @return float The square root of the sum of squares of the arguments
  */
 public function hypot($x, $y, $z_ = null)
 {
     if ($z_ === null) {
         return hypot($x, $y);
     }
     $sum = 0;
     foreach (func_get_args() as $value) {
         $sum += $value * $value;
     }
     return sqrt($sum);
 }
Exemplo n.º 7
0
 * Description: Calculate the length of the hypotenuse of a right-angle triangle
 * Source code: ext/standard/math.c
 */
echo "*** Testing hypot() : usage variations ***\n";
//get an unset variable
$unset_var = 10;
unset($unset_var);
// heredoc string
$heredoc = <<<EOT
abc
xyz
EOT;
// get a class
class classA
{
}
// get a resource variable
$fp = fopen(__FILE__, "r");
// unexpected values to be passed to $arg argument
$inputs = array(0, 1, 12345, -2345, 2147483647, 10.5, -10.5, 123456789000.0, 1.23456789E-9, 0.5, NULL, null, true, false, TRUE, FALSE, "", '', array(), "abcxyz", 'abcxyz', $heredoc, new classA(), @$undefined_var, @$unset_var, $fp);
// loop through each element of $inputs to check the behaviour of hypot()
$iterator = 1;
foreach ($inputs as $input) {
    echo "\n-- Iteration {$iterator} --\n";
    var_dump(hypot(3, $input));
    $iterator++;
}
fclose($fp);
?>
===Done===
Exemplo n.º 8
0
 /**
  * Calcula o tamanho da hipotenusa de um ângulo reto do triângulo Retorna a raiz quadrada de (num1*num1 + num2*num2)
  * @return Number
  */
 public function hypot($x = 0, $y = 0)
 {
     if ($x == 0) {
         $x = $this->num;
     }
     $this->num = hypot($x, $y);
     return $this;
 }
Exemplo n.º 9
0
 protected function _MATH_HYPOT($elem)
 {
     return hypot($elem['X'], $elem['Y']);
 }
Exemplo n.º 10
0
 /**
  *
  */
 public function getHipotenuseValue($left, $right)
 {
     try {
         self::numberLeftVerify($left);
         self::numberRightVerify($right);
         $this->lastOutputValue = hypot($this->calcLeftNumber, $this->calcRightNumber);
         return $this->lastOutputValue;
     } catch (Exception $e) {
         echo "Erro linha: " . $e->getLine() . " - Desc: " . $e->getMessage() . "- Arquivo:" . $e->getFile();
     }
 }
Exemplo n.º 11
0
 /**
  * Calculates the inverse sine of a complex number: z = asinAlt(c1)
  * Uses an alternative algorithm
  *
  * @param Math_Complex $c1
  * @return Math_Complex A valid Math_Complex number on success
  * @throws InvalidArgumentException
  */
 public static function asinAlt(Math_Complex $c1)
 {
     if (!Math_ComplexOp::isComplex($c1)) {
         throw new InvalidArgumentException('argument is not a Math_Complex object');
     }
     $r = $c1->getReal();
     $i = $c1->getIm();
     if ($i == 0) {
         return Math_ComplexOp::asinReal($r);
     } else {
         $x = abs($r);
         $y = abs($i);
         $r = hypot($x + 1, $y);
         $s = hypot($x - 1, $y);
         $a = ($r + $s) / 2;
         $b = $x / $a;
         $y2 = $y * $y;
         $ac = 1.5;
         $bc = 0.6417;
         // crossover values
         if ($b <= $bc) {
             $real = asin($b);
         } else {
             if ($x <= 1) {
                 $d = 0.5 * ($a + $x) * ($y2 / ($r + $x + 1) + ($s + (1 - $x)));
                 $real = atan2($x, sqrt($d));
             } else {
                 $ax = $a + $x;
                 $d = 0.5 * ($ax / ($r + $x + 1) + $ax / ($s + ($x - 1)));
                 $real = atan2($x, $y * sqrt($d));
             }
         }
         if ($a <= $ac) {
             if ($x < 1) {
                 $m = 0.5 * ($y2 / ($r + ($x + 1)) + $y2 / ($s + (1 - $x)));
             } else {
                 $m = 0.5 * ($y2 / ($r + ($x + 1)) + ($s + ($x - 1)));
             }
             $im = log1p($m + sqrt($m * ($a + 1)));
         } else {
             $im = log($a + sqrt($a * $a - 1));
         }
         $real = $r >= 0 ? $real : -1 * $real;
         $im = $i >= 0 ? $im : -1 * $im;
         return new Math_Complex($real, $im);
     }
 }
Exemplo n.º 12
0
VC(pow("2", "8"), 256);
VC(pow("-1", "20"), 1);
var_dump(pow("0", "0"));
var_dump(is_int(pow("2", "32")));
VC(exp(12), 162754.791419);
VC(exp(5.7), 298.86740096706);
VC(expm1(5.7), 297.8674);
var_dump(log10(10));
var_dump(log10(100));
VC(log1p(9), 2.302585092994);
VC(log1p(99), 4.6051701859881);
VC(log(8), 2.0794415416798);
var_dump(log(8, 2));
VC(cos(M_PI), -1);
VC(cosh(1.23), 1.8567610569853);
VC(sin(deg2rad(90)), 1);
VC(sinh(1.23), 1.5644684793044);
VC(tan(deg2rad(45)), 1);
VC(tanh(1.23), 0.84257932565893);
VC(acos(-1), M_PI);
VC(acosh(1.8567610569853), 1.23);
VC(asin(1), deg2rad(90));
VC(asinh(1.5644684793044), 1.23);
VC(atan(1), deg2rad(45));
VC(atanh(0.84257932565893), 1.23);
VC(atan2(3, 4), 0.64350110879328);
var_dump(hypot(3, 4));
var_dump(fmod(5.7, 1.3));
var_dump(sqrt(9));
var_dump(getrandmax());
var_dump(mt_getrandmax());
Exemplo n.º 13
0
<?php

/* Prototype  : float hypot  ( float $x  , float $y  )
 * Description: Calculate the length of the hypotenuse of a right-angle triangle.
 * Source code: ext/standard/math.c
 */
echo "*** Testing hypot() : error conditions ***\n";
echo "\n-- Testing hypot() function with less than expected no. of arguments --\n";
hypot();
hypot(36);
echo "\n-- Testing hypot() function with more than expected no. of arguments --\n";
hypot(36, 25, 0);
?>
===Done===
Exemplo n.º 14
0
 /**
  * Modulus (absolute value)
  *
  * Return the modulus of the complex number z=x+iy, i.e.
  * sqrt(x^2 + y^2)
  *
  * @retval float modulus
  */
 public function abs()
 {
     return hypot($this->x, $this->y);
 }
Exemplo n.º 15
0
 /**
  * This method returns the length of the hypotenuse of a right-angle triangle.
  *
  * @access public
  * @static
  * @param IReal\Type $x                                     the left operand
  * @param IReal\Type $y                                     the right operand
  * @return IDouble\Type                                     the result
  */
 public static function hypot(IReal\Type $x, IReal\Type $y) : IDouble\Type
 {
     return IDouble\Type::box(hypot($x->unbox(), $y->unbox()));
 }
 public function __construct(Matrix $_matrix)
 {
     $this->l_matrix = $_matrix;
     $m = $_matrix->u_size;
     $n = $_matrix->u_stride;
     /*if($m < $n)
     		{
     			return;
     		}*/
     $a = clone $this->l_matrix->u_data;
     /*$nu = min($m, $n);*/
     $this->l_singular = new Vector($sl = min($m + 1, $n));
     $s = $this->l_singular->u_data;
     $this->l_left = new Matrix($um = $m, $un = $m);
     $u = $this->l_left->u_data;
     $this->l_right = new Matrix($vm = $n, $vn = $n);
     $v = $this->l_right->u_data;
     $e = arrayFill($n, 0.0);
     $work = arrayFill($m, 0.0);
     $wantu = true;
     $wantv = true;
     /* Reduce A to bidiagonal form, storing the diagonal elements in s and the super-diagonal elements in e. */
     $nct = min($m - 1, $n);
     $nrt = max(0, min($n - 2, $m));
     $kmax = max($nct, $nrt);
     for ($k = 0; $k < $kmax; $k++) {
         if ($k < $nct) {
             /*
             	Compute the transformation for the k-th column and place the k-th diagonal in s[k].
             	Compute 2-norm of k-th column without under/overflow.
             */
             $s[$k] = 0.0;
             for ($i = $k; $i < $m; $i++) {
                 $s[$k] = hypot($s[$k], $a[$i * $n + $k]);
             }
             if (compare($s[$k], 0)) {
                 if ($a[$pos = $k * $n + $k] < 0) {
                     $s[$k] = -$s[$k];
                 }
                 for ($i = $k; $i < $m; $i++) {
                     $a[$i * $n + $k] /= (double) $s[$k];
                     /* Division */
                 }
                 $a[$pos] += 1.0;
             }
             $s[$k] = -$s[$k];
         }
         for ($j = $k + 1; $j < $n; $j++) {
             if ($k < $nct && compare($s[$k], 0)) {
                 /* Apply the transformation. */
                 $t = 0.0;
                 for ($i = $k; $i < $m; $i++) {
                     $t += $a[$i * $n + $k] * $a[$i * $n + $j];
                 }
                 $t = -$t / (double) $a[$k * $n + $k];
                 /* Division */
                 for ($i = $k; $i < $m; $i++) {
                     $a[$i * $n + $j] += $t * $a[$i * $n + $k];
                 }
             }
             /* Place the k-th row of A into e for the subsequent calculation of the row transformation. */
             $e[$j] = $a[$k * $n + $j];
         }
         if ($wantu && $k < $nct) {
             /* Place the transformation in U for subsequent back multiplication. */
             for ($i = $k; $i < $m; $i++) {
                 $u[$i * $un + $k] = $a[$i * $n + $k];
             }
         }
         if ($k < $nrt) {
             /* Compute the k-th row transformation and place the k-th super-diagonal in e[k]. Compute 2-norm without under/overflow. */
             $e[$k] = 0.0;
             for ($i = $k + 1; $i < $n; $i++) {
                 $e[$k] = hypot($e[$k], $e[$i]);
             }
             if (compare($e[$k], 0)) {
                 if ($e[$k + 1] < 0) {
                     $e[$k] = -$e[$k];
                 }
                 for ($i = $k + 1; $i < $n; $i++) {
                     $e[$i] /= (double) $e[$k];
                     /* Division */
                 }
                 $e[$k + 1] += 1.0;
             }
             $e[$k] = -$e[$k];
             if ($k + 1 < $m && compare($e[$k], 0)) {
                 /* Apply the transformation. */
                 for ($i = $k + 1; $i < $m; $i++) {
                     $work[$i] = 0.0;
                 }
                 for ($j = $k + 1; $j < $n; $j++) {
                     for ($i = $k + 1; $i < $m; $i++) {
                         $work[$i] += $e[$j] * $a[$i * $n + $j];
                     }
                 }
                 for ($j = $k + 1; $j < $n; $j++) {
                     $t = -$e[$j] / (double) $e[$k + 1];
                     /* Division */
                     for ($i = $k + 1; $i < $m; $i++) {
                         $a[$i * $n + $j] += $t * $work[$i];
                     }
                 }
             }
             if ($wantv) {
                 /* Place the transformation in V for subsequent back multiplication. */
                 for ($i = $k + 1; $i < $n; $i++) {
                     $v[$i * $vn + $k] = $e[$i];
                 }
             }
         }
     }
     /* Set up the final bidiagonal matrix or order p. */
     $p = min($n, $m + 1);
     if ($nct < $n) {
         $s[$nct] = $a[$nct * $n + $nct];
     }
     if ($m < $p) {
         $s[$p - 1] = 0.0;
     }
     if ($nrt + 1 < $p) {
         $e[$nrt] = $a[$nrt * $n + $p - 1];
     }
     $e[$p - 1] = 0.0;
     /* If required, generate U. */
     if ($wantu) {
         for ($j = $nct; $j < $m; $j++) {
             for ($i = 0; $i < $m; $i++) {
                 $u[$i * $un + $j] = 0.0;
             }
             $u[$j * $un + $j] = 1.0;
         }
         for ($k = $nct - 1; $k >= 0; $k--) {
             if (compare($s[$k], 0)) {
                 for ($j = $k + 1; $j < $m; $j++) {
                     $t = 0.0;
                     for ($i = $k; $i < $m; $i++) {
                         $t += $u[$i * $un + $k] * $u[$i * $un + $j];
                     }
                     $t = -$t / (double) $u[$k * $un + $k];
                     /* Division */
                     for ($i = $k; $i < $m; $i++) {
                         $u[$i * $un + $j] += $t * $u[$i * $un + $k];
                     }
                 }
                 for ($i = $k; $i < $m; $i++) {
                     $u[$pos = $i * $un + $k] = -$u[$pos];
                 }
                 $u[$pos = $k * $un + $k] = 1.0 + $u[$pos];
                 for ($i = 0; $i < $k - 1; $i++) {
                     $u[$i * $un + $k] = 0.0;
                 }
             } else {
                 for ($i = 0; $i < $m; $i++) {
                     $u[$i * $un + $k] = 0.0;
                 }
                 $u[$k * $un + $k] = 1.0;
             }
         }
     }
     /* If required, generate V. */
     if ($wantv) {
         for ($k = $n - 1; $k >= 0; $k--) {
             if ($k < $nrt && compare($e[$k], 0)) {
                 for ($j = $k + 1; $j < $n; $j++) {
                     $t = 0.0;
                     for ($i = $k + 1; $i < $n; $i++) {
                         $t += $v[$i * $vn + $k] * $v[$i * $vn + $j];
                     }
                     $t = -$t / (double) $v[($k + 1) * $vn + $k];
                     /* Division */
                     for ($i = $k + 1; $i < $n; $i++) {
                         $v[$i * $vn + $j] += $t * $v[$i * $vn + $k];
                     }
                 }
             }
             for ($i = 0; $i < $n; $i++) {
                 $v[$i * $vn + $k] = 0.0;
             }
             $v[$k * $vn + $k] = 1.0;
         }
     }
     /* Main iteration loop for the singular values. */
     $pp = $p - 1;
     $iter = 0;
     $eps = pow(2, -52);
     $tiny = pow(2, -966);
     while ($p > 0) {
         $k = $kase = null;
         /*
         	Here is where a test for too many iterations would go.
          
         	This section of the program inspects for negligible elements in the s and e arrays.
         	On completion the variables kase and k are set as follows.
         	kase = 1	if s(p) and e[k - 1] are negligible and k < p
         	kase = 2	if s(k) is negligible and k < p
         	kase = 3	if e[k - 1] is negligible, k < p, and s(k), ..., s(p) are not negligible (qr step).
         	kase = 4	if e(p - 1) is negligible (convergence).
         */
         for ($k = $p - 2; $k >= -1; $k--) {
             if ($k == -1) {
                 break;
             }
             if (compare(abs($e[$k]), $tiny + $eps * (abs($s[$k]) + abs($s[$k + 1]))) <= 0) {
                 $e[$k] = 0.0;
                 break;
             }
         }
         if ($k == $p - 2) {
             $kase = 4;
         } else {
             $ks = null;
             for ($ks = $p - 1; $ks >= $k; $ks--) {
                 if ($ks == $k) {
                     break;
                 }
                 $t = ($ks != $p ? abs($e[$ks]) : 0) + ($ks != $k + 1 ? abs($e[$ks - 1]) : 0);
                 if (compare(abs($s[$ks]), $tiny + $eps * $t) <= 0) {
                     $s[$ks] = 0.0;
                     break;
                 }
             }
             if ($ks == $k) {
                 $kase = 3;
             } else {
                 if ($ks == $p - 1) {
                     $kase = 1;
                 } else {
                     $kase = 2;
                     $k = $ks;
                 }
             }
         }
         $k++;
         /* Perform the task indicated by kase. */
         switch ($kase) {
             /* Deflate negligible s(p). */
             case 1:
                 $f = $e[$p - 2];
                 $e[$p - 2] = 0.0;
                 for ($j = $p - 2; $j >= $k; $j--) {
                     $t = (double) hypot($s[$j], $f);
                     $cs = $s[$j] / $t;
                     /* Division */
                     $sn = $f / $t;
                     /* Division */
                     $s[$j] = $t;
                     if ($j != $k) {
                         $f = -$sn * $e[$j - 1];
                         $e[$j - 1] = $cs * $e[$j - 1];
                     }
                     if ($wantv) {
                         for ($i = 0; $i < $n; $i++) {
                             $t = $cs * $v[$ijpos = $i * $vn + $j] + $sn * $v[$ippos = $i * $vn + $p - 1];
                             $v[$ippos] = -$sn * $v[$ijpos] + $cs * $v[$ippos];
                             $v[$ijpos] = $t;
                         }
                     }
                 }
                 break;
                 /* Split at negligible s(k). */
             /* Split at negligible s(k). */
             case 2:
                 $f = $e[$k - 1];
                 $e[$k - 1] = 0.0;
                 for ($j = $k; $j < $p; $j++) {
                     $t = (double) hypot($s[$j], $f);
                     $cs = $s[$j] / $t;
                     /* Division */
                     $sn = $f / $t;
                     /* Division */
                     $s[$j] = $t;
                     $f = -$sn * $e[$j];
                     $e[$j] = $cs * $e[$j];
                     if ($wantu) {
                         for ($i = 0; $i < $m; $i++) {
                             $t = $cs * $u[$ijpos = $i * $un + $j] + $sn * $u[$ikpos = $i * $un + $k - 1];
                             $u[$ikpos] = -$sn * $u[$ijpos] + $cs * $u[$ikpos];
                             $u[$ijpos] = $t;
                         }
                     }
                 }
                 break;
                 /* Perform one qr step. */
             /* Perform one qr step. */
             case 3:
                 /* Calculate the shift. */
                 $scale = (double) max(max(max(max(abs($s[$p - 1]), abs($s[$p - 2])), abs($e[$p - 2])), abs($s[$k])), abs($e[$k]));
                 $sp = $s[$p - 1] / $scale;
                 /* Division */
                 $spm1 = $s[$p - 2] / $scale;
                 /* Division */
                 $epm1 = $e[$p - 2] / $scale;
                 /* Division */
                 $sk = $s[$k] / $scale;
                 /* Division */
                 $ek = $e[$k] / $scale;
                 /* Division */
                 $b = (($spm1 + $sp) * ($spm1 - $sp) + $epm1 * $epm1) / 2.0;
                 $c = $sp * $epm1 * ($sp * $epm1);
                 $shift = 0.0;
                 if (compare($b, 0) || compare($c, 0)) {
                     $shift = sqrt($b * $b + $c);
                     if ($b < 0) {
                         $shift = -$shift;
                     }
                     $shift = $c / (double) ($b + $shift);
                     /* Division */
                 }
                 $f = ($sk + $sp) * ($sk - $sp) + $shift;
                 $g = $sk * $ek;
                 /* Chase zeros. */
                 for ($j = $k; $j < $p - 1; $j++) {
                     $t = (double) hypot($f, $g);
                     $cs = $f / $t;
                     /* Division */
                     $sn = $g / $t;
                     /* Division */
                     if ($j != $k) {
                         $e[$j - 1] = $t;
                     }
                     $f = $cs * $s[$j] + $sn * $e[$j];
                     $e[$j] = $cs * $e[$j] - $sn * $s[$j];
                     $g = $sn * $s[$j + 1];
                     $s[$j + 1] = $cs * $s[$j + 1];
                     if ($wantv) {
                         for ($i = 0; $i < $n; $i++) {
                             $t = $cs * $v[$ijpos = $i * $vn + $j] + $sn * $v[$ij1pos = $i * $vn + $j + 1];
                             $v[$ij1pos] = -$sn * $v[$ijpos] + $cs * $v[$ij1pos];
                             $v[$ijpos] = $t;
                         }
                     }
                     $t = (double) hypot($f, $g);
                     $cs = $f / $t;
                     /* Division */
                     $sn = $g / $t;
                     /* Division */
                     $s[$j] = $t;
                     $f = $cs * $e[$j] + $sn * $s[$j + 1];
                     $s[$j + 1] = -$sn * $e[$j] + $cs * $s[$j + 1];
                     $g = $sn * $e[$j + 1];
                     $e[$j + 1] = $cs * $e[$j + 1];
                     if ($wantu && $j < $m - 1) {
                         for ($i = 0; $i < $m; $i++) {
                             $t = $cs * $u[$ijpos = $i * $un + $j] + $sn * $u[$ij1pos = $i * $un + $j + 1];
                             $u[$ij1pos] = -$sn * $u[$ijpos] + $cs * $u[$ij1pos];
                             $u[$ijpos] = $t;
                         }
                     }
                 }
                 $e[$p - 2] = $f;
                 $iter = $iter + 1;
                 break;
                 /* Convergence. */
             /* Convergence. */
             case 4:
                 /* Make the singular values positive. */
                 if (compare($s[$k], 0) <= 0) {
                     $s[$k] = $s[$k] < 0 ? -$s[$k] : 0.0;
                     if ($wantv) {
                         for ($i = 0; $i <= $pp; $i++) {
                             $v[$pos = $i * $vn + $k] = -$v[$pos];
                         }
                     }
                 }
                 /* Order the singular values. */
                 while ($k < $pp) {
                     if (compare($s[$k], $s[$k + 1]) >= 0) {
                         break;
                     }
                     $t = $s[$k];
                     $s[$k] = $s[$k + 1];
                     $s[$k + 1] = $t;
                     if ($wantv && $k < $n - 1) {
                         for ($i = 0; $i < $n; $i++) {
                             $t = $v[$ik1pos = $i * $vn + $k + 1];
                             $v[$ik1pos] = $v[$ikpos = $i * $vn + $k];
                             $v[$ikpos] = $t;
                         }
                     }
                     if ($wantu && $k < $m - 1) {
                         for ($i = 0; $i < $m; $i++) {
                             $t = $u[$ik1pos = $i * $un + $k + 1];
                             $u[$ik1pos] = $u[$ikpos = $i * $un + $k];
                             $u[$ikpos] = $t;
                         }
                     }
                     $k++;
                 }
                 $iter = 0;
                 $p--;
                 break;
         }
     }
     if ($sl > $m) {
         $this->l_singular->u_stride = $m;
         $s->setSize($m);
     }
 }
Exemplo n.º 17
0
	function calculate_distance($SimilarityCoefficient, $Rootx, $Rooty){
		$MaxWidth = WIDTH - $Rootx;
		$MaxHeight = HEIGHT - $Rooty;
		$x = $MaxWidth - ($SimilarityCoefficient*$MaxWidth*.01); // Possible x value
		$y = $MaxHeight - ($SimilarityCoefficient*$MaxHeight); // Possible y value
		$Hypot = hypot($Rootx - $x, $Rooty - $y);
		return $MaxWidth - $Hypot;
		
	}
Exemplo n.º 18
0
 * Description: Calculate the length of the hypotenuse of a right-angle triangle
 * Source code: ext/standard/math.c
 */
echo "*** Testing hypot() : usage variations ***\n";
//get an unset variable
$unset_var = 10;
unset($unset_var);
// heredoc string
$heredoc = <<<EOT
abc
xyz
EOT;
// get a class
class classA
{
}
// get a resource variable
$fp = fopen(__FILE__, "r");
// unexpected values to be passed to $arg argument
$inputs = array(0, 1, 12345, -2345, 2147483647, 10.5, -10.5, 123456789000.0, 1.23456789E-9, 0.5, NULL, null, true, false, TRUE, FALSE, "", '', array(), "abcxyz", 'abcxyz', $heredoc, new classA(), @$undefined_var, @$unset_var, $fp);
// loop through each element of $inputs to check the behaviour of hypot()
$iterator = 1;
foreach ($inputs as $input) {
    echo "\n-- Iteration {$iterator} --\n";
    var_dump(hypot($input, 5));
    $iterator++;
}
fclose($fp);
?>
===Done===
Exemplo n.º 19
0
 /**
  * @param Node $node1
  * @param Node $node2
  * @return float
  */
 public static function getLinearDistance(Node $node1, Node $node2)
 {
     $dist_x = abs($node1->getX() - $node2->getX());
     $dist_y = abs($node1->getY() - $node2->getY());
     return hypot($dist_x, $dist_y);
 }
Exemplo n.º 20
0
<?php

/* Prototype  : float hypot  ( float $x  , float $y  )
 * Description: Calculate the length of the hypotenuse of a right-angle triangle.
 * Source code: ext/standard/math.c
 */
echo "*** Testing hypot() : basic functionality ***\n";
$valuesy = array(23, -23, 23.45, -23.45, 0x17, 027, "23", "23.45", "2.345e1", "23abc", null, true, false);
$valuesx = array(33, -33, 33.45, -33.45, 0x27, 037, "33", "43.45", "1.345e1", "33abc", null, true, false);
for ($i = 0; $i < count($valuesy); $i++) {
    for ($j = 0; $j < count($valuesx); $j++) {
        echo "\nY:{$valuesy[$i]} X:{$valuesx[$j]} ";
        $res = hypot($valuesy[$i], $valuesx[$j]);
        var_dump($res);
    }
}
?>
===Done===
Exemplo n.º 21
0
 public function frobeniusNorm()
 {
     $result = 0.0;
     for ($i = 0; $i < $this->u_size; $i++) {
         $offset = $i * $this->u_stride;
         for ($j = 0; $j < $this->u_stride; $j++) {
             $result = hypot($result, $this->u_data[$offset + $j]);
         }
     }
     return $result;
 }
Exemplo n.º 22
0
 /**
  * Calculate the length of the hypotenuse of a right-angle triangle.
  * @link http://php.net/manual/en/function.hypot.php
  * @param float $x <p>Length of first side</p>
  * @param float $y <p>Length of second side</p>
  * @return float Calculated length of the hypotenuse
  */
 public static function hypot($x, $y)
 {
     return hypot($x, $y);
 }
Exemplo n.º 23
0
 /**
  * Calculate hypotenuse
  *
  * @param number $xValue Length of first line
  * @param number $yValue Length of second line
  *
  * @return float
  */
 public static function hypotenuse($xValue, $yValue)
 {
     return hypot($xValue, $yValue);
 }
Exemplo n.º 24
0
echo "floor\n";
echo floor(-2354) . " " . floor("foo") . " " . floor(0) . " " . floor(5) . floor(1.2345) . "\n";
// in windows, php has this at 32767 for no good reason
if (PHP_OS != 'WINNT') {
    echo getrandmax() . "\n";
    if (100000 < getrandmax()) {
        echo "getrandmax: Well, that's a start.\n";
    } else {
        echo "woops, getrandmax: " . getrandmax() . "\n";
    }
}
echo "hexdec\n";
echo hexdec("-2354") . " " . hexdec("foo") . " " . hexdec(0) . " " . hexdec(5) . hexdec("1.2345") . "\n";
if (PHP_OS != 'WINNT') {
    echo "hypot\n";
    echo hypot(-2354, 34) . " " . hypot("foo", 2) . " " . hypot(0, 0) . " " . hypot(5, 12) . hypot(1.2345, 2.3234) . "\n";
}
echo "log\n";
echo log(-2354) . " " . log("foo") . " " . log(0) . " " . log(5) . log(1.2345) . "\n";
echo "log10\n";
echo log10(-2354) . " " . log10("foo") . " " . log10(0) . " " . log10(5) . log10(1.2345) . "\n";
if (PHP_OS != 'WINNT') {
    echo "log1p\n";
    echo log1p(-2354) . " " . log1p("foo") . " " . log1p(0) . " " . log1p(5) . log1p(1.2345) . "\n";
}
echo "octdec\n";
echo octdec("-2354") . " " . octdec("foo") . " " . octdec(0) . " " . octdec(5) . octdec("1.2345") . "\n";
echo "pi\n";
echo pi() . "\n";
echo "pow\n";
echo pow(-2354, 4) . " " . pow("foo", 2) . " " . pow(0, 0) . " " . pow(5, 12) . pow(1.2345, 2.3234) . "\n";
Exemplo n.º 25
0
<?php

$num = 25;
$raizQuadrada = sqrt($num);
// 5
$potencia = 2;
$potencia = pow($num, $potencia);
// 625
$graus = 45;
// inclinação...
$radianos = deg2rad($graus);
// 0.785398163397
$grausNovamente = rad2deg($radianos);
$seno = sin($radianos);
$cosseno = cos($radianos);
$tangente = tan($radianos);
echo pi();
// 3.1415926535898
echo M_PI;
// 3.1415926535898
echo M_SQRTPI;
// raiz de pi, 1.77245385090551602729
$hipotenusa = hypot(3, 4);
// 5, = sqrt(3*3+4*4);
$numDecimal = 256;
$numBinario = base_convert($numDecimal, 10, 2);
$numHexa = base_convert($numDecimal, 10, 16);
echo log(5);
// logaritmo natural