当前位置: 首页>>代码示例>>PHP>>正文


PHP bcpow函数代码示例

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


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

示例1: convBase

function convBase($numberInput, $fromBaseInput, $toBaseInput)
{
    if ($fromBaseInput == $toBaseInput) {
        return $numberInput;
    }
    $fromBase = str_split($fromBaseInput, 1);
    $toBase = str_split($toBaseInput, 1);
    $number = str_split($numberInput, 1);
    $fromLen = strlen($fromBaseInput);
    $toLen = strlen($toBaseInput);
    $numberLen = strlen($numberInput);
    $retval = '';
    $base10 = '';
    if ($toBaseInput == '0123456789') {
        $retval = 0;
        for ($i = 1; $i <= $numberLen; $i++) {
            $retval = bcadd($retval, bcmul(array_search($number[$i - 1], $fromBase), bcpow($fromLen, $numberLen - $i)));
        }
        return $retval;
    }
    if ($fromBaseInput != '0123456789') {
        $base10 = convBase($numberInput, $fromBaseInput, '0123456789');
    } else {
        $base10 = $numberInput;
    }
    if ($base10 < strlen($toBaseInput)) {
        return $toBase[$base10];
    }
    while ($base10 != '0') {
        $retval = $toBase[bcmod($base10, $toLen)] . $retval;
        $base10 = bcdiv($base10, $toLen, 0);
    }
    return $retval;
}
开发者ID:Adrian0350,项目名称:zero-knowledge-keychain,代码行数:34,代码来源:functions.php

示例2: solve

/**
 * Triples by picolll
 *
 * x=0 y=z dla j>2
 * x >= 0
 * y >= x
 * z >= y
 * m >= z
 * 100 >= m >=5
 * 2 <= n <= 100
 *
 */
function solve($m, $n)
{
    $sum = 0;
    for ($j = 2; $j <= $n; $j++) {
        if ($j > 2) {
            $sum += $m + 1;
            continue;
        }
        for ($x = 0; $x <= $m; $x++) {
            for ($y = $x; $y <= $m; $y++) {
                if ($x == 0) {
                    $sum++;
                    continue;
                }
                $x2 = bcpow($x, $j);
                $y2 = bcpow($y, $j);
                $x2y2 = bcadd($x2, $y2);
                if ($x2y2 == 0) {
                    $sum++;
                    continue;
                }
                for ($z = $y; $z <= $m; $z++) {
                    $z2 = bcpow($z, $j);
                    if ($x2y2 == $z2) {
                        $sum++;
                        if ($x != 0) {
                        }
                        continue;
                    }
                }
            }
        }
    }
    return $sum;
}
开发者ID:picolll,项目名称:hackerrank,代码行数:47,代码来源:triples.php

示例3: square_chain

function square_chain($n, &$total, &$x)
{
    $p = $n;
    while ($p > 1 && $p != 89) {
        $digits = str_split($p);
        $sum = 0;
        foreach ($digits as $digit) {
            $sum += bcpow($digit, 2);
        }
        $p = $sum;
        if ($n > 567 && in_array($p, $x)) {
            $total++;
            //$x[]=$n;
            //echo "in array $p for number $n<br />";
            return;
        }
        //echo "N is $n and P is $p <br />";
    }
    switch ($p) {
        case 1:
            break;
        case 89:
            $total++;
            $x[] = $n;
            return $total;
            break;
        default:
            echo "error!";
            break;
    }
    //print_r($x);
}
开发者ID:jaynorth,项目名称:Euler-Project,代码行数:32,代码来源:problem92_bis.php

示例4: PMA_pow

/**
 * Exponential expression / raise number into power
 *
 * @param string $base         base to raise
 * @param string $exp          exponent to use
 * @param mixed  $use_function pow function to use, or false for auto-detect
 *
 * @return mixed string or float
 */
function PMA_pow($base, $exp, $use_function = false)
{
    static $pow_function = null;
    if (null == $pow_function) {
        $pow_function = PMA_detect_pow();
    }
    if (!$use_function) {
        $use_function = $pow_function;
    }
    if ($exp < 0 && 'pow' != $use_function) {
        return false;
    }
    switch ($use_function) {
        case 'bcpow':
            // bcscale() needed for testing PMA_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 = (double) $base;
            $exp = (int) $exp;
            $pow = pow($base, $exp);
            break;
        default:
            $pow = $use_function($base, $exp);
    }
    return $pow;
}
开发者ID:AmberWish,项目名称:laba_web,代码行数:40,代码来源:common.lib.php

示例5: 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 = (double) $base;
             $exp = (int) $exp;
             $pow = pow($base, $exp);
             break;
         default:
             $pow = $use_function($base, $exp);
     }
     return $pow;
 }
开发者ID:altesien,项目名称:FinalProject,代码行数:44,代码来源:Util.class.php

