• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP bccomp函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: convertDecimal2Binary

 /**
  * Convert decimal number as a string to binary number
  * For TblUtil in Karate rank
  *
  * Example:
  * Input:  string $uuid = "465827479475458048";
  * Output: string 10101001111100111001111111100000110000000001000000000000
  *
  * @time 2015/08/30 21:45
  *
  * @param $uuid string
  * @param $base string The convert base
  * @return bool
  */
 public static function convertDecimal2Binary($uuid = "", $base = "2")
 {
     if (empty($uuid) || bccomp($uuid, "0", 0) <= 0) {
         return false;
     }
     $binaryResult = "";
     bcscale(0);
     //Set the default precision
     $intBase = (int) $base;
     while (true) {
         if (substr_compare($uuid, "0", 0) == 0) {
             break;
         }
         $last = substr($uuid, -1);
         //Get the last number
         $divFlag = 0;
         if ($last % $intBase == 0) {
             //If $uuid could be divisible
             $binaryResult .= "0";
         } else {
             $binaryResult .= "1";
             $divFlag = 1;
         }
         if ($divFlag == 1) {
             $lastTwo = substr($uuid, -2);
             $replace = (string) ((int) $lastTwo - 1);
             $uuid = substr_replace($uuid, $replace, -2);
         }
         $uuid = bcdiv($uuid, $base);
     }
     $binaryResult = strrev($binaryResult);
     //Reversing the binary sequence to get the right result
     return $binaryResult;
 }
开发者ID:niceforbear,项目名称:lib,代码行数:48,代码来源:Toys.php


示例2: generator

 /**
  * Generate a valid prime based on which php is used. Slower than the Prime generator.
  * @return \Generator
  */
 public static function generator()
 {
     $primes = ['2'];
     $currentNumber = '2';
     (yield '2');
     while (true) {
         ++$currentNumber;
         $unitNumber = (int) substr($currentNumber, -1);
         if (($currentNumber & 1) === 0) {
             continue;
         }
         $squareRoot = bcsqrt($currentNumber);
         $foundPrimeDivisor = false;
         foreach ($primes as $prime) {
             if (bccomp($prime, $squareRoot) === 1) {
                 break;
             }
             if (bcmod($currentNumber, $prime) === '0') {
                 $foundPrimeDivisor = true;
                 break;
             }
         }
         if (!$foundPrimeDivisor) {
             $primes[] = $currentNumber;
             (yield $currentNumber);
         }
     }
 }
开发者ID:tomzx,项目名称:project-euler,代码行数:32,代码来源:BigPrime.php


示例3: dec2Any

 /**
  * 10进制转其它进制
  * 
  * @access public
  * @param String $dec 十进制数据
  * @param String $toRadix 要转换的进制
  * @return String
  */
 public static function dec2Any($dec, $toRadix)
 {
     $MIN_RADIX = 2;
     $MAX_RADIX = 62;
     $num62 = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
     if ($toRadix < $MIN_RADIX || $toRadix > $MAX_RADIX) {
         $toRadix = 2;
     }
     if ($toRadix == 10) {
         return $dec;
     }
     $buf = array();
     $charPos = 64;
     $isNegative = $dec < 0;
     if (!$isNegative) {
         $dec = -$dec;
     }
     while (bccomp($dec, -$toRadix) <= 0) {
         $buf[$charPos--] = $num62[-bcmod($dec, $toRadix)];
         $dec = bcdiv($dec, $toRadix);
     }
     $buf[$charPos] = $num62[-$dec];
     if ($isNegative) {
         $buf[--$charPos] = '-';
     }
     $_any = '';
     for ($i = $charPos; $i < 65; $i++) {
         $_any .= $buf[$i];
     }
     return $_any;
 }
开发者ID:sammychan1981,项目名称:quanpin,代码行数:39,代码来源:chips_class.php


示例4: isLowerThan

 public function isLowerThan($decimal)
 {
     if (!$decimal instanceof Decimal) {
         $decimal = new Decimal($decimal);
     }
     return bccomp($this->amount, $decimal->getAmount(), self::$scale) === -1;
 }
开发者ID:hatimeria,项目名称:HatimeriaBankBundle,代码行数:7,代码来源:Decimal.php


