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


PHP bcmul函数代码示例

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


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

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

示例2: php_compat_bcpowmod

/**
 * Replace bcpowmod()
 *
 * @category    PHP
 * @package     PHP_Compat
 * @license     LGPL - http://www.gnu.org/licenses/lgpl.html
 * @copyright   2004-2007 Aidan Lister <aidan@php.net>, Arpad Ray <arpad@php.net>
 * @link        http://php.net/function.bcpowmod
 * @author      Sara Golemon <pollita@php.net>
 * @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

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

示例4: getStateTaxPayable

 function getStateTaxPayable()
 {
     //Arizona is a percent of federal tax rate.
     //However after 01-Jul-10 it changed to a straight percent of gross.
     $annual_income = $this->getAnnualTaxableIncome();
     $rate = $this->getUserValue1();
     Debug::text('Raw Rate: ' . $rate, __FILE__, __LINE__, __METHOD__, 10);
     //Because of the change from a percent of federal rate to a gross rate,
     //add some checks so if an employee's amount isn't changed we default to the closest rate.
     if ($rate >= 39.5) {
         $rate = 5.1;
     } elseif ($rate >= 33.1) {
         $rate = 4.2;
     } elseif ($rate >= 26.7) {
         $rate = 3.6;
     } elseif ($rate >= 24.5) {
         $rate = 2.7;
     } elseif ($rate >= 20.3) {
         $rate = 1.8;
     } elseif ($rate >= 10.7) {
         $rate = 1.3;
     }
     Debug::text(' Adjusted Rate: ' . $rate, __FILE__, __LINE__, __METHOD__, 10);
     $retval = bcmul($annual_income, bcdiv($rate, 100));
     if ($retval < 0) {
         $retval = 0;
     }
     Debug::text('State Annual Tax Payable: ' . $retval, __FILE__, __LINE__, __METHOD__, 10);
     return $retval;
 }
开发者ID:alachaum,项目名称:timetrex,代码行数:30,代码来源:AZ.class.php

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

示例6: makeLine

 public static function makeLine($data, $do, &$errors)
 {
     //net value is unit-price * quantity
     if (!isset($data['tax_value'])) {
         //tax  (in the UK at least) is dependent on the tax_rate of the item, and the tax status of the customer.
         //this function is a wrapper to a call to a config-dependent method
         $data['tax_percentage'] = calc_tax_percentage($data['tax_rate_id'], $data['tax_status_id'], $data['net_value']);
         $data['tax_value'] = round(bcmul($data['net_value'], $data['tax_percentage'], 4), 2);
         $data['tax_rate_percent'] = bcmul($data['tax_percentage'], 100);
     } else {
         $tax_rate = DataObjectFactory::Factory('TaxRate');
         $tax_rate->load($data['tax_rate_id']);
         $data['tax_rate_percent'] = $tax_rate->percentage;
     }
     //gross value is net + tax; use bcadd to format the data
     $data['tax_value'] = bcadd($data['tax_value'], 0);
     $data['gross_value'] = bcadd($data['net_value'], $data['tax_value']);
     //then convert to the base currency
     if ($data['rate'] == 1) {
         $data['base_net_value'] = $data['net_value'];
         $data['base_tax_value'] = $data['tax_value'];
         $data['base_gross_value'] = $data['gross_value'];
     } else {
         $data['base_net_value'] = round(bcdiv($data['net_value'], $data['rate'], 4), 2);
         $data['base_tax_value'] = round(bcdiv($data['tax_value'], $data['rate'], 4), 2);
         $data['base_gross_value'] = round(bcadd($data['base_tax_value'], $data['base_net_value']), 2);
     }
     //and to the twin-currency
     $data['twin_net_value'] = round(bcmul($data['base_net_value'], $data['twin_rate'], 4), 2);
     $data['twin_tax_value'] = round(bcmul($data['base_tax_value'], $data['twin_rate'], 4), 2);
     $data['twin_gross_value'] = round(bcadd($data['twin_tax_value'], $data['twin_net_value']), 2);
     return DataObject::Factory($data, $errors, $do);
 }
开发者ID:uzerpllp,项目名称:uzerp,代码行数:33,代码来源:InvoiceLine.php

示例7: mul

 /**
  * This method will multiply the two given operands with the bcmath extension
  * when available, otherwise it will use the default mathematical operations.
  *
  * @param string $left  The left arithmetic operand.
  * @param string $right The right arithmetic operand.
  *
  * @return string
  */
 public static function mul($left, $right)
 {
     if (function_exists('bcmul')) {
         return bcmul($left, $right);
     }
     return (string) ((int) $left * (int) $right);
 }
开发者ID:Jvbzephir,项目名称:pdepend,代码行数:16,代码来源:MathUtil.php

示例8: ReadInt64

 public static function ReadInt64($str, $pos)
 {
     $hi = sprintf("%u", self::ReadInt32($str, $pos));
     $lo = sprintf("%u", self::ReadInt32($str, $pos + 4));
     $int64 = bcadd(bcmul($hi, "4294967296"), $lo);
     return $int64;
 }
