Signature
sinh(float $num): floatPurpose
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)is0.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 isINF. Large negative inputs give-INF. sinh(NAN)isNAN, andsinh(INF)isINF.
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.
echo json_encode([round(sinh(0.5), 4), round(sinh(1), 6), round(sinh(-1), 6)]);[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 ==.
$x = 2.0;
$manual = (exp($x) - exp(-$x)) / 2;
echo json_encode(['close' => abs(sinh($x) - $manual) < 1.0E-12]);{"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.
$big = sinh(1000);
echo json_encode([is_infinite($big), $big > 0, is_infinite(sinh(-1000)), sinh(-1000) < 0]);[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 float0.0, not the integer0. If you need an int, convert deliberately. - Negative zero:
sinh(-0.0)keeps the negative sign in floating-point arithmetic. It compares equal to0.0, but may show up differently when dumped. - Precision:
echoandvar_dump()may show different numbers of digits because they use different ini settings. For stable output, round first or usejson_encode(). - Growth: the function grows very fast. For input
xabove 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
- 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. - Comparing floats with
==. Use a tolerance such asabs($a - $b) < 1.0E-12, or round both values. - Ignoring infinity. A user-supplied value of
1000silently producesINF, which then spreads through later calculations. Validate the range or test the result. - Passing non-numeric text. Strings like
"abc"cause aTypeError. Validate or cast input first. - Expecting an integer. The result is always a float, even for integer-looking input such as
0. - Confusing it with its inverse. To go from a hyperbolic sine value back to the original number, use
asinh(), notsinh()again.
Related functions
sin(): the ordinary (circular) sine.asinh(): the inverse hyperbolic sine, which undoessinh().cosh(): the hyperbolic cosine.tanh(): the hyperbolic tangent, equal tosinh($x) / cosh($x).exp(): the exponential function used in the definition.is_infinite()andis_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
echo json_encode([round(sinh(0.5), 4), round(sinh(1), 6), round(sinh(-1), 6)]);[0.5211,1.175201,-1.175201]
$x = 2.0;
$manual = (exp($x) - exp(-$x)) / 2;
echo json_encode(['close' => abs(sinh($x) - $manual) < 1.0E-12]);{"close":true}
$big = sinh(1000);
echo json_encode([is_infinite($big), $big > 0, is_infinite(sinh(-1000)), sinh(-1000) < 0]);[true,true,true,true]