示例5: bcinvert

 function bcinvert($a, $n)
 {
     // Sanity check
     if (!is_scalar($a)) {
         user_error('bcinvert() expects parameter 1 to be string, ' . gettype($a) . ' given', E_USER_WARNING);
         return false;
     }
     if (!is_scalar($n)) {
         user_error('bcinvert() expects parameter 2 to be string, ' . gettype($n) . ' given', E_USER_WARNING);
         return false;
     }
     $u1 = $v2 = '1';
     $u2 = $v1 = '0';
     $u3 = $n;
     $v3 = $a;
     while (bccomp($v3, '0')) {
         $q0 = bcdiv($u3, $v3);
         $t1 = bcsub($u1, bcmul($q0, $v1));
         $t2 = bcsub($u2, bcmul($q0, $v2));
         $t3 = bcsub($u3, bcmul($q0, $v3));
         $u1 = $v1;
         $u2 = $v2;
         $u3 = $v3;
         $v1 = $t1;
         $v2 = $t2;
         $v3 = $t3;
     }
     if (bccomp($u2, '0') < 0) {
         return bcadd($u2, $n);
     } else {
         return bcmod($u2, $n);
     }
 }
开发者ID:casan,项目名称:eccube-2_13,代码行数:33,代码来源:bcinvert.php


示例6: base_convert

/**
 * Convert a large arbitrary number between arbitrary bases
 *
 * Works the same as the php version but supports large arbitrary numbers by using BCMath
 *
 * @see http://php.net/manual/en/function.base-convert.php
 * @see http://php.net/manual/en/function.base-convert.php#109660
 * @param string $number
 * @param int $frombase
 * @param int $tobase
 * @return string
 */
function base_convert($number, $frombase, $tobase)
{
    if ($frombase == $tobase) {
        return $number;
    }
    $number = trim($number);
    if ($frombase != 10) {
        $len = strlen($number);
        $fromDec = 0;
        for ($i = 0; $i < $len; $i++) {
            $v = \base_convert($number[$i], $frombase, 10);
            $fromDec = bcadd(bcmul($fromDec, $frombase, 0), $v, 0);
        }
    } else {
        $fromDec = $number;
    }
    if ($tobase != 10) {
        $result = '';
        while (bccomp($fromDec, '0', 0) > 0) {
            $v = intval(bcmod($fromDec, $tobase));
            $result = \base_convert($v, 10, $tobase) . $result;
            $fromDec = bcdiv($fromDec, $tobase, 0);
        }
    } else {
        $result = $fromDec;
    }
    return (string) $result;
}
开发者ID:phlib,项目名称:base_convert,代码行数:40,代码来源:base_convert.php


示例7: validate

 /**
  * Validate comma-separated IP address ranges.
  *
  * @param string $ranges
  *
  * @return bool
  */
 public function validate($ranges)
 {
     if (!is_string($ranges)) {
         $this->setError(_s('Invalid IP address range "%1$s": must be a string.', $this->stringify($ranges)));
         return false;
     }
     if ($ranges === '') {
         $this->setError(_('IP address range cannot be empty.'));
         return false;
     }
     $this->maxIPCount = 0;
     $this->maxIPRange = '';
     foreach (explode(',', $ranges) as $range) {
         $range = trim($range, " \t\r\n");
         if (!$this->isValidMask($range) && !$this->isValidRange($range)) {
             $this->setError(_s('Invalid IP address range "%1$s".', $range));
             return false;
         }
     }
     if ($this->ipRangeLimit != 0 && bccomp($this->maxIPCount, $this->ipRangeLimit) > 0) {
         $this->setError(_s('IP range "%1$s" exceeds "%2$s" address limit.', $this->maxIPRange, $this->ipRangeLimit));
         return false;
     }
     return true;
 }
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:32,代码来源:CIPRangeValidator.php


示例8: formatAccountPerspective

 /**
  * @return Twig_SimpleFunction
  */
 public function formatAccountPerspective() : Twig_SimpleFunction
 {
     return new Twig_SimpleFunction('formatAccountPerspective', function (TransactionJournal $journal, Account $account) {
         $cache = new CacheProperties();
         $cache->addProperty('formatAccountPerspective');
         $cache->addProperty($journal->id);
         $cache->addProperty($account->id);
         if ($cache->has()) {
             return $cache->get();
         }
         // get the account amount:
         $transactions = $journal->transactions()->where('transactions.account_id', $account->id)->get(['transactions.*']);
         $amount = '0';
         foreach ($transactions as $transaction) {
             $amount = bcadd($amount, strval($transaction->amount));
         }
         if ($journal->isTransfer()) {
             $amount = bcmul($amount, '-1');
         }
         // check if this sum is the same as the journal:
         $journalSum = TransactionJournal::amount($journal);
         $full = Amount::formatJournal($journal);
         if (bccomp($journalSum, $amount) === 0 || bccomp(bcmul($journalSum, '-1'), $amount) === 0) {
             $cache->store($full);
             return $full;
         }
         $formatted = Amount::format($amount, true);
         if ($journal->isTransfer()) {
             $formatted = '<span class="text-info">' . Amount::format($amount) . '</span>';
         }
         $str = $formatted . ' (' . $full . ')';
         $cache->store($str);
         return $str;
     });
 }
开发者ID:roberthorlings,项目名称:firefly-iii,代码行数:38,代码来源:Journal.php


示例9: baseConvert

 /**
  * @param $str string
  * @param $frombase int
  * @param $tobase int 
  *
  * @return string
  * 
  * Converts integers from base to another.
  */
 public static function baseConvert($str, $frombase = 10, $tobase = 36)
 {
     $str = trim($str);
     if (intval($frombase) != 10) {
         $len = strlen($str);
         $q = 0;
         for ($i = 0; $i < $len; $i++) {
             $r = base_convert($str[$i], $frombase, 10);
             $q = bcadd(bcmul($q, $frombase), $r);
         }
     } else {
         $q = $str;
     }
     if (intval($tobase) != 10) {
         $s = '';
         while (bccomp($q, '0', 0) > 0) {
             $r = intval(bcmod($q, $tobase));
             $s = base_convert($r, 10, $tobase) . $s;
             $q = bcdiv($q, $tobase, 0);
         }
     } else {
         $s = $q;
     }
     return $s;
 }
开发者ID:pvpalvk,项目名称:kyberkoulutus2,代码行数:34,代码来源:CommonUtil.php


示例10: testNull

 public function testNull()
 {
     $oDB = new \LibPostgres\LibPostgresDriver(array('host' => getenv('TEST_HOST') ?: 'localhost', 'port' => getenv('TEST_PORT') ?: 5432, 'user_name' => getenv('TEST_USER_NAME'), 'user_password' => getenv('TEST_PASSWORD'), 'db_name' => getenv('TEST_DB_NAME')));
     // ?d
     $iFirst = 1;
     $iSecond = 2;
     $aResult = $oDB->selectRecord("\n            SELECT  (?d IS NULL)::integer AS is_null,\n                    (?d IS NOT NULL)::integer AS is_not_null,\n                    (SELECT sum(COALESCE(x, 0)) FROM unnest(array[?d]::integer[]) AS x) AS sum_coalesce\n        ", null, $iFirst, array($iFirst, null, $iSecond));
     $this->assertEquals(1, $aResult['is_null']);
     $this->assertEquals(1, $aResult['is_not_null']);
     $this->assertEquals($iFirst + $iSecond, $aResult['sum_coalesce']);
     // ?f
     $fFirst = 1.1;
     $fSecond = 2.2;
     $aResult = $oDB->selectRecord("\n            SELECT  (?f IS NULL)::integer AS is_null,\n                    (?f IS NOT NULL)::integer AS is_not_null,\n                    (SELECT sum(COALESCE(x, 0)) FROM unnest(array[?f]::numeric[]) AS x) AS sum_coalesce\n        ", null, $fFirst, array($fFirst, null, $fSecond));
     $this->assertEquals(1, $aResult['is_null']);
     $this->assertEquals(1, $aResult['is_not_null']);
     $this->assertTrue(bccomp($fFirst + $fSecond, $aResult['sum_coalesce'], 2) === 0);
     // ?j / ?jb / ?h
     $aResult = $oDB->selectRecord("\n            SELECT  (?j IS NULL)::integer AS is_j_null,\n                    (?jb IS NULL)::integer AS is_jb_null,\n                    (?h IS NULL)::integer AS is_h_null,\n                    ((?h->'i_am_null') IS NULL)::integer AS is_null_inside_hstore,\n                    ((?h->'i_am_not_null') IS NOT NULL)::integer AS is_not_null_inside_hstore\n        ", null, null, null, array('i_am_null' => null, 'i_am_not_null' => 1), array('i_am_null' => null, 'i_am_not_null' => 1));
     $this->assertEquals(1, $aResult['is_j_null']);
     $this->assertEquals(1, $aResult['is_jb_null']);
     $this->assertEquals(1, $aResult['is_jb_null']);
     $this->assertEquals(1, $aResult['is_null_inside_hstore']);
     $this->assertEquals(1, $aResult['is_not_null_inside_hstore']);
     // ?w
     $sString1 = null;
     $sString2 = "2'2\r";
     $sStringDefault = "3'3\n";
     $aResult = $oDB->selectRecord("\n            SELECT  (?w IS NULL)::integer AS is_null,\n                    (?w IS NOT NULL)::integer AS is_not_null,\n                    COALESCE(?w, ?w) || ?w AS concat,\n                    (SELECT string_agg(COALESCE(s, ?w), '') FROM unnest(array[?w]::varchar[]) AS s) AS concat_coalesce\n\n        ", $sString1, $sString2, $sString1, $sStringDefault, $sString2, $sStringDefault, array($sString1, $sString2, $sString1));
     $this->assertEquals(1, $aResult['is_null']);
     $this->assertEquals(1, $aResult['is_not_null']);
     $this->assertEquals($sStringDefault . $sString2, $aResult['concat']);
     $this->assertEquals($sStringDefault . $sString2 . $sStringDefault, $aResult['concat_coalesce']);
 }
