예제 #1
0
 public function _testNegativeExpGmppow()
 {
     if (function_exists('gmp_pow')) {
         $this->assertEquals(0.25, PMA_pow(2, -2, 'gmp_pow'));
     } else {
         $this->markTestSkipped('function gmp_pow() does not exist');
     }
 }
예제 #2
0
/**
 * Based on IP Pattern Matcher
 * Originally by J.Adams <*****@*****.**>
 * Found on <http://www.php.net/manual/en/function.ip2long.php>
 * Modified for phpMyAdmin
 *
 * Matches:
 * xxx.xxx.xxx.xxx        (exact)
 * xxx.xxx.xxx.[yyy-zzz]  (range)
 * xxx.xxx.xxx.xxx/nn     (CIDR)
 *
 * Does not match:
 * xxx.xxx.xxx.xx[yyy-zzz]  (range, partial octets not supported)
 *
 * @param string $testRange string of IP range to match
 * @param string $ipToTest  string of IP to test against range
 *
 * @return boolean    always true
 *
 * @access  public
 */
function PMA_ipMaskTest($testRange, $ipToTest)
{
    $result = true;
    $match = preg_match('|([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)/([0-9]+)|', $testRange, $regs);
    if ($match) {
        // performs a mask match
        $ipl = ip2long($ipToTest);
        $rangel = ip2long($regs[1] . '.' . $regs[2] . '.' . $regs[3] . '.' . $regs[4]);
        $maskl = 0;
        for ($i = 0; $i < 31; $i++) {
            if ($i < $regs[5] - 1) {
                $maskl = $maskl + PMA_pow(2, 30 - $i);
            }
            // end if
        }
        // end for
        if (($maskl & $rangel) == ($maskl & $ipl)) {
            return true;
        } else {
            return false;
        }
    } else {
        // range based
        $maskocts = explode('.', $testRange);
        $ipocts = explode('.', $ipToTest);
        // perform a range match
        for ($i = 0; $i < 4; $i++) {
            if (preg_match('|\\[([0-9]+)\\-([0-9]+)\\]|', $maskocts[$i], $regs)) {
                if ($ipocts[$i] > $regs[2] || $ipocts[$i] < $regs[1]) {
                    $result = false;
                }
                // end if
            } else {
                if ($maskocts[$i] != $ipocts[$i]) {
                    $result = false;
                }
                // end if
            }
            // end if/else
        }
        //end for
    }
    //end if/else
    return $result;
}
예제 #3
0
/**
 * Returns the number of bytes when a formatted size is given
 *
 * @param string $formatted_size the size expression (for example 8MB)
 *
 * @return  integer  The numerical part of the expression (for example 8)
 */
function PMA_extractValueFromFormattedSize($formatted_size)
{
    $return_value = -1;
    if (preg_match('/^[0-9]+GB$/', $formatted_size)) {
        $return_value = substr($formatted_size, 0, -2) * PMA_pow(1024, 3);
    } elseif (preg_match('/^[0-9]+MB$/', $formatted_size)) {
        $return_value = substr($formatted_size, 0, -2) * PMA_pow(1024, 2);
    } elseif (preg_match('/^[0-9]+K$/', $formatted_size)) {
        $return_value = substr($formatted_size, 0, -1) * PMA_pow(1024, 1);
    }
    return $return_value;
}
예제 #4
0
/**
 * Formats $value to the given length and appends SI prefixes
 * $comma is not substracted from the length
 * with a $length of 0 no truncation occurs, number is only formated
 * to the current locale
 *
 * examples:
 * <code>
 * echo PMA_formatNumber(123456789, 6);     // 123,457 k
 * echo PMA_formatNumber(-123456789, 4, 2); //    -123.46 M
 * echo PMA_formatNumber(-0.003, 6);        //      -3 m
 * echo PMA_formatNumber(0.003, 3, 3);      //       0.003
 * echo PMA_formatNumber(0.00003, 3, 2);    //       0.03 m
 * echo PMA_formatNumber(0, 6);             //       0
 *
 * </code>
 * @param   double   $value     the value to format
 * @param   integer  $length    the max length
 * @param   integer  $comma     the number of decimals to retain
 * @param   boolean  $only_down do not reformat numbers below 1
 *
 * @return  string   the formatted value and its unit
 *
 * @access  public
 *
 * @author  staybyte, sebastian mendel
 * @version 1.1.0 - 2005-10-27
 */
function PMA_formatNumber($value, $length = 3, $comma = 0, $only_down = false)
{
    //number_format is not multibyte safe, str_replace is safe
    if ($length === 0) {
        return str_replace(array(',', '.'), array($GLOBALS['number_thousands_separator'], $GLOBALS['number_decimal_separator']), number_format($value, $comma));
    }
    // this units needs no translation, ISO
    $units = array(-8 => 'y', -7 => 'z', -6 => 'a', -5 => 'f', -4 => 'p', -3 => 'n', -2 => '&micro;', -1 => 'm', 0 => ' ', 1 => 'k', 2 => 'M', 3 => 'G', 4 => 'T', 5 => 'P', 6 => 'E', 7 => 'Z', 8 => 'Y');
    // we need at least 3 digits to be displayed
    if (3 > $length + $comma) {
        $length = 3 - $comma;
    }
    // check for negative value to retain sign
    if ($value < 0) {
        $sign = '-';
        $value = abs($value);
    } else {
        $sign = '';
    }
    $dh = PMA_pow(10, $comma);
    $li = PMA_pow(10, $length);
    $unit = $units[0];
    if ($value >= 1) {
        for ($d = 8; $d >= 0; $d--) {
            if (isset($units[$d]) && $value >= $li * PMA_pow(1000, $d - 1)) {
                $value = round($value / (PMA_pow(1000, $d) / $dh)) / $dh;
                $unit = $units[$d];
                break 1;
            }
            // end if
        }
        // end for
    } elseif (!$only_down && (double) $value !== 0.0) {
        for ($d = -8; $d <= 8; $d++) {
            // force using pow() because of the negative exponent
            if (isset($units[$d]) && $value <= $li * PMA_pow(1000, $d - 1, 'pow')) {
                $value = round($value / (PMA_pow(1000, $d, 'pow') / $dh)) / $dh;
                $unit = $units[$d];
                break 1;
            }
            // end if
        }
        // end for
    }
    // end if ($value >= 1) elseif (!$only_down && (float) $value !== 0.0)
    //number_format is not multibyte safe, str_replace is safe
    $value = str_replace(array(',', '.'), array($GLOBALS['number_thousands_separator'], $GLOBALS['number_decimal_separator']), number_format($value, $comma));
    return $sign . $value . ' ' . $unit;
}