本文整理汇总了PHP中log10函数的典型用法代码示例。如果您正苦于以下问题:PHP log10函数的具体用法?PHP log10怎么用?PHP log10使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了log10函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ProdottiInEvidenza
/**
*
* @return type json dell' array dei prodotti della home
*/
public function ProdottiInEvidenza()
{
$ProdottoDAO = new FProdotto();
$risultato = $ProdottoDAO->ContaProdotti();
$risultato = $risultato[0]["COUNT(Id)"];
//Risultato contiene il num di prodotti presenti nel Catalogo
$Indicicasuali = array();
for ($index = 0; $index < 6; $index++) {
$Indicicasuali[] = rand(1, $risultato);
}
$Indicicasuali = array_unique($Indicicasuali);
while (count($Indicicasuali) < 6) {
$Indicicasuali[] = rand(1, $risultato);
$Indicicasuali = array_unique($Indicicasuali);
}
$CRicercaProdotto = new CRicercaProdotto();
$ArrayProdotti = array();
foreach ($Indicicasuali as $key => $value) {
for ($i = 0; $i < 2 - log10($value); $i++) {
$value = "0" . $value;
}
$value = "P" . $value;
$ArrayProdotti[] = $CRicercaProdotto->RicercaPerId($value);
}
$JsonRisultato = json_encode($ArrayProdotti);
return $JsonRisultato;
}
示例2: decode
/**
* Decode a geohash and return an array with decimal lat,long in it
*/
public function decode($hash)
{
//decode hash into binary string
$binary = "";
$hl = strlen($hash);
for ($i = 0; $i < $hl; $i++) {
$binary .= $this->codingMap[substr($hash, $i, 1)];
}
//split the binary into lat and log binary strings
$bl = strlen($binary);
$blat = "";
$blong = "";
for ($i = 0; $i < $bl; $i++) {
if ($i % 2) {
$blat = $blat . substr($binary, $i, 1);
} else {
$blong = $blong . substr($binary, $i, 1);
}
}
//now concert to decimal
$lat = $this->binDecode($blat, -90, 90);
$long = $this->binDecode($blong, -180, 180);
//figure out how precise the bit count makes this calculation
$latErr = $this->calcError(strlen($blat), -90, 90);
$longErr = $this->calcError(strlen($blong), -180, 180);
//how many decimal places should we use? There's a little art to
//this to ensure I get the same roundings as geohash.org
$latPlaces = max(1, -round(log10($latErr))) - 1;
$longPlaces = max(1, -round(log10($longErr))) - 1;
//round it
$lat = round($lat, $latPlaces);
$long = round($long, $longPlaces);
return array($lat, $long);
}
示例3: testTwoAxis
/**
* @dataProvider twoAxisDataProvider
**/
public function testTwoAxis($firstAxisData, $secondtAxisData, $result)
{
foreach ($result as $chartClass => $expectedString) {
$views = GoogleChartDataSet::create()->setData($firstAxisData);
$clicks = GoogleChartDataSet::create()->setData($secondtAxisData);
$chart = new $chartClass();
if ($chart->getData()->isNormalized()) {
if ($views->getMax() >= 10) {
$base = pow(10, floor(log10($views->getMax())));
} else {
$base = 0.1;
}
$views->setBase($base);
if ($clicks->getMax() >= 10) {
$base = pow(10, floor(log10($clicks->getMax())));
} else {
$base = 0.1;
}
$clicks->setBase($base);
}
$viewAxis = GoogleChartAxis::create(new GoogleChartAxisType(GoogleChartAxisType::Y))->setRange($views->getMinMax());
$clickAxis = GoogleChartAxis::create(new GoogleChartAxisType(GoogleChartAxisType::R))->setRange($clicks->getMinMax());
if ($chart->getData()->isNormalized()) {
$viewAxis->setInterval($views->getBase());
$clickAxis->setInterval($clicks->getBase());
}
$chart->setSize(GoogleChartSize::create()->setWidth(300)->setHeight(300))->addAxis($viewAxis)->addLine(GoogleChartLine::create()->setTitle('Показы')->setColor(Color::create('336699'))->setValue($views))->addAxis($clickAxis)->addLine(GoogleChartLine::create()->setTitle('Клики')->setColor(Color::create('339911'))->setValue($clicks));
$this->assertEquals($expectedString, $chart->toString());
}
}
示例4: isPalindromic
/**
* Determine if the integer is palindromic. This works by comparing the most significant and least significant digits
* at each iteration for equality. If they are equal it keeps iterating. If it makes it half-way through the integer
* with no differences, the integer is palindromic.
* The most significant digit is found by dividing the integer by 10^the number of digits in the integer. If the
* integer is 98789 then the number of digits is 5, then 98789 is divided by 10^4(10000). This results in
* 98789 / 10000 = 9.8789. This value is treated as an integer so it's just 9.
* The least significant digit is found by calculating the modulo of the integer and 10. If the integer is 98789 then
* this results in 98789 % 10 = 9.
* If the digits match in an iteration then the modulo of the original iterator and 10^the number of digits in the
* integer is found. This becomes the new integer value. If the integer is 98789 then this results in 98789 % 10000 =
* 8789. Then the copy of the original integer is divided by 10 to remove the least significant digit. If the copy of
* the original integer is 98789 this results in 98789 / 10 = 9878.9. This is treated as an integer so it's just 9878.
* After this happens we have two new integers, 8789 and 9878 which are the result of the original integer 98789 with
* the most significant and least significant digits stripped, respectively.
*
* If the number is 98789:
* $numberOfDigits = 5
* $msdShift = 10000
*
* Iteration 1:
* 98789 / 10000 = 9.8789 rounded to 9 AND 98789 % 10 = 9 so we continue
* $integer = 98789 % 10000 = 8789
* $msdShift = 10000 / 10 = 1000
* $integerRemaining = 98789 / 10 = 9878
*
* Iteration 2:
* 8789 / 1000 = 8.789 rounded to 8 AND 9878 % 10 = 8 so we continue
* $integer = 8789 % 1000 = 789
* $msdShift = 1000 / 10 = 100
* $integerRemaining = 9878 / 10 = 987
*
* Iteration 3:
* 789 / 100 = 7.89 rounded to 7 AND 987 % 10 = 7 so we continue
* $integer = 789 % 100 = 89
* $msdShift = 100 / 10 = 10
* $integerRemaining = 987 / 10 = 98
*
* Iteration 4:
* 89 / 10 = 8.9 rounded to 8 AND 98 % 10 = 8 so we continue
* $integer = 89 % 10 = 9
* $msdShift = 10/10 = 1
* $integerRemaining = 98 / 10 = 9
*
* We have reached the middle so we are done, 98789 is palindromic
*
*
* If the number is 9587:
* $numberOfDigits = 4
* $msdShift = 1000
*
* Iteration 1:
* 9587 / 1000 = 9.587 rounded to 9 AND 9587 % 10 = 7 so 9587 is not a palindrome
*
* @param $integer
* @return bool
*/
function isPalindromic($integer)
{
if (!is_numeric($integer)) {
throw new \InvalidArgumentException('$integer must be a number');
}
$integer = (int) $integer;
if ($integer < 0) {
return false;
}
if ($integer === 0) {
return true;
}
$numberOfDigits = floor(log10($integer)) + 1;
$integerRemaining = $integer;
$msdShift = pow(10, $numberOfDigits - 1);
for ($i = 0; $i < $numberOfDigits / 2; $i++) {
if ((int) ($integer / $msdShift) != (int) ($integerRemaining % 10)) {
return false;
}
$integer %= $msdShift;
$msdShift /= 10;
$integerRemaining /= 10;
}
return true;
}
示例5: actionView
public function actionView($id)
{
if ($id <= 0) {
$this->goHome();
}
$allCategory = Category::find()->asArray()->all();
$arrayCategoryIdName = ArrayHelper::map($allCategory, 'id', 'name');
$arrSubCat = Category::getArraySubCatalogId($id, $allCategory);
/****** 价格筛选 ****/
$result = (new Query())->select('min(price) as min, max(price) as max')->from('product')->where(['category_id' => $arrSubCat, 'status' => Status::STATUS_ACTIVE])->one();
$min = $result['min'];
$max = $result['max'];
if ($max > $min && $max > 0) {
// 计算跨度
$priceGrade = 0.0001;
for ($i = -2; $i < log10($max); $i++) {
$priceGrade *= 10;
}
$span = ceil(($max - $min) / 5 / $priceGrade) * $priceGrade;
if ($span == 0) {
$span = $priceGrade;
}
// 计算价格的起点和终点
for ($i = 1; $min > $span * $i; $i++) {
}
for ($j = 1; $min > $span * ($i - 1) + $priceGrade * $j; $j++) {
}
$priceFilter['start'] = $span * ($i - 1) + $priceGrade * ($j - 1);
for (; $max >= $span * $i; $i++) {
}
$priceFilter['end'] = $span * $i + $priceGrade * ($j - 1);
$priceFilter['span'] = $span;
}
/****** 价格筛选 end ****/
/****** 品牌筛选 start ****/
$result = (new Query())->select('distinct(brand_id)')->from('product')->where(['category_id' => $arrSubCat, 'status' => Status::STATUS_ACTIVE])->all();
$ids = ArrayHelper::map($result, 'brand_id', 'brand_id');
$brandFilter = Brand::find()->where(['id' => $ids])->orderBy(['name' => SORT_ASC])->all();
/****** 品牌筛选 end ****/
$query = Product::find()->where(['category_id' => $arrSubCat, 'status' => Status::STATUS_ACTIVE]);
// 如果选择了价格区间
if (Yii::$app->request->get('max')) {
$min = intval(Yii::$app->request->get('min'));
$max = intval(Yii::$app->request->get('max'));
if ($min >= 0 && $max) {
$query->andWhere(['and', ['>', 'price', $min], ['<=', 'price', $max]]);
}
}
// 如果选择了品牌
if (Yii::$app->request->get('brand_id')) {
$brandId = intval(Yii::$app->request->get('brand_id'));
if ($brandId >= 0) {
$query->andWhere(['brand_id' => $brandId]);
}
}
// 侧边热销商品
$sameCategoryProducts = Product::find()->where(['category_id' => $id])->orderBy(['sales' => SORT_DESC])->limit(5)->all();
$dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['defaultPageSize' => Yii::$app->params['defaultPageSizeProduct']], 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]]]);
return $this->render('view', ['model' => $this->findModel($id), 'allCategory' => $allCategory, 'arrayCategoryIdName' => $arrayCategoryIdName, 'products' => $dataProvider->getModels(), 'pagination' => $dataProvider->pagination, 'priceFilter' => isset($priceFilter) ? $priceFilter : null, 'brandFilter' => $brandFilter, 'sameCategoryProducts' => $sameCategoryProducts]);
}
示例6: pctcolour
function pctcolour($pct)
{
if ($pct == 100) {
$fg = 'white';
$bg = 'black';
}
if ($pct < 100) {
$grn = (2.0 - log10($pct)) * 255;
if ($grn < 0) {
$grn = 0;
}
if ($grn > 255) {
$grn = 255;
}
if ($grn > 190) {
$fg = 'blue';
} else {
$fg = 'white';
}
$bg = sprintf("#00%02x00", $grn);
}
if ($pct > 100) {
$red = (log10(pow($pct, 4.0)) - 8.0) / 3.0 * 255;
if ($red < 0) {
$red = 0;
}
if ($red > 255) {
$red = 255;
}
$fg = 'white';
$bg = sprintf("#%02x0000", $red);
}
return array($fg, $bg);
}
示例7: Generate
function Generate($level)
{
if ($level <= 3) {
$base = rand(2, 3);
$result = rand(5, 10);
} elseif ($level <= 6) {
$base = rand(4, 5);
$result = rand(10, 15);
} else {
$base = rand(6, 7);
$result = rand(15, 20);
}
// // Original exercise
// $base = 2;
// $result = 10;
$question = 'Oldja meg a következő egyenletet a valós számok halmazán! Válaszát három tizedesjegyre kerekítve adja meg!$$' . $base . '^x=' . $result . '$$';
$exponent1 = log10($result) / log10($base);
$exponent2 = round2($exponent1, 5);
$correct = round2($exponent1, 3);
$solution = '$' . $correct . '$';
$page[] = 'Vegyük mindkét oldal $10$-es alapú logaritmusát:$$\\log_{10}\\left(' . $base . '^x\\right)=\\log_{10}' . $result . '$$';
$page[] = '<div class="alert alert-info"><strong>Logaritmus azonossága:</strong><br />Hatvány logaritmusa egyenlő az alap logaritmusának és a kitevőnek a szorzatával:$$\\log_ab^k=k\\cdot\\log_ab$$</div>';
$page[] = 'Az azonosság felhasználásával át tudjuk írni a baloldali kifejezést:$$x\\cdot\\log_{10}' . $base . '=\\log_{10}' . $result . '$$';
$hints[] = $page;
$page = [];
$page[] = 'Osszuk el mindkét oldalt $\\log_{10}' . $base . '$-' . With($base) . '!$$x=\\frac{\\log_{10}' . $result . '}{\\log_{10}' . $base . '}\\approx' . $exponent2 . '$$';
$page[] = '<b>Megjegyzés</b>: a számológépen a tízes alapú logaritmust a <b>log</b> gomb jelöli:<div class="text-center"><kbd>' . $result . '</kbd> <kbd>log</kbd> <kbd>÷</kbd> <kbd>' . $base . '</kbd> <kbd>log</kbd> <kbd>=</kbd></div>';
$page[] = 'A megoldás három tizedesjegyre kerekített értéke <span class="label label-success">$' . $correct . '$</span>.';
$hints[] = $page;
return array('question' => $question, 'correct' => $correct, 'solution' => $solution, 'hints' => $hints);
}
示例8: convfunc
function convfunc($valtoconv, $convtowhat)
{
if ($valtoconv == 0) {
return 0;
}
if (strlen($valtoconv) == 1) {
return $valtoconv;
}
switch ($convtowhat) {
case 1:
$a = $valtoconv / 20.0;
$b = pow(10, $a);
$c = $b * sqrt(8);
$x = $c;
error_log("a = {$a}, b = {$b}, c = {$c}");
return $x;
case 2:
$a = $valtoconv / sqrt(8);
$b = log10($a);
$c = 20.0 * $b;
$x = $c;
error_log("a = {$a}, b = {$b}, c = {$c}");
return $x;
default:
return $valtoconv;
}
}
示例9: FromReal
public function FromReal($aVal, $aPrecision = 2)
{
// Convert a floating point number to scientific notation
$neg = 1.0;
if ($aVal < 0) {
$neg = -1.0;
$aVal = -$aVal;
}
$l = floor(log10($aVal));
$a = sprintf("%0." . $aPrecision . "f", round($aVal / pow(10, $l), $aPrecision));
$a *= $neg;
if ($this->iSimple && ($a == 1 || $a == -1)) {
$a = '';
}
if ($a != '') {
$this->t = $a . ' * 10';
} else {
if ($neg == 1) {
$this->t = '10';
} else {
$this->t = '-10';
}
}
$this->iSuper = $l;
}
示例10: decode
public function decode($hash)
{
$binary = "";
$hl = strlen($hash);
for ($i = 0; $i < $hl; $i++) {
$binary .= $this->codingMap[substr($hash, $i, 1)];
}
$bl = strlen($binary);
$blat = "";
$blong = "";
for ($i = 0; $i < $bl; $i++) {
if ($i % 2) {
$blat = $blat . substr($binary, $i, 1);
} else {
$blong = $blong . substr($binary, $i, 1);
}
}
$lat = $this->binDecode($blat, -90, 90);
$long = $this->binDecode($blong, -180, 180);
$latErr = $this->calcError(strlen($blat), -90, 90);
$longErr = $this->calcError(strlen($blong), -180, 180);
$latPlaces = max(1, -round(log10($latErr))) - 1;
$longPlaces = max(1, -round(log10($longErr))) - 1;
$lat = round($lat, $latPlaces);
$long = round($long, $longPlaces);
return array($lat, $long);
}
示例11: toDecimal
/**
* From roman to decimal numeral system
*
* @param string $sRoman
* @return integer 0 on failure.
*/
public static function toDecimal($sRoman)
{
if (!is_string($sRoman)) {
return 0;
}
$iStrLen = strlen($sRoman);
$iDoubleSymbol = $iDec = $iPos = 0;
foreach (self::$asRomanTransTable as $iNum => $sSymbol) {
$iLen = strlen($sSymbol);
$iCount = 0;
if ($iDoubleSymbol) {
--$iDoubleSymbol;
continue;
}
# Mind the fact that 1000 in the Roman numeral system may be represented by M or i.
while (($sChunk = substr($sRoman, $iPos, $iLen)) == $sSymbol || $iNum < 10000.0 && $sChunk == strtr($sSymbol, 'iM', 'Mi')) {
if ($iLen == 2) {
$iDoubleSymbol = 3 - 2 * ($iNum % 3);
}
$iDec += $iNum;
$iPos += $iLen;
# All symbols that represent 1eX may appear at maximum three times. All other symbols may only represent one time in a roman number.
if (fmod(log10($iNum), 1) || ++$iCount == 3) {
break;
}
}
if ($iPos == $iStrLen) {
break;
}
}
# If there are symbols left, then the number was mallformed (following default rules (M = 1000 and i = 1000)).
return $iPos == $iStrLen ? $iDec : 0;
}
示例12: execute
/** {@inheritdoc} */
protected function execute(InputInterface $input, OutputInterface $output)
{
$type = $input->getOption('type');
if (!in_array($type, array('error', 'exception'))) {
throw new \LogicException('Type must be either "error" or "exception"');
}
$count = intval($input->getOption('count'));
$digits = floor(log10($count) + 1);
/** @var ErrorHandler $errorHandler */
$errorHandler = $this->getContainer()->get('error_handler');
$metadata = new Metadata();
$metadata->addCategories($input->getArgument('category'));
$output->writeln('<fg=cyan>Creating errors</fg=cyan>');
for ($i = 1; $i <= $count; ++$i) {
switch ($type) {
case 'error':
$error = new ErrorException('TEST ERROR', E_USER_ERROR, __FILE__, __LINE__);
$errorHandler->handleError($error, $metadata);
break;
case 'exception':
$errorHandler->handleException(new \Exception(), $metadata);
break;
}
$output->writeln(sprintf("<comment>[%{$digits}d/%{$digits}d]</comment> <info>OK</info>", $i, $count));
}
$output->writeln('<info>DONE</info>');
}
示例13: setPoweredBy
/**
* Set the power
*
* @param int p power
* @throws lang.IllegalArgumentException in case the parameter p contains an illegal value
*/
public function setPoweredBy($p)
{
if (!($x = log10($p / 6.1)) || floor($x) != $x) {
throw new IllegalArgumentException($p . ' not allowed');
}
$this->poweredBy = $p;
}
示例14: good_125step
function good_125step($x)
{
$n = (int) floor(log10($x));
$residue = $x / pow(10, $n);
# Equality test on floats isn't usually safe, but it works here.
return $residue == 1 || $residue == 2 || $residue == 5;
}
示例15: radixSortInt
function radixSortInt($array)
{
$maxPow = floor(log10(max($array)));
for ($i = 0; $i <= $maxPow; $i++) {
// makes an array of buckets to sort mod into
$bucketArray = [];
for ($j = -9; $j < 10; $j++) {
$bucketArray[$j] = 0;
}
foreach ($array as $element) {
$bucketArray[$element / 10 ** $i % 10]++;
}
$bucketArray[-9]--;
for ($j = -8; $j < 10; $j++) {
$bucketArray[$j] += $bucketArray[$j - 1];
}
$arraySorted = $array;
for ($j = count($array) - 1; $j >= 0; $j--) {
$arraySorted[$bucketArray[$array[$j] / 10 ** $i % 10]] = $array[$j];
$bucketArray[$array[$j] / 10 ** $i % 10]--;
}
$array = $arraySorted;
}
return $array;
}