Math 函数

目录

  • abs — 绝对值
  • acos — 反余弦
  • acosh — 反双曲余弦
  • asin — 反正弦
  • asinh — 反双曲正弦
  • atan — 反正切
  • atan2 — 两个参数的反正切
  • atanh — 反双曲正切
  • base_convert — 在任意进制之间转换数字
  • bindec — 二进制转换为十进制
  • ceil — 进一法取整
  • cos — 余弦
  • cosh — 双曲余弦
  • decbin — 十进制转换为二进制
  • dechex — 十进制转换为十六进制
  • decoct — 十进制转换为八进制
  • deg2rad — 将角度转换为弧度
  • exp — 计算 e 的指数
  • expm1 — 返回 exp($num) - 1,甚至当 number 的值接近零也能计算出准确结果
  • fdiv — Divides two numbers, according to IEEE 754
  • floor — 舍去法取整
  • fmod — 返回除法的浮点数余数
  • fpow — Raise one number to the power of another, according to IEEE 754
  • hexdec — 十六进制转换为十进制
  • hypot — 计算直角三角形的斜边长度
  • intdiv — 对除法结果取整
  • is_finite — 判断浮点数是否是有效的有限值
  • is_infinite — 判断浮点数是否为无限值
  • is_nan — 判断浮点数是否是否为 NAN
  • log — 自然对数
  • log10 — 以 10 为底的对数
  • log1p — 返回 log(1 + number),甚至当 number 的值接近零也能计算出准确结果
  • max — 找出最大值
  • min — 找出最小值
  • octdec — 八进制转换为十进制
  • pi — 得到圆周率值
  • pow — 指数表达式
  • rad2deg — 将弧度数转换为相应的角度数
  • round — 对浮点数进行四舍五入
  • sin — 正弦
  • sinh — 双曲正弦
  • sqrt — 平方根
  • tan — 正切
  • tanh — 双曲正切
添加备注

用户贡献的备注 4 notes

up
11
pat.mat AT sympatico DOT com
20 years ago
For people interest in Differential Equations, I've done a function that receive a string like: x^2+x^3 and put it in
2x+3x^2 witch is the differantial of the previous equation.

In the code there is one thing missing: the $string{$i} is often going outOfBound (Uninitialized string offset: 6 in...)
if your error setting is set a little too high... I just dont know how to fix this.

So there is the code for differential equation with (+ and -) only:

<?
function differentiel($equa)
{
$equa = strtolower($equa);
echo
"Equation de depart: ".$equa."<br>";
$final = "";

for(
$i = 0; $i < strlen($equa); $i++)
{
//Make a new string from the receive $equa
if($equa{$i} == "x" && $equa{$i+1} == "^")
{
$final .= $equa{$i+2};
$final .= "x^";
$final .= $equa{$i+2}-1;
}
elseif(
$equa{$i} == "+" || $equa{$i} == "-")
{
$final .= $equa{$i};
}
elseif(
is_numeric($equa{$i}) && $i == 0)
{
//gerer parenthese et autre terme generaux + gerer ^apres: 2^2
$final .= $equa{$i}."*";
}
elseif(
is_numeric($equa{$i}) && $i > 0 && $equa{$i-1} != "^")
{
//gerer ^apres: 2^2
$final .= $equa{$i}."*";
}
elseif(
$equa{$i} == "^")
{
continue;
}
elseif(
is_numeric($equa{$i}) && $equa{$i-1} == "^")
{
continue;
}
else
{
if(
$equa{$i} == "x")
{
$final .= 1;
}
else
{
$final .= $equa{$i};
}
}
}
//
//Manage multiplication add in the previous string $final
//
$finalMul = "";
for(
$i = 0; $i < strlen($final); $i++)
{
if(
is_numeric($final{$i}) && $final{$i+1} == "*" && is_numeric($final{$i+2}))
{
$finalMul .= $final{$i}*$final{$i+2};
}
elseif(
$final{$i} == "*")
{
continue;
}
elseif(
is_numeric($final{$i}) && $final{$i+1} != "*" && $final{$i-1} == "*")
{
continue;
}
else
{
$finalMul .= $final{$i};
}
}
echo
"equa final: ".$finalMul;
}
?>

I know this is not optimal but i've done this quick :)
If you guys have any comment just email me.
I also want to do this fonction In C to add to phpCore maybe soon...
Patoff
up
5
daniel at g-loc dot org
18 years ago
If you're an aviator and needs to calculate windcorrection angles and groundspeed (e.g. during flightplanning) this can be very useful.

$windcorrection = rad2deg(asin((($windspeed * (sin(deg2rad($tt - ($winddirection-180))))/$tas))));
$groundspeed = $tas*cos(deg2rad($windcorrection)) + $windspeed*cos(deg2rad($tt-($winddirection-180)));

You can probably write these lines more beautiful, but they work!
up
3
lummox
16 years ago
Wouldn't the following function do the same but a lot easier than the one in the comment before?

function trimInteger($targetNumber,$newLength) {
return $targetNumber%pow(10,$newLength);
}
up
1
info at gavinvincent dot co dot uk
20 years ago
If you need to deal with polar co-ordinates for somereason you will need to convert to and from x,y for input and output in most situations: here are some functions to convert cartesian to polar and polar to cartesian
<?
//returns array of r, theta in the range of 0-2*pi (in radians)
function rect2polar($x,$y)
{
if(
is_numeric($x)&&is_numeric($y))
{
$r=sqrt(pow($x,2)+pow($y,2));
if(
$x==0)
{
if(
$y>0) $theta=pi()/2;
else
$theta=3*pi()/2;
}
else if(
$x<0) $theta=atan($y/$x)+pi();
else if(
$y<0) $theta=atan($y/$x)+2*pi();
else
$theta=atan($y/$x);
$polar=array("r"=>$r,"theta"=>$theta);
return
$polar;
}
else return
false;
}

//r must be in radians, returns array of x,y
function polar2rect($r,$theta)
{
if(
is_numeric($r)&&is_numeric($theta))
{
$x=$r*cos($theta);
$y=$r*sin($theta);
$rect=array("x"=>$x,"y"=>$y);
}
else
{
return
false;
}
}
?>
To Top