/** * @param float $x A number * @return float The natural logarithm (base e) of 1 + the given value */ public function log1p($x) { return log1p($x); }
/** * Returns log(1 + number), computed in a way that is accurate even when * the value of number is close to zero. * @link http://php.net/manual/en/function.log1p.php * @param float $number <p>The argument to process</p> * @return float log(1 + <i>number</i>) */ public static function log1p($number) { return log1p($number); }
/** * 根据链接热度信息生成常用链接 * * @param integer $check 保证不会由浏览器访问直接触发 * @return boolean 是否执行成功 */ function generate_common($check = 0) { if (!$check) { show_404(); } $this->load->model('url_m'); $this->load->model('common_m'); $topurl = $this->url_m->get_by_heat(8); $this->common_m->clean(4); foreach ($topurl as $row) { $tmp = array(); $tmp['url'] = $row->url; $tmp['name'] = $row->name; $tmp['rank'] = ceil(200 - log1p($row->heat) * 10); $this->common_m->insert_url($tmp); } return TRUE; }
function atanh($x) { return log1p(2 * $x / (1 - $x)) / 2; }
/** * @return $this * @desc 返回 log(1 + number)。 */ public function log1p() { $this->current = log1p($this->toDouble()); return $this; }
/** * This method returns the natural logarithm of this object's value plus one. * * @access public * @static * @param IReal\Type $x the operand * @return IDouble\Type the result */ public static function log1p(IReal\Type $x) : IDouble\Type { return IDouble\Type::box(log1p($x->unbox())); }
$ep = 1.0E-5; if (abs($a - $b) < $ep) { echo "<br />", "true"; } if ($a != $b) { echo "<br />", "11111111111111"; } ?> <?php $nan = acos(8); var_dump($nan, is_nan($nan)); echo "*****************************<br />"; echo rand(), "<br />"; echo log10(1000), "<br />"; echo log1p(1 + 1.0E-33), "<br />"; echo log(16, 2), "<br />"; ?> <?php echo "+++++++++++++++++++++++++++++++++++++++++<br />"; echo max(1, 2, 3, 4, 5), "<br />"; echo max(array(1, 2, 3, 4, 5, 5, 4, 7, 3)), "<br />"; echo gettype(array(12, 34, 5)), "<br />"; echo max('42', 3, "lit", "qqq", 'aaa', 'n'), "<br />"; echo max('hello', 0), "<br />"; echo max(0, 'hello'), "<br />"; echo count(array(1, 2, 3, 4, 5, 7, 6, 5, 4, 2, 1)), "<br />"; echo "+++++++++++++++++++++++++++++++++++++++++<br />"; $val = max('string', array(2, 5, 7), 42); echo $val;
<?php /* Prototype : float log1p ( float $arg ) * Description: Returns log(1 + number), computed in a way that is accurate even * when the value of number is close to zero * Source code: ext/standard/math.c */ echo "*** Testing log1p() : error conditions ***\n"; echo "\n-- Testing log1p() function with less than expected no. of arguments --\n"; log1p(); echo "\n-- Testing log1p() function with more than expected no. of arguments --\n"; log1p(36, true); ?> ===Done===
<?php /* Prototype : float log1p ( float $arg ) * Description: Returns log(1 + number), computed in a way that is accurate even * when the value of number is close to zero * Source code: ext/standard/math.c */ echo "*** Testing log1p() : basic functionality ***\n"; $values = array(23, -23, 23.45, -23.45, 0x17, 027, "23", "23.45", "2.345e1", null, true, false); echo "\n LOG1p tests\n"; foreach ($values as $value) { echo "\n-- log1p {$value} --\n"; var_dump(log1p($value)); } ?> ===Done===
/** * Calculates the inverse sine of a complex number: z = asinAlt(c1) * Uses an alternative algorithm * * @param Math_Complex $c1 * @return Math_Complex A valid Math_Complex number on success * @throws InvalidArgumentException */ public static function asinAlt(Math_Complex $c1) { if (!Math_ComplexOp::isComplex($c1)) { throw new InvalidArgumentException('argument is not a Math_Complex object'); } $r = $c1->getReal(); $i = $c1->getIm(); if ($i == 0) { return Math_ComplexOp::asinReal($r); } else { $x = abs($r); $y = abs($i); $r = hypot($x + 1, $y); $s = hypot($x - 1, $y); $a = ($r + $s) / 2; $b = $x / $a; $y2 = $y * $y; $ac = 1.5; $bc = 0.6417; // crossover values if ($b <= $bc) { $real = asin($b); } else { if ($x <= 1) { $d = 0.5 * ($a + $x) * ($y2 / ($r + $x + 1) + ($s + (1 - $x))); $real = atan2($x, sqrt($d)); } else { $ax = $a + $x; $d = 0.5 * ($ax / ($r + $x + 1) + $ax / ($s + ($x - 1))); $real = atan2($x, $y * sqrt($d)); } } if ($a <= $ac) { if ($x < 1) { $m = 0.5 * ($y2 / ($r + ($x + 1)) + $y2 / ($s + (1 - $x))); } else { $m = 0.5 * ($y2 / ($r + ($x + 1)) + ($s + ($x - 1))); } $im = log1p($m + sqrt($m * ($a + 1))); } else { $im = log($a + sqrt($a * $a - 1)); } $real = $r >= 0 ? $real : -1 * $real; $im = $i >= 0 ? $im : -1 * $im; return new Math_Complex($real, $im); } }
/** * Perform a log-modulo transformation * * @param $value The value to transform * * @return double The transformed value */ protected function log($value) { $sign = $value > 0 ? 1 : -1; return $sign * log1p($sign * $value) / log($this->base); }
var_dump(base_convert("A37334", 16, 2)); VC(pow(2, 8), 256); VC(pow(-1, 20), 1); var_dump(pow(0, 0)); var_dump(is_int(pow(2, 32))); VC(pow("2", "8"), 256); VC(pow("-1", "20"), 1); var_dump(pow("0", "0")); var_dump(is_int(pow("2", "32"))); VC(exp(12), 162754.791419); VC(exp(5.7), 298.86740096706); VC(expm1(5.7), 297.8674); var_dump(log10(10)); var_dump(log10(100)); VC(log1p(9), 2.302585092994); VC(log1p(99), 4.6051701859881); VC(log(8), 2.0794415416798); var_dump(log(8, 2)); VC(cos(M_PI), -1); VC(cosh(1.23), 1.8567610569853); VC(sin(deg2rad(90)), 1); VC(sinh(1.23), 1.5644684793044); VC(tan(deg2rad(45)), 1); VC(tanh(1.23), 0.84257932565893); VC(acos(-1), M_PI); VC(acosh(1.8567610569853), 1.23); VC(asin(1), deg2rad(90)); VC(asinh(1.5644684793044), 1.23); VC(atan(1), deg2rad(45)); VC(atanh(0.84257932565893), 1.23); VC(atan2(3, 4), 0.64350110879328);
public static function logarithm($x, $base) { if ($base == 10) { return self::logarithmDecade($x); } if ($x < 1.0) { return log1p($x); } return log($x, $base); }
/** * Returns the value of log gamma(1 + x) for -0.5 <= x <= 1.5. */ public static function logGamma1p($x) { if ($x < -0.5) { throw new Exception($x . " is smaller then the minimum -0.5"); } if ($x > 1.5) { throw new Exception($x . " is larger then the maximum 1.5"); } return -1.0 * log1p(Statistics::invGamma1pm1($x)); }
<?php define("MAX_64Bit", 9223372036854775807); define("MAX_32Bit", 2147483647); define("MIN_64Bit", -9223372036854775807 - 1); define("MIN_32Bit", -2147483647 - 1); $longVals = array(MAX_64Bit, MIN_64Bit, MAX_32Bit, MIN_32Bit, MAX_64Bit - MAX_32Bit, MIN_64Bit - MIN_32Bit, MAX_32Bit + 1, MIN_32Bit - 1, MAX_32Bit * 2, MAX_32Bit * 2 + 1, MAX_32Bit * 2 - 1, MAX_64Bit - 1, MAX_64Bit + 1, MIN_64Bit + 1, MIN_64Bit - 1); foreach ($longVals as $longVal) { echo "--- testing: {$longVal} ---\n"; var_dump(log1p($longVal)); } ?> ===DONE===
echo "woops, getrandmax: " . getrandmax() . "\n"; } } echo "hexdec\n"; echo hexdec("-2354") . " " . hexdec("foo") . " " . hexdec(0) . " " . hexdec(5) . hexdec("1.2345") . "\n"; if (PHP_OS != 'WINNT') { echo "hypot\n"; echo hypot(-2354, 34) . " " . hypot("foo", 2) . " " . hypot(0, 0) . " " . hypot(5, 12) . hypot(1.2345, 2.3234) . "\n"; } echo "log\n"; echo log(-2354) . " " . log("foo") . " " . log(0) . " " . log(5) . log(1.2345) . "\n"; echo "log10\n"; echo log10(-2354) . " " . log10("foo") . " " . log10(0) . " " . log10(5) . log10(1.2345) . "\n"; if (PHP_OS != 'WINNT') { echo "log1p\n"; echo log1p(-2354) . " " . log1p("foo") . " " . log1p(0) . " " . log1p(5) . log1p(1.2345) . "\n"; } echo "octdec\n"; echo octdec("-2354") . " " . octdec("foo") . " " . octdec(0) . " " . octdec(5) . octdec("1.2345") . "\n"; echo "pi\n"; echo pi() . "\n"; echo "pow\n"; echo pow(-2354, 4) . " " . pow("foo", 2) . " " . pow(0, 0) . " " . pow(5, 12) . pow(1.2345, 2.3234) . "\n"; var_dump(pow(2, 2)); echo "\n"; var_dump(pow(2, 2.0)); var_dump(pow(2.0, 2.0)); var_dump(pow(2.0, 2)); echo pow(2, 64) . "\n"; echo pow(2, 64.0) . "\n"; echo "rad2deg\n";
* Description: Returns log(1 + number), computed in a way that is accurate even * when the value of number is close to zero * Source code: ext/standard/math.c */ echo "*** Testing log1p() : usage variations ***\n"; //get an unset variable $unset_var = 10; unset($unset_var); // heredoc string $heredoc = <<<EOT abc xyz EOT; // get a class class classA { } // get a resource variable $fp = fopen(__FILE__, "r"); $inputs = array(0, 1, 12345, -2345, 2147483647, -2147483648, 10.5, -10.5, 123456.789, 0.00123456789, 0.5, NULL, null, true, false, TRUE, FALSE, "", '', array(), "abcxyz", 'abcxyz', $heredoc, new classA(), @$undefined_var, @$unset_var, $fp); // loop through each element of $inputs to check the behaviour of log1p() $iterator = 1; foreach ($inputs as $input) { echo "\n-- Iteration {$iterator} --\n"; var_dump(log1p($input)); $iterator++; } fclose($fp); ?> ===Done===