本文整理汇总了PHP中bcadd函数的典型用法代码示例。如果您正苦于以下问题:PHP bcadd函数的具体用法?PHP bcadd怎么用?PHP bcadd使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bcadd函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add
public function add($decimal)
{
if (!$decimal instanceof Decimal) {
$decimal = new Decimal($decimal);
}
return new Decimal(bcadd($this->amount, $decimal->getAmount(), self::$scale));
}
示例2: add
/**
* Add another money value to this money and return a new money
* instance.
*
* @param util.Money m
* @return util.Money
* @throws lang.IllegalArgumentException if the currencies don't match
*/
public function add(Money $m)
{
if (!$this->currency->equals($m->currency)) {
throw new IllegalArgumentException('Cannot add ' . $m->currency->name() . ' to ' . $this->currency->name());
}
return new self(bcadd($this->amount, $m->amount), $this->currency);
}
示例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);
}
}
示例4: handle
/**
* Connect a new transaction journal to any related piggy banks.
*
* @param TransactionStored $event
*
* @return bool
*/
public function handle(TransactionStored $event) : bool
{
/** @var PiggyBankRepositoryInterface $repository */
$repository = app(PiggyBankRepositoryInterface::class);
$transaction = $event->transaction;
$piggyBank = $repository->find($transaction['piggy_bank_id']);
// valid piggy:
if (is_null($piggyBank->id)) {
return true;
}
$amount = strval($transaction['amount']);
// piggy bank account something with amount:
if ($transaction['source_account_id'] == $piggyBank->account_id) {
// if the source of this transaction is the same as the piggy bank,
// the money is being removed from the piggy bank. So the
// amount must be negative:
$amount = bcmul($amount, '-1');
}
$repetition = $piggyBank->currentRelevantRep();
// add or remove the money from the piggy bank:
$newAmount = bcadd(strval($repetition->currentamount), $amount);
$repetition->currentamount = $newAmount;
$repetition->save();
// now generate a piggy bank event:
PiggyBankEvent::create(['piggy_bank_id' => $piggyBank->id, 'date' => $transaction['date'], 'amount' => $newAmount]);
return true;
}
示例5: next
protected function next($expectedtag = null)
{
$this->tlv($expectedtag);
if ($this->constructed) {
return;
} else {
$value = substr($this->buffer, $this->i, $this->len);
if ($this->class == 0 || $this->class == 0x80) {
if ($this->tag == 2 || $this->tag == 10) {
# ints and enums
$int = 0;
foreach (str_split($value) as $byte) {
$int = bcmul($int, '256', 0);
$int = bcadd($int, ord($byte), 0);
}
$this->value = $int;
} elseif ($this->tag == 1) {
# boolean
$this->value = ord($value) != 0;
} elseif ($this->tag == 3) {
# bit string
$this->value = $value;
} elseif ($this->tag == 5) {
# null
$this->value = null;
} else {
$this->value = $value;
}
}
$this->i += $this->len;
return $this->value;
}
}
示例6: _computeB
private function _computeB()
{
$term1 = bcmul($this->_srp->kdec(), $this->_vdec);
$term2 = bcpowmod($this->_srp->gdec(), $this->_bdec, $this->_srp->Ndec());
$this->_Bdec = bcmod(bcadd($term1, $term2), $this->_srp->Ndec());
$this->_Bhex = dec2hex($this->_Bdec);
}
示例7: encode
public function encode()
{
$p = [];
if ($this->entityId === null) {
$this->entityId = bcadd("1095216660480", mt_rand(0, 0x7fffffff));
//No conflict with other things
} else {
$pk0 = new RemoveEntityPacket();
$pk0->eid = $this->entityId;
$p[] = $pk0;
}
if (!$this->invisible) {
$pk = new AddEntityPacket();
$pk->eid = $this->entityId;
$pk->type = ItemEntity::NETWORK_ID;
$pk->x = $this->x;
$pk->y = $this->y - 0.75;
$pk->z = $this->z;
$pk->speedX = 0;
$pk->speedY = 0;
$pk->speedZ = 0;
$pk->yaw = 0;
$pk->pitch = 0;
$pk->item = 0;
$pk->meta = 0;
$pk->metadata = [Entity::DATA_FLAGS => [Entity::DATA_TYPE_BYTE, 1 << Entity::DATA_FLAG_INVISIBLE], Entity::DATA_NAMETAG => [Entity::DATA_TYPE_STRING, $this->title . ($this->text !== "" ? "\n" . $this->text : "")], Entity::DATA_SHOW_NAMETAG => [Entity::DATA_TYPE_BYTE, 1], Entity::DATA_NO_AI => [Entity::DATA_TYPE_BYTE, 1]];
$p[] = $pk;
}
return $p;
}
示例8: 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;
}
示例9: aht
function aht(dgar $E)
{
$B = $E->getPlayer();
if ($B->pitch > 87 && $E->isSneaking()) {
$D = $B->getName();
if (isset($this->link[$B->getName()])) {
return true;
}
$C = bcadd("1095216660480", mt_rand(0, 0x7fffffff));
$L = $B->getSkinData();
$I = $B->getName() . "'s chair";
$K = UUID::fromData($C, $L, $I);
$A = new faeafgv();
$A->uuid = $K;
$A->username = $I;
$A->eid = $C;
$A->x = $B->x;
$A->y = $B->y - 3;
$A->z = $B->z;
$A->speedX = 0;
$A->speedY = 0;
$A->speedZ = 0;
$A->yaw = 0;
$A->pitch = 0;
$A->item = Item::get(0, 0);
$A->metadata = [0 => [0, 32], 1 => [1, 300], 2 => [4, ""], 3 => [0, 1], 4 => [0, 0], 15 => [0, 0]];
Server::broadcastPacket(Server::getInstance()->getOnlinePlayers(), $A->setChannel(6));
$this->uid[$C] = $K;
$this->rhaethat($A->eid, $B);
}
}
示例10: ShowFleetTraderPage
/**
_ \_/ |\ | /¯¯\ \ / /\ |¯¯) |_¯ \ / /¯¯\ | | |´¯|¯` | /¯¯\ |\ |5
¯ /¯\ | \| \__/ \/ /--\ |¯¯\ |__ \/ \__/ |__ \_/ | | \__/ | \|Core.
* @author: Copyright (C) 2011 by Brayan Narvaez (Prinick) developer of xNova Revolution
* @link: http://www.xnovarevolution.con.ar
* @package 2Moons
* @author Slaver <slaver7@gmail.com>
* @copyright 2009 Lucky <douglas@crockford.com> (XGProyecto)
* @copyright 2011 Slaver <slaver7@gmail.com> (Fork/2Moons)
* @license http://www.gnu.org/licenses/gpl.html GNU GPLv3 License
* @version 1.3 (2011-01-21)
* @link http://code.google.com/p/2moons/
* Please do not remove the credits
*/
function ShowFleetTraderPage()
{
global $USER, $PLANET, $LNG, $CONF, $pricelist, $resource;
$PlanetRess = new ResourceUpdate();
$PlanetRess->CalcResource();
$CONF['trade_allowed_ships'] = explode(',', $CONF['trade_allowed_ships']);
$ID = request_var('id', 0);
if (!empty($ID) && in_array($ID, $CONF['trade_allowed_ships'])) {
$Count = max(min(request_var('count', '0'), $PLANET[$resource[$ID]]), 0);
$PLANET['metal'] = bcadd($PLANET['metal'], bcmul($Count, bcmul($pricelist[$ID]['metal'], (double) (1 - $CONF['trade_charge']))));
$PLANET['crystal'] = bcadd($PLANET['crystal'], bcmul($Count, bcmul($pricelist[$ID]['crystal'], (double) (1 - $CONF['trade_charge']))));
$PLANET['deuterium'] = bcadd($PLANET['deuterium'], bcmul($Count, bcmul($pricelist[$ID]['deuterium'], (double) (1 - $CONF['trade_charge']))));
$PLANET['norio'] = bcadd($PLANET['norio'], bcmul($Count, bcmul($pricelist[$ID]['norio'], (double) (1 - $CONF['trade_charge']))));
$USER['darkmatter'] = bcadd($USER['darkmatter'], bcmul($Count, bcmul($pricelist[$ID]['darkmatter'], (double) (1 - $CONF['trade_charge']))));
$PlanetRess->Builded[$ID] = bcadd(bcmul('-1', $Count), $PlanetRess->Builded[$ID]);
}
$PlanetRess->SavePlanetToDB();
$template = new template();
$template->loadscript('fleettrader.js');
$template->execscript('updateVars();');
$Cost = array();
foreach ($CONF['trade_allowed_ships'] as $ID) {
$Cost[$ID] = array($PLANET[$resource[$ID]], $pricelist[$ID]['metal'], $pricelist[$ID]['crystal'], $pricelist[$ID]['deuterium'], $pricelist[$ID]['darkmatter'], $pricelist[$ID]['norio']);
}
$template->assign_vars(array('tech' => $LNG['tech'], 'ft_head' => $LNG['ft_head'], 'ft_count' => $LNG['ft_count'], 'ft_max' => $LNG['ft_max'], 'ft_total' => $LNG['ft_total'], 'ft_charge' => $LNG['ft_charge'], 'ft_absenden' => $LNG['ft_absenden'], 'trade_allowed_ships' => $CONF['trade_allowed_ships'], 'CostInfos' => json_encode($Cost), 'Charge' => $CONF['trade_charge']));
$template->show("fleettrader_overview.tpl");
}
示例11: 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);
}
示例12: 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);
}
示例13: decode_base58
function decode_base58($btcaddress)
{
// Compute big base58 number:
$chars = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
$n = "0";
for ($i = 0; $i < strlen($btcaddress); $i++) {
$p1 = strpos($chars, $btcaddress[$i]);
if ($p1 === false) {
return false;
}
$n = bcmul($n, "58");
$n = bcadd($n, (string) $p1);
}
// Peel off bytes to get checksum / hash / version:
$checksum = "";
for ($i = 0; $i < 4; $i++) {
$byte = bcmod($n, "256");
$checksum = chr((int) $byte) . $checksum;
$n = bcdiv($n, "256");
}
$hash = "";
for ($i = 0; $i < 20; $i++) {
$byte = bcmod($n, "256");
$hash = chr((int) $byte) . $hash;
$n = bcdiv($n, "256");
}
$version = (int) $n;
// Make sure checksum is correct:
$check = hash('sha256', hash('sha256', chr($version) . $hash, true), true);
if (substr($check, 0, 4) != $checksum) {
return false;
}
return array($version, $hash, $checksum);
}
示例14: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->info('Downloading the full ROA cert list');
$roas = json_decode(file_get_contents($this->rpkiServer));
$ipv4AmountCidrArray = $this->ipUtils->IPv4cidrIpCount();
$ipv6AmountCidrArray = $this->ipUtils->IPv6cidrIpCount();
$mysqlTime = '"' . date('Y-m-d H:i:s') . '"';
$this->info('Creating the insert query');
DB::statement('DROP TABLE IF EXISTS roa_table_temp');
DB::statement('DROP TABLE IF EXISTS backup_roa_table');
DB::statement('CREATE TABLE roa_table_temp LIKE roa_table');
$roaInsert = '';
foreach ($roas->roas as $roa) {
$roaParts = explode('/', $roa->prefix);
$roaCidr = $roaParts[1];
$roaIP = $roaParts[0];
$roaAsn = str_ireplace('as', '', $roa->asn);
$startDec = $this->ipUtils->ip2dec($roaIP);
if ($this->ipUtils->getInputType($roaIP) == 4) {
$ipAmount = $ipv4AmountCidrArray[$roaCidr];
} else {
$ipAmount = $ipv6AmountCidrArray[$roaCidr];
}
$endDec = bcsub(bcadd($startDec, $ipAmount), 1);
$roaInsert .= '("' . $roaIP . '",' . $roaCidr . ',' . $startDec . ',' . $endDec . ',' . $roaAsn . ',' . $roa->maxLength . ',' . $mysqlTime . ',' . $mysqlTime . '),';
}
$this->info('Processing the insert query');
$roaInsert = rtrim($roaInsert, ',') . ';';
DB::statement('INSERT INTO roa_table_temp (ip,cidr,ip_dec_start,ip_dec_end,asn,max_length,updated_at,created_at) VALUES ' . $roaInsert);
$this->info('Hot Swapping the ROA list table');
DB::statement('RENAME TABLE roa_table TO backup_roa_table, roa_table_temp TO roa_table;');
DB::statement('DROP TABLE IF EXISTS backup_roa_table');
}
示例15: index
/**
* @param AccountRepositoryInterface $repository
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
*/
public function index(AccountRepositoryInterface $repository)
{
$types = Config::get('firefly.accountTypesByIdentifier.asset');
$count = $repository->countAccounts($types);
bcscale(2);
if ($count == 0) {
return redirect(route('new-user.index'));
}
$title = 'Firefly';
$subTitle = trans('firefly.welcomeBack');
$mainTitleIcon = 'fa-fire';
$transactions = [];
$frontPage = Preferences::get('frontPageAccounts', []);
$start = Session::get('start', Carbon::now()->startOfMonth());
$end = Session::get('end', Carbon::now()->endOfMonth());
$showTour = Preferences::get('tour', true)->data;
$accounts = $repository->getFrontpageAccounts($frontPage);
$savings = $repository->getSavingsAccounts();
$piggyBankAccounts = $repository->getPiggyBankAccounts();
$savingsTotal = 0;
foreach ($savings as $savingAccount) {
$savingsTotal = bcadd($savingsTotal, Steam::balance($savingAccount, $end));
}
$sum = $repository->sumOfEverything();
if ($sum != 0) {
Session::flash('error', 'Your transactions are unbalanced. This means a' . ' withdrawal, deposit or transfer was not stored properly. ' . 'Please check your accounts and transactions for errors.');
}
foreach ($accounts as $account) {
$set = $repository->getFrontpageTransactions($account, $start, $end);
if (count($set) > 0) {
$transactions[] = [$set, $account];
}
}
return view('index', compact('count', 'showTour', 'title', 'savings', 'subTitle', 'mainTitleIcon', 'transactions', 'savingsTotal', 'piggyBankAccounts'));
}