示例6: pow_mod

 private function pow_mod($p, $q, $r)
 {
     $factors = array();
     $div = $q;
     $power_of_two = 0;
     while (bccomp($div, "0") == 1) {
         $rem = bcmod($div, 2);
         $div = bcdiv($div, 2);
         if ($rem) {
             array_push($factors, $power_of_two);
         }
         $power_of_two++;
     }
     $partial_results = array();
     $part_res = $p;
     $idx = 0;
     foreach ($factors as $factor) {
         while ($idx < $factor) {
             $part_res = bcpow($part_res, "2");
             $part_res = bcmod($part_res, $r);
             $idx++;
         }
         array_push($partial_results, $part_res);
     }
     $result = "1";
     foreach ($partial_results as $part_res) {
         $result = bcmul($result, $part_res);
         $result = bcmod($result, $r);
     }
     return $result;
 }
开发者ID:AxelPanda,项目名称:ibos,代码行数:31,代码来源:RSA.php

示例7: convertBase

 /**
  * @see http://php.net/manual/en/function.base-convert.php#106546
  *
  * @param $numberInput
  * @param $fromBaseInput
  * @param $toBaseInput
  *
  * @return int|string
  */
 protected static function convertBase($numberInput, $fromBaseInput, $toBaseInput)
 {
     if ($fromBaseInput == $toBaseInput) {
         return $numberInput;
     }
     $fromBase = str_split($fromBaseInput, 1);
     $toBase = str_split($toBaseInput, 1);
     $number = str_split($numberInput, 1);
     $fromLen = strlen($fromBaseInput);
     $toLen = strlen($toBaseInput);
     $numberLen = strlen($numberInput);
     $retval = '';
     if ($toBaseInput == self::FORMAT_NUMBER) {
         $retval = 0;
         for ($i = 1; $i <= $numberLen; $i++) {
             $retval = bcadd($retval, bcmul(array_search($number[$i - 1], $fromBase), bcpow($fromLen, $numberLen - $i)));
         }
         return $retval;
     }
     if ($fromBaseInput != self::FORMAT_NUMBER) {
         $base10 = self::convertBase($numberInput, $fromBaseInput, self::FORMAT_NUMBER);
     } else {
         $base10 = $numberInput;
     }
     if ($base10 < strlen($toBaseInput)) {
         return $toBase[$base10];
     }
     while ($base10 != '0') {
         $retval = $toBase[bcmod($base10, $toLen)] . $retval;
         $base10 = bcdiv($base10, $toLen, 0);
     }
     return $retval;
 }
开发者ID:ajaxray,项目名称:short-code,代码行数:42,代码来源:Code.php

示例8: alpha_id

function alpha_id($in, $to_num = false, $pad_up = 6, $passkey = '', $index = '')
{
    if (!$passkey) {
        $passkey = "Dj*H&^(#x43)[=Na!";
    }
    if (!$index) {
        $index = "ABCDEF012345";
    }
    if ($passkey !== null) {
        for ($n = 0; $n < strlen($index); $n++) {
            $i[] = substr($index, $n, 1);
        }
        $passhash = hash('sha256', $passkey);
        $passhash = strlen($passhash) < strlen($index) ? hash('sha512', $passkey) : $passhash;
        for ($n = 0; $n < strlen($index); $n++) {
            $p[] = substr($passhash, $n, 1);
        }
        array_multisort($p, SORT_DESC, $i);
        $index = implode($i);
    }
    $base = strlen($index);
    if ($to_num) {
        $in = strrev($in);
        $out = 0;
        $len = strlen($in) - 1;
        for ($t = 0; $t <= $len; $t++) {
            $bcpow = bcpow($base, $len - $t);
            $out = $out + strpos($index, substr($in, $t, 1)) * $bcpow;
        }
        if (is_numeric($pad_up)) {
            $pad_up--;
            if ($pad_up > 0) {
                $out -= pow($base, $pad_up);
            }
        }
        $out = sprintf('%F', $out);
        $out = substr($out, 0, strpos($out, '.'));
    } else {
        if (is_numeric($pad_up)) {
            $pad_up--;
            if ($pad_up > 0) {
                $in += pow($base, $pad_up);
            }
        }
        $out = "";
        for ($t = floor(log($in, $base)); $t >= 0; $t--) {
            $bcp = bcpow($base, $t);
            $a = floor($in / $bcp) % $base;
            $out = $out . substr($index, $a, 1);
            $in = $in - $a * $bcp;
        }
        $out = strrev($out);
    }
    if ($to_num === true) {
        return $out <= PHP_INT_MAX ? intval($out) : (double) $out;
    } else {
        return $out;
    }
}
开发者ID:jiangwuzhang,项目名称:library,代码行数:59,代码来源:alpha_id.php

示例9: GetMaxVal

 function GetMaxVal()
 {
     if (function_exists("bcpow")) {
         return round(bcpow(10, $this->scale[1], 15), 14);
     } else {
         return round(pow(10, $this->scale[1]), 14);
     }
 }
