commit
9927c37f8d
@ -29,76 +29,6 @@ if (! defined('PHPMYADMIN')) {
|
||||
*/
|
||||
class Util
|
||||
{
|
||||
|
||||
/**
|
||||
* Detects which function to use for pow.
|
||||
*
|
||||
* @return string Function name.
|
||||
*/
|
||||
public static function detectPow()
|
||||
{
|
||||
if (function_exists('bcpow')) {
|
||||
// BCMath Arbitrary Precision Mathematics Function
|
||||
return 'bcpow';
|
||||
} elseif (function_exists('gmp_pow')) {
|
||||
// GMP Function
|
||||
return 'gmp_pow';
|
||||
} else {
|
||||
// PHP function
|
||||
return 'pow';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Exponential expression / raise number into power
|
||||
*
|
||||
* @param string $base base to raise
|
||||
* @param string $exp exponent to use
|
||||
* @param string $use_function pow function to use, or false for auto-detect
|
||||
*
|
||||
* @return mixed string or float
|
||||
*/
|
||||
public static function pow($base, $exp, $use_function = '')
|
||||
{
|
||||
static $pow_function = null;
|
||||
|
||||
if ($pow_function == null) {
|
||||
$pow_function = self::detectPow();
|
||||
}
|
||||
|
||||
if (! $use_function) {
|
||||
if ($exp < 0) {
|
||||
$use_function = 'pow';
|
||||
} else {
|
||||
$use_function = $pow_function;
|
||||
}
|
||||
}
|
||||
|
||||
if (($exp < 0) && ($use_function != 'pow')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch ($use_function) {
|
||||
case 'bcpow' :
|
||||
// bcscale() needed for testing pow() with base values < 1
|
||||
bcscale(10);
|
||||
$pow = bcpow($base, $exp);
|
||||
break;
|
||||
case 'gmp_pow' :
|
||||
$pow = gmp_strval(gmp_pow($base, $exp));
|
||||
break;
|
||||
case 'pow' :
|
||||
$base = $base;
|
||||
$exp = (int) $exp;
|
||||
$pow = pow($base, $exp);
|
||||
break;
|
||||
default:
|
||||
$pow = $use_function($base, $exp);
|
||||
}
|
||||
|
||||
return $pow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether configuration value tells to show icons.
|
||||
*
|
||||
@ -1444,15 +1374,15 @@ class Util
|
||||
__('EiB')
|
||||
);
|
||||
|
||||
$dh = self::pow(10, $comma);
|
||||
$li = self::pow(10, $limes);
|
||||
$dh = pow(10, $comma);
|
||||
$li = pow(10, $limes);
|
||||
$unit = $byteUnits[0];
|
||||
|
||||
for ($d = 6, $ex = 15; $d >= 1; $d--, $ex-=3) {
|
||||
$unitSize = $li * self::pow(10, $ex);
|
||||
$unitSize = $li * pow(10, $ex);
|
||||
if (isset($byteUnits[$d]) && $value >= $unitSize) {
|
||||
// use 1024.0 to avoid integer overflow on 64-bit machines
|
||||
$value = round($value / (self::pow(1024, $d) / $dh)) /$dh;
|
||||
$value = round($value / (pow(1024, $d) / $dh)) /$dh;
|
||||
$unit = $byteUnits[$d];
|
||||
break 1;
|
||||
} // end if
|
||||
@ -1521,7 +1451,7 @@ class Util
|
||||
__(',')
|
||||
);
|
||||
if (($originalValue != 0) && (floatval($value) == 0)) {
|
||||
$value = ' <' . (1 / self::pow(10, $digits_right));
|
||||
$value = ' <' . (1 / pow(10, $digits_right));
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
@ -1555,7 +1485,7 @@ class Util
|
||||
$sign = '';
|
||||
}
|
||||
|
||||
$dh = self::pow(10, $digits_right);
|
||||
$dh = pow(10, $digits_right);
|
||||
|
||||
/*
|
||||
* This gives us the right SI prefix already,
|
||||
@ -1567,7 +1497,7 @@ class Util
|
||||
* So if we have 3,6,9,12.. free digits ($digits_left - $cur_digits)
|
||||
* to use, then lower the SI prefix
|
||||
*/
|
||||
$cur_digits = floor(log10($value / self::pow(1000, $d, 'pow'))+1);
|
||||
$cur_digits = floor(log10($value / pow(1000, $d))+1);
|
||||
if ($digits_left > $cur_digits) {
|
||||
$d -= floor(($digits_left - $cur_digits)/3);
|
||||
}
|
||||
@ -1576,7 +1506,7 @@ class Util
|
||||
$d = 0;
|
||||
}
|
||||
|
||||
$value = round($value / (self::pow(1000, $d, 'pow') / $dh)) /$dh;
|
||||
$value = round($value / (pow(1000, $d) / $dh)) /$dh;
|
||||
$unit = $units[$d];
|
||||
|
||||
// number_format is not multibyte safe, str_replace is safe
|
||||
@ -1595,7 +1525,7 @@ class Util
|
||||
|
||||
if ($originalValue != 0 && floatval($value) == 0) {
|
||||
return ' <' . number_format(
|
||||
(1 / self::pow(10, $digits_right)),
|
||||
(1 / pow(10, $digits_right)),
|
||||
$digits_right,
|
||||
/* l10n: Decimal separator */
|
||||
__('.'),
|
||||
@ -1621,13 +1551,13 @@ class Util
|
||||
|
||||
if (preg_match('/^[0-9]+GB$/', $formatted_size)) {
|
||||
$return_value = mb_substr($formatted_size, 0, -2)
|
||||
* self::pow(1024, 3);
|
||||
* pow(1024, 3);
|
||||
} elseif (preg_match('/^[0-9]+MB$/', $formatted_size)) {
|
||||
$return_value = mb_substr($formatted_size, 0, -2)
|
||||
* self::pow(1024, 2);
|
||||
* pow(1024, 2);
|
||||
} elseif (preg_match('/^[0-9]+K$/', $formatted_size)) {
|
||||
$return_value = mb_substr($formatted_size, 0, -1)
|
||||
* self::pow(1024, 1);
|
||||
* pow(1024, 1);
|
||||
}
|
||||
return $return_value;
|
||||
}// end of the 'extractValueFromFormattedSize' function
|
||||
|
||||
@ -32,7 +32,7 @@ function ADVISOR_bytime($num, $precision)
|
||||
$num = round($num, $precision);
|
||||
|
||||
if ($num == 0) {
|
||||
$num = '<' . PMA\libraries\Util::pow(10, -$precision);
|
||||
$num = '<' . pow(10, -$precision);
|
||||
}
|
||||
|
||||
return "$num $per";
|
||||
|
||||
@ -182,7 +182,7 @@ class ServerVariablesController extends Controller
|
||||
'gb' => 3,
|
||||
'gib' => 3
|
||||
);
|
||||
$value = floatval($matches[1]) * Util::pow(
|
||||
$value = floatval($matches[1]) * pow(
|
||||
1024,
|
||||
$exp[mb_strtolower($matches[3])]
|
||||
);
|
||||
|
||||
@ -538,10 +538,7 @@ class GISPolygon extends GISGeometry
|
||||
|
||||
// Always keep $epsilon < 1 to go with the reduction logic down here
|
||||
$epsilon = 0.1;
|
||||
$denominator = sqrt(
|
||||
Util::pow(($y1 - $y0), 2)
|
||||
+ Util::pow(($x0 - $x1), 2)
|
||||
);
|
||||
$denominator = sqrt(pow(($y1 - $y0), 2) + pow(($x0 - $x1), 2));
|
||||
$pointA = array();
|
||||
$pointB = array();
|
||||
|
||||
@ -566,7 +563,7 @@ class GISPolygon extends GISGeometry
|
||||
|
||||
//If both are outside the polygon reduce the epsilon and
|
||||
//recalculate the points(reduce exponentially for faster convergence)
|
||||
$epsilon = Util::pow($epsilon, 2);
|
||||
$epsilon = pow($epsilon, 2);
|
||||
if ($epsilon == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -476,7 +476,7 @@ function PMA_getColumnNumberFromName($name)
|
||||
// base26 to base10 conversion : multiply each number
|
||||
// with corresponding value of the position, in this case
|
||||
// $i=0 : 1; $i=1 : 26; $i=2 : 676; ...
|
||||
$column_number += $number * PMA\libraries\Util::pow(26, $i);
|
||||
$column_number += $number * pow(26, $i);
|
||||
}
|
||||
return $column_number;
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ function PMA_ipv4MaskTest($testRange, $ipToTest)
|
||||
|
||||
for ($i = 0; $i < 31; $i++) {
|
||||
if ($i < $regs[5] - 1) {
|
||||
$maskl = $maskl + PMA\libraries\Util::pow(2, (30 - $i));
|
||||
$maskl = $maskl + pow(2, (30 - $i));
|
||||
} // end if
|
||||
} // end for
|
||||
|
||||
|
||||
@ -1,133 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for PMA\libraries\Util::pow() function from Util.php
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\Util::pow() function from Util.php
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
* @group common.lib-tests
|
||||
*/
|
||||
class PMA_Pow_Test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Test forpow
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIntOverflow()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'1267650600228229401496703205376',
|
||||
PMA\libraries\Util::pow(2, 100)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test forpow
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBcpow()
|
||||
{
|
||||
if (function_exists('bcpow')) {
|
||||
$this->assertEquals(
|
||||
'1267650600228229401496703205376',
|
||||
PMA\libraries\Util::pow(2, 100, 'bcpow')
|
||||
);
|
||||
} else {
|
||||
$this->markTestSkipped('function bcpow() does not exist');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test forpow
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGmppow()
|
||||
{
|
||||
if (function_exists('gmp_pow')) {
|
||||
$this->assertEquals(
|
||||
'1267650600228229401496703205376',
|
||||
PMA\libraries\Util::pow(2, 100, 'gmp_pow')
|
||||
);
|
||||
} else {
|
||||
$this->markTestSkipped('function gmp_pow() does not exist');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test forpow
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testNegativeExp()
|
||||
{
|
||||
$this->assertEquals(
|
||||
0.25,
|
||||
PMA\libraries\Util::pow(2, -2)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test forpow
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testNegativeExpPow()
|
||||
{
|
||||
if (function_exists('pow')) {
|
||||
$this->assertEquals(
|
||||
0.25,
|
||||
PMA\libraries\Util::pow(2, -2, 'pow')
|
||||
);
|
||||
} else {
|
||||
$this->markTestSkipped('function pow() does not exist');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test forpow
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testNegativeExpBcpow()
|
||||
{
|
||||
if (function_exists('bcpow')) {
|
||||
$this->assertEquals(
|
||||
false,
|
||||
PMA\libraries\Util::pow(2, -2, 'bcpow')
|
||||
);
|
||||
} else {
|
||||
$this->markTestSkipped('function bcpow() does not exist');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test forpow
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testNegativeExpGmppow()
|
||||
{
|
||||
if (function_exists('gmp_pow')) {
|
||||
$this->assertEquals(
|
||||
false,
|
||||
PMA\libraries\Util::pow(2, -2, 'gmp_pow')
|
||||
);
|
||||
} else {
|
||||
$this->markTestSkipped('function gmp_pow() does not exist');
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user