开发者ID:denismilovanov,项目名称:libpostgres,代码行数:34,代码来源:NullTest.php


示例11: GetAuthID

function GetAuthID($i64friendID)
{
    $tmpfriendID = $i64friendID;
    $iServer = "1";
    if (extension_loaded('bcmath') == 1) {
        //decode communityid with bcmath
        if (bcmod($i64friendID, "2") == "0") {
            $iServer = "0";
        }
        $tmpfriendID = bcsub($tmpfriendID, $iServer);
        if (bccomp("76561197960265728", $tmpfriendID) == -1) {
            $tmpfriendID = bcsub($tmpfriendID, "76561197960265728");
        }
        $tmpfriendID = bcdiv($tmpfriendID, "2");
        return "STEAM_0:" . $iServer . ":" . $tmpfriendID;
    } else {
        if (extension_loaded('gmp') == 1) {
            //decode communityid with gmp
            if (gmp_mod($i64friendID, "2") == "0") {
                $iServer = "0";
            }
            $tmpfriendID = gmp_sub($tmpfriendID, $iServer);
            if (gmp_cmp("76561197960265728", $tmpfriendID) == -1) {
                $tmpfriendID = gmp_sub($tmpfriendID, "76561197960265728");
            }
            $tmpfriendID = gmp_div($tmpfriendID, "2");
            return "STEAM_0:" . $iServer . ":" . gmp_strval($tmpfriendID);
        }
    }
    return false;
}
开发者ID:GoeGaming,项目名称:bans.sevenelevenclan.org,代码行数:31,代码来源:steam.inc.php


示例12: onAfterOrderCreate

 public function onAfterOrderCreate(&$order)
 {
     if (empty($order) || empty($order->order_type) || $order->order_type != 'sale' || !isset($order->order_full_price)) {
         return;
     }
     $this->init();
     $send_confirmation = $this->params->get('send_confirmation', 1);
     if (!$send_confirmation && $order->order_status == 'confirmed') {
         $class = hikashop_get('class.cart');
         $class->cleanCartFromSession();
         return;
     }
     if ($send_confirmation && bccomp($order->order_full_price, 0, 5) == 0) {
         $config = hikashop_config();
         $orderObj = new stdClass();
         $orderObj->order_id = (int) $order->order_id;
         $orderObj->order_status = $config->get('order_confirmed_status', 'confirmed');
         $orderObj->history = new stdClass();
         $orderObj->history->history_notified = 1;
         $orderClass = hikashop_get('class.order');
         $orderClass->save($orderObj);
         $class = hikashop_get('class.cart');
         $class->cleanCartFromSession();
     }
 }
开发者ID:rodhoff,项目名称:MNW,代码行数:25,代码来源:validate_free_order.php


示例13: pleac_Comparing_Floating_Point_Numbers