开发者ID:trong,项目名称:adobehds,代码行数:7,代码来源:Utils.php

示例9: multiply

 public function multiply(Number $precision, $scale = null)
 {
     $scale = $this->scale($scale);
     $result = bcmul($this->value, $precision->getValue(), self::MAX_PRECISION);
     $diff = $this->round($result, $scale);
     return new self($diff, $scale);
 }
开发者ID:shrikeh,项目名称:precision,代码行数:7,代码来源:Number.php

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

示例11: bcfact

function bcfact($fact, $scale = 100)
{
    if ($fact == 1) {
        return 1;
    }
    return bcmul($fact, bcfact(bcsub($fact, '1'), $scale), $scale);
}
开发者ID:Nilithus,项目名称:euler,代码行数:7,代码来源:euler024.php

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

示例13: chargeCard

 /**
  *
  * {@inheritDoc}
  *
  * @see \PhalconRest\Libraries\Payments\Processor::chargeCard()
  */
 public function chargeCard($data)
 {
     // assume we use stored card for now, will support a new card soon
     if ($data['amount'] < 10) {
         throw new \Exception('Charge amount must exceed $10.');
     }
     // convert amount to decimal
     // then convert to cents cuz that is what stripe wants
     $amount = bcmul(number_format($data['amount'], 2), 100);
     // set base charge data, add card on file or new card
     $chargeData = ["amount" => $amount, "currency" => "usd", "description" => "SMORES Payment"];
     if (isset($data['card_id'])) {
         // verify that the external_id exists in the database
         $card = $this->findCard($data['card_id']);
         $chargeData['source'] = $data['card_id'];
         $chargeData['customer'] = $data['account_id'];
     } else {
         // maybe this is a one time card?
         $chargeData['source'] = ['address_zip' => $data['zip'], 'number' => $data['number'], 'object' => 'card', 'cvc' => $data['cvc'], 'exp_year' => $data['expiration_year'], 'exp_month' => $data['expiration_month'], 'name' => $data['name'], 'address_line1' => $data['address']];
     }
     try {
         $result = \Stripe\Charge::create($chargeData);
         return $result->id;
     } catch (\Stripe\Error\Base $e) {
         $this->handleStripeError($e);
     }
 }
开发者ID:jking6884,项目名称:smores-api,代码行数:33,代码来源:StripeAdapter.php

示例14: pay

 public function pay($runValidation = true)
 {
     if ($runValidation && !$this->validate()) {
         return false;
     }
     if ($this->_order->status !== Order::STATUS_UNPAID) {
         return false;
     }
     require_once Yii::getAlias('@vendor') . "/pingplusplus/pingpp-php/init.php";
     \Pingpp\Pingpp::setApiKey(Yii::$app->params['pingpp.apiKey']);
     try {
         $extra = [];
         switch ($this->channel) {
             case self::CHANNEL_ALIPAY_WAP:
                 $extra = ['success_url' => Yii::$app->request->hostInfo . '/#/order/detail/' . $this->_order->id, 'cancel_url' => Yii::$app->request->hostInfo . '/#/order/pay/' . $this->_order->id];
                 break;
             case self::CHANNEL_WX_PUB:
                 Yii::$app->session->open();
                 $extra = ['open_id' => Yii::$app->session['wechatOpenid']];
                 break;
             case self::CHANNEL_ALIPAY_PC_DIRECT:
                 $extra = ['success_url' => Yii::$app->request->hostInfo . '/#/order/detail/' . $this->_order->id];
                 break;
             default:
                 throw new InvalidValueException('支付渠道错误!');
         }
         $ch = \Pingpp\Charge::create(['subject' => '笑e购订单', 'body' => '笑e购(xiaoego.com)订单,订单号:' . $this->_order->order_sn, 'amount' => bcmul($this->_order->real_fee, 100), 'order_no' => $this->_order->order_sn, 'currency' => 'cny', 'extra' => $extra, 'channel' => $this->channel, 'client_ip' => Yii::$app->request->userIP, 'time_expire' => $this->_order->timeout + 1800, 'app' => ['id' => Yii::$app->params['pingpp.appId']], 'description' => mb_strlen($this->_order->description, 'UTF-8') <= 255 ? $this->_order->description : substr($this->_order->description, 0, 253) . '……']);
         return $ch;
     } catch (\Exception $e) {
         throw $e;
     }
 }
开发者ID:shunzi250,项目名称:xiaoego.com,代码行数:32,代码来源:PayOrderForm.php

示例15: Extract

 function Extract($j){
    $bigj = strval($j);
    $qjr = bcadd(bcmul($this->q, $bigj), $this->r);
    $sjt = bcadd(bcmul($this->s, $bigj), $this->t);
    $d = bcdiv($qjr, $sjt);
    return floor($d);
 }
开发者ID:rurban,项目名称:shootout,代码行数:7,代码来源:pidigits.php


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