sinh
Returns the hyperbolic sine of a number, equal to (exp(x) - exp(-x)) / 2.
sinh(float $num): float- Added in PHP 4.1.0
Parameters
| Parameter | Type | Description |
|---|---|---|
$num | float | The argument to process. Unlike sin(), this is not an angle. |
Return value
floatThe hyperbolic sine of num.
Errors
Throws a TypeError if num is not a number and cannot be converted to a float. Very large inputs overflow to INF rather than throwing.
sinh() is the hyperbolic sine, defined as (exp($x) - exp(-$x)) / 2. Despite the name it has nothing to do with angles — it is not periodic and it is not bounded. It is an odd function that passes through the origin and then grows roughly like exp($x) / 2.
When you actually need it
Hyperbolic functions turn up wherever a hanging cable, a suspension bridge chain or a power line is modelled: the catenary curve is $a * cosh($x / $a), and its slope is a sinh(). They also appear in special relativity as rapidity, in some statistical link functions, and in the asinh() log-like transform used to compress data that includes zero and negative values — something log() cannot do.
Overflow is quiet
Because it grows exponentially, sinh() reaches PHP_FLOAT_MAX around an input of 710. Past that it returns INF with no warning. Guard your input range if it comes from user data.
Getting back
asinh() is the exact inverse and is defined for every real number, unlike acosh() which needs an argument of at least 1.
Example
When to use it
- Compute the slope of a catenary curve for a hanging cable or arch
- Apply an asinh-style variance-stabilising transform to data containing zeros and negatives
- Convert rapidity to velocity in a relativistic physics calculation
Frequently asked questions
What is the difference between sin() and sinh()?
sin() is the circular sine: periodic and permanently bounded between -1 and 1. sinh() is the hyperbolic sine, (exp(x) - exp(-x)) / 2, which is not periodic and grows exponentially without limit.
Does sinh() take radians?
No. sinh() takes a plain number, not an angle, so deg2rad() is irrelevant here. Passing degrees or radians is meaningless - the argument is just a real value.
How do I reverse sinh()?
Use asinh(), the inverse hyperbolic sine. It accepts any real number, so asinh(sinh($x)) returns $x for every input within float precision.
More examples
Growth compared with sin()
sin() stays inside -1 to 1 forever, while sinh() climbs past 11000 by x = 10. That unbounded exponential growth is the practical difference between the circular and hyperbolic families.
<?php
printf("%-4s %-22s %s\n", 'x', 'sinh(x)', 'sin(x)');
foreach ([0, 1, 2, 5, 10] as $x) {
printf("%-4d %-22.6f %.6f\n", $x, sinh($x), sin($x));
}Slope of a catenary
A hanging cable follows a * cosh(x / a); differentiating gives sinh(x / a) as the slope. The slope is zero at the lowest point and symmetric in sign on either side.
<?php
$a = 20.0; // cable parameter
foreach ([-40, -20, 0, 20, 40] as $x) {
$height = $a * cosh($x / $a);
$slope = sinh($x / $a);
printf("x=%4d height=%7.3f slope=%7.4f\n", $x, $height, $slope);
}Guarding against overflow
Around x = 710 the result exceeds PHP_FLOAT_MAX and sinh() returns INF without any warning or error. Testing with is_infinite() is the only way to catch it before the value poisons later arithmetic.
<?php
foreach ([700, 710, 720] as $x) {
$v = sinh($x);
printf("sinh(%d) = %-24s infinite? %s\n",
$x, $v, is_infinite($v) ? 'yes' : 'no');
}
Discussion