W3docs

cosh()

Today, we will discuss the cosh() function in PHP. This function is used to get the hyperbolic cosine of a number.

The PHP cosh() function returns the hyperbolic cosine of a number. Unlike the ordinary cos() function, which describes points on a circle, the hyperbolic cosine describes points on a hyperbola and shows up in physics (the shape of a hanging cable, a "catenary"), engineering, and numerical math. This page explains what cosh() computes, its syntax and return value, and the gotchas to watch for.

Syntax

cosh(float $num): float
  • $num — the value to process, interpreted in radians (not degrees).
  • Return value — a float: the hyperbolic cosine of $num.

Mathematically, the function evaluates:

cosh(x) = (e^x + e^-x) / 2

Because both e^x and e^-x are always positive, cosh(x) is always ≥ 1. Its minimum value, 1, occurs at x = 0, and it grows quickly for large positive or negative inputs. The function is even, meaning cosh(-x) === cosh(x).

Basic Example

php— editable, runs on the server

We store the input in a variable, pass it to cosh(), and print the result. PHP returns roughly 3.7621956910836 for an input of 2.

A Range of Values

The example below shows how cosh() behaves across several inputs, including the special case at 0 and the symmetry between positive and negative arguments:

<?php
echo cosh(0);   // 1 — the minimum value
echo "\n";
echo cosh(1);   // 1.5430806348152
echo "\n";
echo cosh(-1);  // 1.5430806348152 — same as cosh(1), the function is even
echo "\n";
echo cosh(2);   // 3.7621956910836
?>

Notice that cosh(-1) equals cosh(1): feeding in the negative of a number gives the same result.

Common Gotchas

  • Radians, not degrees. cosh() does not interpret its argument as degrees. If you have a value in degrees, convert it first with deg2rad().
  • Result is never below 1. If you ever get a value less than 1, you are not calling cosh() — you may be confusing it with cos(), whose result ranges from -1 to 1.
  • Large inputs overflow. For very large arguments, e^x exceeds the range of a float and PHP returns INF. For example, cosh(1000) is INF.

When to Use cosh()

Reach for cosh() when your math genuinely involves hyperbolic functions: modeling a hanging chain or cable (catenary curves), solving certain differential equations, signal processing, or relativity calculations. For everyday circular trigonometry use cos() instead.

  • cos() — the (circular) cosine of an angle.
  • sinh() — the hyperbolic sine.
  • tanh() — the hyperbolic tangent.
  • acosh() — the inverse hyperbolic cosine (undoes cosh()).
  • exp() — the exponential e^x, the building block of cosh().

Conclusion

The cosh() function returns the hyperbolic cosine of a number, computed as (e^x + e^-x) / 2. Remember that the input is in radians, the output is always at least 1, and the function is symmetric around zero. When you need ordinary angle-based trigonometry, use cos() instead.

Practice

Practice
What is the purpose of the cosh() function in PHP?
What is the purpose of the cosh() function in PHP?
Was this page helpful?