Calculates the hyperbolic cosine of a number.
What Is cosh() in PHP?
Calculates the hyperbolic cosine of a number.
Its syntax is:
cosh(float $num): float
Parameters:
$num— Accepted as float; required argument.
Return type: float. Input values are in the real-number domain; large values may overflow to INF. Do not confuse cosh() with cos().
Availability: Core PHP.
Example 1: Basic Usage
<?php
echo cosh(0);
Output:
1
Input values are in the real-number domain; large values may overflow to INF. Do not confuse cosh() with cos().
Example 2: A Different Input
<?php
echo round(cosh(1), 3);
Output:
1.543
Input values are in the real-number domain; large values may overflow to INF. Do not confuse cosh() with cos().
Practical Example: Applying It in a Program
<?php
$inputs = [-1, 0, 1]; foreach ($inputs as $input) { echo round(cosh($input), 4) . PHP_EOL; }
Output:
1.5431
1
1.5431
Input values are in the real-number domain; large values may overflow to INF. Do not confuse cosh() with cos().
Important Behavior and Edge Cases
- Key behavior: Input values are in the real-number domain; large values may overflow to INF. Do not confuse cosh() with cos().
- Environment: Core PHP.
Comparison With Related Functions
| Function | Purpose |
|---|---|
cosh() | Calculates the hyperbolic cosine of a number. |
cos() | cos() computes ordinary cosine of radians; cosh() computes hyperbolic cosine. |
Common Beginner Mistakes
| Mistake | Correct Approach |
|---|---|
| Ignoring this behavior: Input values are in the real-number domain; large values may overflow to INF | Input values are in the real-number domain; large values may overflow to INF. Do not confuse cosh() with cos(). |
Key Takeaways
- Calculates the hyperbolic cosine of a number.
- Input values are in the real-number domain; large values may overflow to INF. Do not confuse cosh() with cos().
- Core PHP.
Summary: Input values are in the real-number domain; large values may overflow to INF. Do not confuse cosh() with cos().