PHP cosh() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Math

Definition

The PHP cosh() function returns the hyperbolic cosine of a number.

The result is always 1 or bigger, and it is the same for a number and its negative, so cosh(2) equals cosh(-2).

Syntax

Call cosh() with the values you need. Start with this line.

PHP
$result = cosh($num);
CallWhat it does
cosh(0)Returns 1.
cosh(1)Returns about 1.5431.
cosh(-1)Returns about 1.5431, the same as cosh(1).

cosh() is not the same as cos(). It uses exponentials, not angles on a circle.

Library declarations
PHP
cosh(float $num): float

Parameters

ParameterDescription
numRequired. The number to work on. Any real number is allowed.

Return Value

Return ValueDescription
floatThe hyperbolic cosine of $num, which is always 1 or greater. Returns INF for very large inputs.

PHP Examples

Example 1 — Basic cosh() usage

This example prints the hyperbolic cosine of several numbers.

PHP
<?php
echo cosh(0) . PHP_EOL;
echo round(cosh(1), 4) . PHP_EOL;
echo round(cosh(2), 4) . PHP_EOL;
echo round(cosh(3), 4) . PHP_EOL;

How It Works

  1. cosh(0) is exactly 1, which is the smallest possible value.
  2. cosh(1) is about 1.5431.
  3. cosh(2) is about 3.7622, so the values climb quickly.
  4. cosh(3) is already above 10, which shows the very fast growth.

Example 2 — Symmetry and overflow

cosh() gives the same answer for x and -x. It also returns INF when the number is too big to store.

PHP
<?php
echo round(cosh(1), 4) . PHP_EOL;
echo round(cosh(-1), 4) . PHP_EOL;
var_dump(cosh(1000));

How It Works

  1. cosh(1) returns 1.5431.
  2. cosh(-1) returns the same 1.5431 because cosh() is symmetric.
  3. cosh(1000) would be a huge number with more than 400 digits.
  4. A float cannot store it, so PHP returns float(INF).

Example 3 — Hanging cable shape

The curve of a hanging cable is called a catenary and uses cosh(). Here we calculate its height with the formula a * cosh(x / a).

PHP
<?php
$a = 2;
$x = 2;

$height = $a * cosh($x / $a);

echo "Height at x = $x: " . round($height, 4) . PHP_EOL;

How It Works

  1. We set the shape value $a to 2 and the horizontal position $x to 2.
  2. $x / $a is 1, so we need cosh(1), which is about 1.5431.
  3. Multiplying by $a gives 2 * 1.5431 = 3.0862.
  4. round() limits the output to 4 decimals.

Frequently Asked Questions

cosh() returns the hyperbolic cosine of a number. It is calculated as (e^x + e^-x) / 2.
The smallest value is 1, which happens at cosh(0). Every other input gives a bigger number.
cos() works with angles on a circle and returns -1 to 1. cosh() works with exponentials and returns 1 or more.
When the result is too large for a float, which starts at inputs above roughly 710.
Use acosh(). It takes a value of 1 or more and returns the positive number whose cosh() is that value.

Next: decbin()

decbin() function converts a decimal (normal) whole number into a binary string made of 0s.

decbin() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful