Mathematics7 min readExamples run on PHP 8.5.10

sinh()

Learn how PHP 8.4 sinh() computes the hyperbolic sine of a float, with its signature, return behavior, overflow cases, examples and common mistakes.

Signature

sinh(float $num): float
Available since PHP 4.1.07.48.08.18.28.38.48.5All versions →

Purpose

sinh() returns the hyperbolic sine of a number. It is the hyperbolic counterpart of sin(), but it has nothing to do with angles on a circle. Instead, it comes from the exponential function and is defined as (exp($num) - exp(-$num)) / 2.

You meet hyperbolic functions in scientific and engineering code. Typical places are catenary curves (a hanging cable), some physics formulas, signal processing and neural-network activation maths. In everyday web code you will use sinh() rarely, but it is a handy, exact building block when a formula already contains it.

Signature

The function is available in all modern PHP versions and has this same shape in PHP 8.4.

Parameters

  • $num: the value to process, as a float. There is no default, so the argument is required. Integers are widened to floats automatically. The value is not an angle in degrees or radians; it is simply the input to the exponential definition.

In the default (non-strict) mode, a numeric string such as "1.5" is converted to a number. A non-numeric string, an array or null for a non-nullable parameter is not accepted and results in a TypeError (or a deprecation for null in some contexts). With declare(strict_types=1); only int and float values are accepted.

Return value and failure cases

sinh() always returns a float. It does not return false and does not throw for out-of-range numbers. Instead, the usual floating-point rules apply:

  • sinh(0) is 0.0.
  • The result has the same sign as the input, and the function is odd: sinh(-$x) == -sinh($x).
  • For large positive inputs (roughly above 710) the underlying exp() overflows, and the result is INF. Large negative inputs give -INF.
  • sinh(NAN) is NAN, and sinh(INF) is INF.

Because nothing is thrown on overflow, check with is_infinite() or is_nan() when inputs come from outside your control.

Example 1: basic values

The results are floats with many decimals, so round them before displaying or comparing.

Example
<?php
echo json_encode([round(sinh(0.5), 4), round(sinh(1), 6), round(sinh(-1), 6)]);
Output
[0.5211,1.175201,-1.175201]

Notice the symmetry: the results for 1 and -1 differ only in sign.

Example 2: checking the definition

You can confirm that sinh() matches its formula. Floating-point results can differ in the last bits, so compare with a small tolerance instead of ==.

Example
<?php
$x = 2.0;
$manual = (exp($x) - exp(-$x)) / 2;
echo json_encode(['close' => abs(sinh($x) - $manual) < 1.0E-12]);
Output
{"close":true}

In practice, prefer sinh() over the manual formula. The library function is simpler to read and is designed to stay accurate, particularly for small inputs where subtracting two nearly equal exponentials can lose precision.

Example 3: overflow to infinity

Very large magnitudes do not raise errors. They produce infinite floats that you can detect.

Example
<?php
$big = sinh(1000);
echo json_encode([is_infinite($big), $big > 0, is_infinite(sinh(-1000)), sinh(-1000) < 0]);
Output
[true,true,true,true]

The four booleans tell you that both results are infinite and that their signs follow the sign of the input.

Edge cases

  • Zero: sinh(0) returns the float 0.0, not the integer 0. If you need an int, convert deliberately.
  • Negative zero: sinh(-0.0) keeps the negative sign in floating-point arithmetic. It compares equal to 0.0, but may show up differently when dumped.
  • Precision: echo and var_dump() may show different numbers of digits because they use different ini settings. For stable output, round first or use json_encode().
  • Growth: the function grows very fast. For input x above about 20, the result is already hundreds of millions.
  • Small inputs: for tiny x, sinh($x) is almost equal to $x, which is a useful sanity check.

Common mistakes

  1. Treating it like sin(). sinh() is not periodic and is not bounded between -1 and 1. Passing degrees or radians expecting a wave gives wrong results.
  2. Comparing floats with ==. Use a tolerance such as abs($a - $b) < 1.0E-12, or round both values.
  3. Ignoring infinity. A user-supplied value of 1000 silently produces INF, which then spreads through later calculations. Validate the range or test the result.
  4. Passing non-numeric text. Strings like "abc" cause a TypeError. Validate or cast input first.
  5. Expecting an integer. The result is always a float, even for integer-looking input such as 0.
  6. Confusing it with its inverse. To go from a hyperbolic sine value back to the original number, use asinh(), not sinh() again.
  • sin(): the ordinary (circular) sine.
  • asinh(): the inverse hyperbolic sine, which undoes sinh().
  • cosh(): the hyperbolic cosine.
  • tanh(): the hyperbolic tangent, equal to sinh($x) / cosh($x).
  • exp(): the exponential function used in the definition.
  • is_infinite() and is_nan(): for checking special float results.

Recap

sinh(float $num): float returns (exp($num) - exp(-$num)) / 2. It is odd, always returns a float, overflows to INF or -INF for large magnitudes instead of throwing, and returns NAN for NAN. Round or use a tolerance when comparing results, and use asinh() when you need to reverse the operation.

Tested examples

Basic hyperbolic sine values
<?php
echo json_encode([round(sinh(0.5), 4), round(sinh(1), 6), round(sinh(-1), 6)]);
Output
[0.5211,1.175201,-1.175201]
Comparing sinh() with its definition
<?php
$x = 2.0;
$manual = (exp($x) - exp(-$x)) / 2;
echo json_encode(['close' => abs(sinh($x) - $manual) < 1.0E-12]);
Output
{"close":true}
Overflow to infinity
<?php
$big = sinh(1000);
echo json_encode([is_infinite($big), $big > 0, is_infinite(sinh(-1000)), sinh(-1000) < 0]);
Output
[true,true,true,true]