PHP 8.4.1 Released!

Math Funzioni

Indice dei contenuti

  • abs — Valore assoluto
  • acos — Arco coseno
  • acosh — Inverso del coseno iperbolico
  • asin — Arco seno
  • asinh — Inverso del seno iperbolico
  • atan — Arco tangente
  • atan2 — Arco tangente di due variabili
  • atanh — Inverso della tangente iperbolica
  • base_convert — Converte un numero fra basi arbitrarie
  • bindec — Da binario a decimale
  • ceil — arrotonda le frazioni all'intero superiore
  • cos — Coseno
  • cosh — Coseno iperbolico
  • decbin — Da decimale a binario
  • dechex — Da decimale a esadecimale
  • decoct — Da decimale a ottale
  • deg2rad — Converte il numero dato in gradi nell'equivalente espresso in radianti
  • exp — Calcola l'esponente di e (la base logaritmica naturale o di Nepero)
  • expm1 — Restituisce exp(numero) - 1, computato in maniera tale da essere accurato anche se il valore del numero è vicino a zero
  • fdiv — Divides two numbers, according to IEEE 754
  • floor — Arrotonda le frazioni all'intero inferiore
  • fmod — Returns the floating point remainder (modulo) of the division of the arguments
  • hexdec — Da esadecimale a decimale
  • hypot — Restituisce sqrt(num1*num1 + num2*num2)
  • intdiv — Integer division
  • is_finite — Verifica se un numero dato è un numero finito
  • is_infinite — Verifica se un dato valore è infinito
  • is_nan — Verifica se un dato valore non sia un numero
  • log — Logaritmo naturale
  • log10 — Logaritmo base-10
  • log1p — Restituisce log(1 + numero), computato in maniera tale da essere accurato anche se il valore del numero è vicino a zero
  • max — Trova il valore massimo
  • min — Trova il valore minimo
  • octdec — Da ottale a decimale
  • pi — Restituisce il valore di pi
  • pow — Espressione esponenziale
  • rad2deg — Converte un numero in radianti nell'equivalente numero in gradi
  • round — Arrotonda un float
  • sin — Seno
  • sinh — Seno iperbolico
  • sqrt — Radice quadrata
  • tan — Tangente
  • tanh — Tangente iperbolica
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