downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

rad2deg> <pi
Last updated: Fri, 24 Jul 2009

view this page in

pow

(PHP 4, PHP 5)

pow거듭제곱 표현

설명

number pow ( number $base , number $exp )

baseexp 승을 반환합니다.

Warning

PHP 4.0.6까지 pow()는 항상 float를 반환하였고, 경고를 발생하지 않았습니다.

인수

base

사용할 밑

exp

승수

반환값

baseexp 승. 결과가 정수로 표현될 수 있으면 integer형으로 반환하고, 그렇지 않으면 float형으로 반환합니다. 거듭제곱을 계산할 수 없으면 FALSE를 반환합니다.

변경점

버전 설명
4.0.6부터 가능하면 결과를 interger로 반환합니다. 이전에는 항상 float로 결과를 반환했습니다. 오래된 버전에서는 복잡한 수에 대해서 이상한 결과를 얻을 수도 있습니다.
4.2.0부터 PHP가 값을 계산할 수 없을 때, 경고를 발생하지 않습니다. 조용히 FALSE만 반환합니다.

예제

Example #1 pow()의 몇몇 예제

<?php

var_dump
(pow(28)); // int(256)
echo pow(-120); // 1
echo pow(00); // 1

echo pow(-15.5); // PHP >4.0.6  NAN
echo pow(-15.5); // PHP <=4.0.6 1.#IND
?>

참고

  • exp() - e의 누승을 계산
  • sqrt() - 평방 제곱근
  • bcpow() - 임의 정밀도 수 거듭제곱
  • gmp_pow() - Raise number into power



rad2deg> <pi
Last updated: Fri, 24 Jul 2009
 
add a note add a note User Contributed Notes
pow
Matt Dudley
17-Jul-2008 07:14
Calculate wind chill based on the National Weather Service formula.

$temp = 25;
$wind_speed_mph = 6;

$wind_chill = 35.74+(.6215*$temp_f)-(35.75*(pow($wind_speed_mph, 0.16)))+(.4275*$temp_f*(pow($wind_speed_mph, 0.16)));

Value only valid when the temp is 45 or below.... I used this with a weather script I wrote that reads an xml file. They don't provide wind chill.
Docey
05-May-2007 02:33
no integer breaking here, pow just silently switches to using floats instead of integers.

pow(2, 31) = integer value
pow(2, 32) = float value.

the manual says the limit for floats is machine dependent so i did a little loop to see how far it will go before becomming infinit. the result is 1023.

pow(2, 1023) = float
pow(2, 1024) = ifinit.

tested on php 4.4.1 under windows2000 on an AMD AthlonXP 2800+.
gilthansREMOVEME at gmail dot com
16-Dec-2006 12:50
Note that pow(0, 0) equals to 1 on PHP 4 (only tested it there), although mathematically this is undefined.
moikboy (nospam) moikboy (nospam) hu
10-May-2006 05:27
Here is a function for calculating the $k-th root of $a :

<?php
function root($a,$k){return(($a<0&&$k%2>0)?-1:1)*pow(abs($a),1/$k);};
?>
louis [at] mulliemedia.com
01-Jan-2005 01: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 11: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 04: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 12: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.

rad2deg> <pi
Last updated: Fri, 24 Jul 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites