PHP 8.5.0 Beta 3 available for testing

Math Functions

Table of Contents

  • abs β€” Absolute value
  • acos β€” Arc cosine
  • acosh β€” Inverse hyperbolic cosine
  • asin β€” Arc sine
  • asinh β€” Inverse hyperbolic sine
  • atan β€” Arc tangent
  • atan2 β€” Arc tangent of two variables
  • atanh β€” Inverse hyperbolic tangent
  • base_convert β€” Convert a number between arbitrary bases
  • bindec β€” Binary to decimal
  • ceil β€” Round fractions up
  • cos β€” Cosine
  • cosh β€” Hyperbolic cosine
  • decbin β€” Decimal to binary
  • dechex β€” Decimal to hexadecimal
  • decoct β€” Decimal to octal
  • deg2rad β€” Converts the number in degrees to the radian equivalent
  • exp β€” Calculates the exponent of e
  • expm1 β€” Returns exp($num) - 1, computed in a way that is accurate even when the value of number is close to zero
  • fdiv β€” Divides two numbers, according to IEEE 754
  • floor β€” Round fractions down
  • fmod β€” Returns the floating point remainder (modulo) of the division of the arguments
  • fpow β€” Raise one number to the power of another, according to IEEE 754
  • hexdec β€” Hexadecimal to decimal
  • hypot β€” Calculate the length of the hypotenuse of a right-angle triangle
  • intdiv β€” Integer division
  • is_finite β€” Checks whether a float is finite
  • is_infinite β€” Checks whether a float is infinite
  • is_nan β€” Checks whether a float is NAN
  • log β€” Natural logarithm
  • log10 β€” Base-10 logarithm
  • log1p β€” Returns log(1 + number), computed in a way that is accurate even when the value of number is close to zero
  • max β€” Find highest value
  • min β€” Find lowest value
  • octdec β€” Octal to decimal
  • pi β€” Get value of pi
  • pow β€” Exponential expression
  • rad2deg β€” Converts the radian number to the equivalent number in degrees
  • round β€” Rounds a float
  • sin β€” Sine
  • sinh β€” Hyperbolic sine
  • sqrt β€” Square root
  • tan β€” Tangent
  • tanh β€” Hyperbolic tangent
οΌ‹add a note

User Contributed Notes 2 notes

up
12
pat.mat AT sympatico DOT com ΒΆ
21 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
2
daniel at g-loc dot org ΒΆ
19 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!
To Top