开发者ID:bklein01,项目名称:Project-Pier,代码行数:8,代码来源:jpgraph_log.php

示例10: normalize

 private function normalize($numberOfBytes)
 {
     $numberOfBytes = (string) $numberOfBytes;
     if (preg_match('/^(?P<coefficient>\\d+(?:\\.\\d+))E\\+(?P<exponent>\\d+)$/', $numberOfBytes, $matches)) {
         $numberOfBytes = bcmul($matches['coefficient'], bcpow($base = 10, $matches['exponent'], self::COMPUTE_WITH_PRECISION));
     }
     return $numberOfBytes;
 }
开发者ID:gabrielelana,项目名称:byte-units,代码行数:8,代码来源:System.php

示例11: encode

 public static function encode($in, $to_num = false, $pad_up = false, $passKey = null)
 {
     $index = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
     if ($passKey !== null) {
         // Although this function's purpose is to just make the
         // ID short - and not so much secure,
         // with this patch by Simon Franz (http://blog.snaky.org/)
         // you can optionally supply a password to make it harder
         // to calculate the corresponding numeric ID
         for ($n = 0; $n < strlen($index); $n++) {
             $i[] = substr($index, $n, 1);
         }
         $passhash = hash('sha256', $passKey);
         $passhash = strlen($passhash) < strlen($index) ? hash('sha512', $passKey) : $passhash;
         for ($n = 0; $n < strlen($index); $n++) {
             $p[] = substr($passhash, $n, 1);
         }
         array_multisort($p, SORT_DESC, $i);
         $index = implode($i);
     }
     $base = strlen($index);
     if ($to_num) {
         // Digital number  <<--  alphabet letter code
         $in = strrev($in);
         $out = 0;
         $len = strlen($in) - 1;
         for ($t = 0; $t <= $len; $t++) {
             $bcpow = bcpow($base, $len - $t);
             $out = $out + strpos($index, substr($in, $t, 1)) * $bcpow;
         }
         if (is_numeric($pad_up)) {
             $pad_up--;
             if ($pad_up > 0) {
                 $out -= pow($base, $pad_up);
             }
         }
         $out = sprintf('%F', $out);
         $out = substr($out, 0, strpos($out, '.'));
     } else {
         // Digital number  -->>  alphabet letter code
         if (is_numeric($pad_up)) {
             $pad_up--;
             if ($pad_up > 0) {
                 $in += pow($base, $pad_up);
             }
         }
         $out = "";
         for ($t = floor(log($in, $base)); $t >= 0; $t--) {
             $bcp = bcpow($base, $t);
             $a = floor($in / $bcp) % $base;
             $out = $out . substr($index, $a, 1);
             $in = $in - $a * $bcp;
         }
         $out = strrev($out);
         // reverse
     }
     return $out;
 }
开发者ID:romainbureau,项目名称:Custom,代码行数:58,代码来源:AlphaId.php

示例12: q48

function q48()
{
    $sum = 0;
    for ($i = 1; $i <= 1000; ++$i) {
        $power = bcpow($i, $i);
        $sum = bcadd($sum, $power);
    }
    return substr($sum, -10);
}
开发者ID:tomzx,项目名称:project-euler,代码行数:9,代码来源:48.php

示例13: binaryToInt

 /**
  * Converts a long binary number to a unsigned integer as BCMath string.
  *
  * @param string $binary a binary number as bit string
  * @return string the resulting integer as BCMath value
  */
 public static function binaryToInt($binary)
 {
     $res = '0';
     $n = strlen($binary);
     for ($i = 0; $i < $n; $i++) {
         $res = bcadd($res, bcmul($binary[$n - $i - 1], bcpow('2', $i)), 0);
     }
     return $res;
 }
开发者ID:thornberger,项目名称:empire,代码行数:15,代码来源:Math.php

示例14: decode

 static function decode($code, $codeset, $base)
 {
     // $base = strlen($codeset);
     $c = '0';
     for ($i = strlen($code); $i; $i--) {
         $c = bcadd($c, bcmul(strpos($codeset, substr($code, -1 * ($i - strlen($code)), 1)), bcpow($base, $i - 1)));
     }
     return bcmul($c, 1, 0);
 }
开发者ID:pilot34,项目名称:lessnmore,代码行数:9,代码来源:BaseIntEncoder.php

示例15: CalculateTimePerBlock

function CalculateTimePerBlock($btc_difficulty, $_hashrate)
{
    if ($btc_difficulty > 0 && $_hashrate > 0) {
        $find_time_hours = $btc_difficulty * bcpow(2, 32) / ($_hashrate * bcpow(10, 6)) / 3600;
    } else {
        $find_time_hours = 0;
    }
    return $find_time_hours;
}
开发者ID:neofutur,项目名称:simplecoin,代码行数:9,代码来源:stats.php


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