|
użytkowników online: 29
|
OPINIE UŻYTKOWNIKÓW
|
Uważam, że serwis jest najlepszy na świecie. Wykonany rzetelnie, a wszystkie skrypty sa dopracowane. Zamieszczony materiał godny mistrza. Jestem programistą od wielu lat i bez tego serwisu nie istnieje. Upraszacza życie każdemu programiście. Imponujący jest fakt, że do twórcy serwisu zawsze można się zwrócić z prośbą o pomoc i uzyskuje się ją w bardzo krótkim czasie. Najważniejsze w tym wszystkim jest to, że można korzystać z witryny za symboliczną opłatą.
Marcin Kowalski Multinet Polska
|
|
PODRĘCZNIK PHP 5.x, 4.x, 3.x - częściowo spolszczony / źródło: www.php.net
[Spis]
[A]
[B]
[C]
[D]
[E]
[F]
[G]
[H]
[I]
[J]
[K]
[L]
[M]
[N]
[O]
[P]
[Q]
[R]
[S]
[T]
[U]
[V]
[X]
[W]
[Z]
pow (PHP 3, PHP 4, PHP 5) pow -- Potęgowanie Opisnumber pow ( number podstawa, number wykładnik )
Zwraca argument podstawa podniesiony do potęgi
wykładnik. Jeśli możliwe, funkcja zwróci typ
integer.
Jeśli nie da się obliczyć potęgi, zostanie wyświetlone ostrzeżenie
a funkcja pow() zwróci FALSE.
Przykład 1. Parę przykładów z pow() |
<?php
var_dump( pow(2,8) ); echo pow(-1,20); echo pow(0, 0); echo pow(-1, 5.5); ?>
|
|
| Ostrzeżenie |
W PHP 4.0.6 i wcześniejszych funkcja pow() zawsze
zwracała typ float i nie wyświetlała ostrzeżeń.
|
Patrz także: exp() i sqrt().
User Contributed Notesadmin at mattwilko dot com
07-Apr-2005 06:32
Here's a function that works with negative powers:
<?php
function newpow($base, $power)
{
if ($power < 0) {
$npower = $power - $power - $power;
return 1 / pow($base, $npower);
}
else
{
return pow($base, $power);
}
}
?>
louis [at] mulliemedia.com
31-Dec-2004 05:02
Here's a pow() function that allows negative bases :
<?php
function npow($base, $exp)
{
$result = pow(abs($base), $exp);
if ($exp % 2 !== 0) {
$result = - ($result);
}
return $result;
}
?>
janklopper .AT. gmail dot.com
10-Nov-2004 03:26
since pow doesn't support decimal powers, you can use a different sollution,
thanks to dOt for doing the math!
a^b = e^(b log a)
which is no the 10log but the e-log (aka "ln")
so instead of: pow( $a , 0.6 ) use something like: exp( 0.6 * log($a) )
matthew underscore kay at ml1 dot net
18-Mar-2004 08:03
As of PHP5beta4, pow() with negative bases appears to work correctly and without errors (from a few cursory tests):
pow(-3, 3) = -27
pow(-3, 2) = 9
pow(-5, -1) = -0.2
bishop
18-Jul-2003 05:01
A couple of points on pow():
1. One of the official examples of pow(2,8) is not pragmatic; use 1 << 8 as it's substantially faster
2. When passing variables to pow(), cast them otherwise you might get warnings on some versions of PHP
3. All the rules of algebra apply: b**(-e) is 1/(b**e), b**(p/q) is the qth root of b**p
So, e.g., sqrt($x) === pow($x, .5); but sqrt() is faster.
|