Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
PHP acosh() Function
The acosh() function returns the inverse hyperbolic cosine of a given number. The inverse hyperbolic cosine is defined mathematically as:
acosh(x) = log(x + sqrt(x² - 1))
This function accepts values greater than or equal to 1 and returns a float value representing the hyperbolic angle in radians.
Syntax
acosh(float $arg): float
Parameters
| Parameter | Description |
|---|---|
| arg | A floating point value ? 1 whose inverse hyperbolic cosine is to be calculated |
Return Value
Returns the inverse hyperbolic cosine of arg as a float, or NAN if arg is less than 1.
Example 1: Basic Usage
Calculate acosh() for different values and verify with the mathematical formula ?
<?php
$arg = M_PI_2; // ?/2 ? 1.5708
$val = acosh($arg);
$formula_result = log($arg + sqrt(pow($arg, 2) - 1));
echo "acosh(" . $arg . ") = " . $val . "<br>";
echo "Formula result = " . $formula_result . "<br>";
echo "Match: " . ($val == $formula_result ? "Yes" : "No");
?>
acosh(1.5707963267949) = 1.0232274785476 Formula result = 1.0232274785476 Match: Yes
Example 2: Different Values
Testing acosh() with various input values ?
<?php
$values = [1, 2, M_PI, 5.5];
foreach ($values as $val) {
$result = acosh($val);
echo "acosh($val) = " . round($result, 6) . "<br>";
}
?>
acosh(1) = 0 acosh(2) = 1.316958 acosh(3.1415926535898) = 1.811526 acosh(5.5) = 2.40441
Example 3: Error Handling
Demonstrating behavior with invalid input values ?
<?php
$invalid_values = [0.5, 0, -1];
foreach ($invalid_values as $val) {
$result = acosh($val);
if (is_nan($result)) {
echo "acosh($val) = NAN (invalid input)<br>";
} else {
echo "acosh($val) = $result<br>";
}
}
?>
acosh(0.5) = NAN (invalid input) acosh(0) = NAN (invalid input) acosh(-1) = NAN (invalid input)
Conclusion
The acosh() function calculates inverse hyperbolic cosine for values ? 1, returning NAN for invalid inputs. It's useful in mathematical calculations involving hyperbolic functions and geometric computations.
