本文整理汇总了PHP中bcdiv函数的典型用法代码示例。如果您正苦于以下问题:PHP bcdiv函数的具体用法?PHP bcdiv怎么用?PHP bcdiv使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bcdiv函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: price_formula_amount_profit
function price_formula_amount_profit($amazon_price, $profit_amount)
{
$temp_price = bcadd($amazon_price, bcdiv($profit_amount, 100, 9), 9);
$temp_price = bcadd($temp_price, 0.3, 9);
$ebay_price = bcdiv($temp_price, 0.871, 9);
return round($ebay_price, 2);
}
示例2: shorten
public static function shorten($num, $minLength, $chars = null, $affine = 0)
{
if (!$num) {
return null;
}
$chars = str_split($chars ? $chars : self::$chars);
$base = $divider = count($chars);
if ($minLength > 1) {
$num = bcadd($num, bcsub(bcpow($base, $minLength - 1), 1));
}
$pos = 0;
$add = $affine;
$ret = array();
while ($num > 0) {
$r = bcmod($num, $base);
$num = bcdiv($num, $base);
if (strpos($num, ".")) {
$num = substr($num, 0, strpos($num, "."));
}
if ($affine) {
$r = ($r + $add + $pos) % $base;
$add = $r;
}
$ret[$pos] = $chars[$r];
$pos++;
}
return implode("", array_reverse($ret));
}
示例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: 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);
}
示例5: frontpage
/**
* @param Collection $paid
* @param Collection $unpaid
*
* @return array
*/
public function frontpage(Collection $paid, Collection $unpaid)
{
$paidDescriptions = [];
$paidAmount = 0;
$unpaidDescriptions = [];
$unpaidAmount = 0;
bcscale(2);
/** @var TransactionJournal $entry */
foreach ($paid as $entry) {
// loop paid and create single entry:
$paidDescriptions[] = $entry->description;
$paidAmount = bcadd($paidAmount, $entry->amount_positive);
}
/** @var Bill $entry */
foreach ($unpaid as $entry) {
// loop unpaid:
$description = $entry[0]->name . ' (' . $entry[1]->format('jS M Y') . ')';
$amount = bcdiv(bcadd($entry[0]->amount_max, $entry[0]->amount_min), 2);
$unpaidDescriptions[] = $description;
$unpaidAmount = bcadd($unpaidAmount, $amount);
unset($amount, $description);
}
$data = [['value' => $unpaidAmount, 'color' => 'rgba(53, 124, 165,0.7)', 'highlight' => 'rgba(53, 124, 165,0.9)', 'label' => trans('firefly.unpaid')], ['value' => $paidAmount, 'color' => 'rgba(0, 141, 76, 0.7)', 'highlight' => 'rgba(0, 141, 76, 0.9)', 'label' => trans('firefly.paid')]];
return $data;
}
示例6: sphPack64
function sphPack64($v)
{
assert(is_numeric($v));
// x64 route
if (PHP_INT_SIZE >= 8) {
$i = (int) $v;
return pack("NN", $i >> 32, $i & (1 << 32) - 1);
}
// x32 route, bcmath
$x = "4294967296";
if (function_exists("bcmul")) {
$h = bcdiv($v, $x, 0);
$l = bcmod($v, $x);
return pack("NN", (double) $h, (double) $l);
// conversion to float is intentional; int would lose 31st bit
}
// x32 route, 15 or less decimal digits
// we can use float, because its actually double and has 52 precision bits
if (strlen($v) <= 15) {
$f = (double) $v;
$h = (int) ($f / $x);
$l = (int) ($f - $x * $h);
return pack("NN", $h, $l);
}
// x32 route, 16 or more decimal digits
// well, let me know if you *really* need this
die("INTERNAL ERROR: packing more than 15-digit numeric on 32-bit PHP is not implemented yet (contact support)");
}
示例7: 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;
}
示例8: DateDiff
function DateDiff($part, $begin, $end)
{
$diff = strtotime($end) - strtotime($begin);
switch ($part) {
case "y":
$retval = bcdiv($diff, 60 * 60 * 24 * 365);
break;
case "m":
$retval = bcdiv($diff, 60 * 60 * 24 * 30);
break;
case "w":
$retval = bcdiv($diff, 60 * 60 * 24 * 7);
break;
case "d":
$retval = bcdiv($diff, 60 * 60 * 24);
break;
case "h":
$retval = bcdiv($diff, 60 * 60);
break;
case "n":
$retval = bcdiv($diff, 60);
break;
case "s":
$retval = $diff;
break;
}
return $retval;
}
示例9: decode_username
function decode_username($hash)
{
if (!$hash) {
return 'invalid_name';
}
$username = '';
while ($hash) {
$i = bcmod($hash, 37);
$hash = bcdiv($hash, 37);
if ($i == '0') {
$username = ' ' . $username;
} else {
if ($i < 27) {
if (bcmod($hash, 37) == '0') {
$username = chr($i + 65 - 1) . $username;
} else {
$username = chr($i + 97 - 1) . $username;
}
} else {
$username = chr($i + 48 - 27) . $username;
}
}
}
return $username;
}
示例10: 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;
}
示例11: dateDiff
/**
* 获取两个日期的差
*
* @param string $interval 返回两个日期差的间隔类型
* @param mixed $startDateTime 开始日期
* @param mixed $endDateTime 结束日期
* @return string
*/
public static function dateDiff($interval, $startDateTime, $endDateTime)
{
$diff = self::getTimeStamp($endDateTime) - self::getTimeStamp($startDateTime);
$retval = 0;
switch ($interval) {
case "y":
$retval = bcdiv($diff, 60 * 60 * 24 * 365);
break;
case "m":
$retval = bcdiv($diff, 60 * 60 * 24 * 30);
break;
case "w":
$retval = bcdiv($diff, 60 * 60 * 24 * 7);
break;
case "d":
$retval = bcdiv($diff, 60 * 60 * 24);
break;
case "h":
$retval = bcdiv($diff, 60 * 60);
break;
case "n":
$retval = bcdiv($diff, 60);
break;
case "s":
default:
$retval = $diff;
break;
}
return $retval;
}
示例12: 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;
}
示例13: powmod
function powmod($base, $exponent, $modulus)
{
if (function_exists('gmp_powm')) {
// fast
return gmp_strval(gmp_powm($base, $exponent, $modulus));
}
if (function_exists('bi_powmod')) {
// not tested
return bi_sto_str(bi_powmod($base, $exponent, $modulus));
}
if (function_exists('bcpowmod')) {
// slow
return bcpowmod($base, $exponent, $modulus);
}
// emulation, slow
$square = bcmod($base, $modulus);
$result = 1;
while (bccomp($exponent, 0) > 0) {
if (bcmod($exponent, 2)) {
$result = bcmod(bcmul($result, $square), $modulus);
}
$square = bcmod(bcmul($square, $square), $modulus);
$exponent = bcdiv($exponent, 2);
}
return $result;
}
示例14: internal_to_numstr
function internal_to_numstr($num, $precision = -1, $round = true)
{
if ($precision == -1) {
$precision = 8;
$tidy = true;
} else {
$tidy = false;
}
if (!is_string($num) && !is_resource($num)) {
throw new Error('Coding error!', "internal_to_numstr argument has type '" . gettype($num) . "'");
}
$repr = gmp_strval($num);
if ($round) {
if ($repr > 0) {
$repr = bcadd($repr, pow(10, 8 - $precision) / 2);
} else {
$repr = bcsub($repr, pow(10, 8 - $precision) / 2);
}
}
$repr = bcdiv($repr, pow(10, 8), $precision);
// now tidy output...
if ($tidy) {
return clean_sql_numstr($repr);
}
return sprintf("%.{$precision}f", $repr);
}
示例15: 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);
}