function pleac_Comparing_Floating_Point_Numbers()
{
    // In PHP floating point comparisions are 'safe' [meaning the '==' comparison operator
    // can be used] as long as the value consists of 14 digits or less [total digits, either
    // side of the decimal point e.g. xxxxxxx.xxxxxxx, xxxxxxxxxxxxxx., .xxxxxxxxxxxxxx]. If
    // values with more digits must be compared, then:
    //
    // * Represent as strings, and take care to avoid any implicit conversions e.g. don't pass
    //   a float as a float to a function and expect all digits to be retained - they won't be -
    //   then use 'strcmp' to compare the strings
    //
    // * Avoid float use; perhaps use arbitrary precision arithmetic. In this case, the
    //   'bccomp' function is relevant
    // Will work as long as each floating point value is 14 digits or less
    if ($float_1 == $float_2) {
        // ...
    }
    // Compare as strings
    $cmp = strcmp('123456789.123456789123456789', '123456789.123456789123456788');
    // Use 'bccomp'
    $precision = 5;
    // Number of significant comparison digits after decimal point
    if (bccomp('1.111117', '1.111116', $precision)) {
        // ...
    }
    $precision = 6;
    if (bccomp('1.111117', '1.111116', $precision)) {
        // ...
    }
    // ----------------------------
    $wage = 536;
    $week = $wage * 40;
    printf("One week's wage is: \$%.2f\n", $week / 100);
}
开发者ID:Halfnhav4,项目名称:pfff,代码行数:34,代码来源:Comparing_Floating_Point_Numbers.php


示例14: php_compat_bcpowmod

/**
 * Replace bcpowmod()
 *
 * @category    PHP
 * @package     PHP_Compat
 * @license     LGPL - http://www.gnu.org/licenses/lgpl.html
 * @copyright   2004-2007 Aidan Lister <[email protected]>, Arpad Ray <[email protected]>
 * @link        http://php.net/function.bcpowmod
 * @author      Sara Golemon <[email protected]>
 * @version     $Revision: 1.1 $
 * @since       PHP 5.0.0
 * @require     PHP 4.0.0 (user_error)
 */
function php_compat_bcpowmod($x, $y, $modulus, $scale = 0)
{
    // Sanity check
    if (!is_scalar($x)) {
        user_error('bcpowmod() expects parameter 1 to be string, ' . gettype($x) . ' given', E_USER_WARNING);
        return false;
    }
    if (!is_scalar($y)) {
        user_error('bcpowmod() expects parameter 2 to be string, ' . gettype($y) . ' given', E_USER_WARNING);
        return false;
    }
    if (!is_scalar($modulus)) {
        user_error('bcpowmod() expects parameter 3 to be string, ' . gettype($modulus) . ' given', E_USER_WARNING);
        return false;
    }
    if (!is_scalar($scale)) {
        user_error('bcpowmod() expects parameter 4 to be integer, ' . gettype($scale) . ' given', E_USER_WARNING);
        return false;
    }
    $t = '1';
    while (bccomp($y, '0')) {
        if (bccomp(bcmod($y, '2'), '0')) {
            $t = bcmod(bcmul($t, $x), $modulus);
            $y = bcsub($y, '1');
        }
        $x = bcmod(bcmul($x, $x), $modulus);
        $y = bcdiv($y, '2');
    }
    return $t;
}
开发者ID:akshayxhtmljunkies,项目名称:brownglock,代码行数:43,代码来源:bcpowmod.php


示例15: updateRegexp

function updateRegexp(array $regexp, array $expressions)
{
    try {
        $regexpId = $regexp['regexpid'];
        unset($regexp['regexpid']);
        // check existence
        if (!getRegexp($regexpId)) {
            throw new Exception(_('Regular expression does not exist.'));
        }
        // check required fields
        $dbFields = array('name' => null);
        if (!check_db_fields($dbFields, $regexp)) {
            throw new Exception(_('Incorrect arguments passed to function') . ' [updateRegexp]');
        }
        // check duplicate name
        $dbRegexp = DBfetch(DBselect('SELECT re.regexpid' . ' FROM regexps re' . ' WHERE re.name=' . zbx_dbstr($regexp['name']) . andDbNode('re.regexpid')));
        if ($dbRegexp && bccomp($regexpId, $dbRegexp['regexpid']) != 0) {
            throw new Exception(_s('Regular expression "%s" already exists.', $regexp['name']));
        }
        rewriteRegexpExpressions($regexpId, $expressions);
        DB::update('regexps', array('values' => $regexp, 'where' => array('regexpid' => $regexpId)));
    } catch (Exception $e) {
        error($e->getMessage());
        return false;
    }
    return true;
}
开发者ID:itnihao,项目名称:zatree-2.2,代码行数:27,代码来源:regexp.inc.php


