PHP 8.4.1 Released!

Fonctions Math

Sommaire

  • abs — Valeur absolue
  • acos — Arc cosinus
  • acosh — Arc cosinus hyperbolique
  • asin — Arc sinus
  • asinh — Arc sinus hyperbolique
  • atan — Arc tangente
  • atan2 — Arc tangent de deux variables
  • atanh — Arc tangente hyperbolique
  • base_convert — Convertit un nombre entre des bases arbitraires
  • bindec — Convertit de binaire en décimal
  • ceil — Arrondit au nombre supérieur
  • cos — Cosinus
  • cosh — Cosinus hyperbolique
  • decbin — Convertit de décimal en binaire
  • dechex — Convertit de décimal en hexadécimal
  • decoct — Convertit de décimal en octal
  • deg2rad — Convertit un nombre de degrés en radians
  • exp — Calcul l'exponentielle de e
  • expm1 — Retourne exp($num) - 1, calculé de manière précise même lorsque la valeur du nombre est proche de zéro
  • fdiv — Divise deux nombres, selon la norme IEEE 754
  • floor — Arrondit à l'entier inférieur
  • fmod — Retourne le reste de la division
  • fpow — Raise one number to the power of another, according to IEEE 754
  • hexdec — Convertit de hexadécimal en décimal
  • hypot — Calcul la longueur de l'hypoténuse d'un triangle à angle droit
  • intdiv — Division d'Entier
  • is_finite — Vérifie si un nombre flottant est fini
  • is_infinite — Vérifie si un nombre flottant est infini
  • is_nan — Vérifie si un nombre flottant est NAN
  • log — Logarithme naturel (népérien)
  • log10 — Logarithme en base 10
  • log1p — Calcule précisément log(1 + nombre)
  • max — La plus grande valeur
  • min — La plus petite valeur
  • octdec — Conversion d'octal en décimal
  • pi — Retourne la valeur de pi
  • pow — Expression exponentielle
  • rad2deg — Conversion de radians en degrés
  • round — Arrondit un nombre à virgule flottante
  • sin — Sinus
  • sinh — Sinus hyperbolique
  • sqrt — Racine carrée
  • tan — Tangente
  • tanh — Tangente hyperbolique
add a note

User Contributed Notes 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