PHP acos() Function
In this chapter you will learn:
- Definition for PHP acos() Function
- Syntax for PHP acos() Function
- Parameter for PHP acos() Function
- Return for PHP acos() Function
- Example - Calculate the arc cosine value
Definition
The acos()
function calculates the arc cosine value,
essentially reversing the operation of cos()
.
Syntax
PHP acos()
Function has the following format.
float acos ( float num )
Parameter
Parameter | Description |
---|---|
num | Required. A number in range -1 to 1 |
Return
acos(-1)
returns the value of Pi
.
The return value is in radians, you should use the
rad2deg()
to convert radians to degrees.
PHP acos()
function returns NAN if number is not in the range -1 to 1.
Example
Calculate the arc cosine value
<?php/*from j av a 2 s .co m*/
$acos1 = acos(0.4346);
print($acos1);
print "\n";
$acos2 = acos(cos(80));
print($acos2);
print "\n";
echo(acos(0.64) . "\n");
echo(acos(-0.4) . "\n");
echo(acos(0) . "\n");
echo(acos(-1) . "\n");
echo(acos(1) . "\n");
echo(acos(2));
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP acosh() Function
- Syntax for PHP acosh() Function
- Parameter for PHP acosh() Function
- Return for PHP acosh() Function
- Example - calculate the inverse hyperbolic cosine
Home » PHP Tutorial » PHP Math Functions