示例16: isZero

 public function isZero(array $args)
 {
     $this->requireExactly(1, $args);
     $a = $args[0];
     $isZero = ($a instanceof Scheme_Int || $a instanceof Scheme_Float) && bccomp($a->value, "0") === 0;
     return new Scheme_Bool($isZero);
 }
开发者ID:airways,项目名称:phpscheme,代码行数:7,代码来源:Math.php


示例17: checkAddress

 public static function checkAddress($address)
 {
     $origbase58 = $address;
     $dec = "0";
     for ($i = 0; $i < strlen($address); $i++) {
         $dec = bcadd(bcmul($dec, "58", 0), strpos("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz", substr($address, $i, 1)), 0);
     }
     $address = "";
     while (bccomp($dec, 0) == 1) {
         $dv = bcdiv($dec, "16", 0);
         $rem = (int) bcmod($dec, "16");
         $dec = $dv;
         $address = $address . substr("0123456789ABCDEF", $rem, 1);
     }
     $address = strrev($address);
     for ($i = 0; $i < strlen($origbase58) && substr($origbase58, $i, 1) == "1"; $i++) {
         $address = "00" . $address;
     }
     if (strlen($address) % 2 != 0) {
         $address = "0" . $address;
     }
     if (strlen($address) != 50) {
         return false;
     }
     if (hexdec(substr($address, 0, 2)) > 0) {
         return false;
     }
     return substr(strtoupper(hash("sha256", hash("sha256", pack("H*", substr($address, 0, strlen($address) - 8)), true))), 0, 8) == substr($address, strlen($address) - 8);
 }
开发者ID:mdominoni,项目名称:binarybtc,代码行数:29,代码来源:Bitcoin.php


示例18: 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


示例19: decodeAddress

 protected static function decodeAddress($data)
 {
     $charsetHex = '0123456789ABCDEF';
     $charsetB58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
     $raw = "0";
     for ($i = 0; $i < strlen($data); $i++) {
         $current = (string) strpos($charsetB58, $data[$i]);
         $raw = (string) bcmul($raw, "58", 0);
         $raw = (string) bcadd($raw, $current, 0);
     }
     $hex = "";
     while (bccomp($raw, 0) == 1) {
         $dv = (string) bcdiv($raw, "16", 0);
         $rem = (int) bcmod($raw, "16");
         $raw = $dv;
         $hex = $hex . $charsetHex[$rem];
     }
     $withPadding = strrev($hex);
     for ($i = 0; $i < strlen($data) && $data[$i] == "1"; $i++) {
         $withPadding = "00" . $withPadding;
     }
     if (strlen($withPadding) % 2 != 0) {
         $withPadding = "0" . $withPadding;
     }
     return $withPadding;
 }
开发者ID:afrikanhut,项目名称:EzBitcoin-Api-Wallet,代码行数:26,代码来源:BitcoinHelper.php


示例20: sort

 /**
  * takes a simple list of item ids and pushes those items to the top of the list
  * starting with the first item id. doesn't need to be every item in the inventory.
  * just the ones you want sorted to the top of the list.
  * makes sense from an api standpoint but may not be perfect from an app standpoint.
  */
 public function sort(array $item_ids)
 {
     if (count($item_ids) < 1) {
         return FALSE;
     }
     rsort($item_ids);
     $user_id = $this->user();
     $pos = $this->maxPos();
     $min = $this->minCustomPos();
     if (bccomp($pos, $min) < 0) {
         $pos = $min;
     }
     if ($this->cacher) {
         $timeout = $this->cacheTimeout();
         foreach ($item_ids as $item_id) {
             $pos = bcadd($pos, 1);
             $this->cacher->set($item_id, $pos, 0, $timeout);
             if ($this->inTran()) {
                 Transaction::onRollback(array($this->cacher, 'delete'), array($item_id));
             }
         }
     }
     try {
         $this->storage('sorter')->sort($pos, $item_ids);
     } catch (Exception $e) {
         throw $this->handle($e);
     }
     return TRUE;
 }
开发者ID:Gaia-Interactive,项目名称:gaia_core_php,代码行数:35,代码来源:sorter.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP bcdiv函数代码示例发布时间:2022-05-24
下一篇:
PHP bcadd函数代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap