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);};
?>
![]() | pow说明number pow ( number base, number exp )返回 base 的 exp 次方的幂。如果可能,本函数会返回 integer。 如果不能计算幂,将发出一条警告,pow() 将返回 FALSE。PHP 4.2.0 版开始 pow() 不要产生任何的警告。
![]()
moikboy (nospam) moikboy (nospam) hu
10-May-2006 04:27
Here is a function for calculating the $k-th root of $a :
admin at mattwilko dot com
08-Apr-2005 12:32
Here's a function that works with negative powers:
louis [at] mulliemedia.com
01-Jan-2005 12:02
Here's a pow() function that allows negative bases :
janklopper .AT. gmail dot.com
10-Nov-2004 10:26
since pow doesn't support decimal powers, you can use a different sollution,
matthew underscore kay at ml1 dot net
18-Mar-2004 03:03
As of PHP5beta4, pow() with negative bases appears to work correctly and without errors (from a few cursory tests):
bishop
18-Jul-2003 11:01
A couple of points on pow(): | ![]() | |||