
Use math.sinh(x) to compute the hyperbolic sine of a real number x. The function is part of Python’s standard math module and returns a floating-point result.
import math value = math.sinh(1.0) print(value) # 1.1752011936438014
For a value already stored in a variable, pass it directly; there is no need to convert it to radians. Hyperbolic functions take ordinary real numbers, not angles.
def sinh_value(x):
return math.sinh(x)
math.sinh expects a real-valued input. If the calculation is part of array processing, use a numerical library’s element-wise hyperbolic sine rather than calling this scalar function repeatedly.
TP-Link Deco X55 AX3000 WiFi 6 Mesh System, Deco X55(3-Pack) | Covers up to 6500 Sq.Ft. , Replaces Wireless Router and Extender, 3 Gigabit ports per unit, supports Ethernet Backhaul
(as of November 6, 2026 11:23 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Understanding the exponential definition
The defining identity is sinh(x) = (exp(x) - exp(-x)) / 2. It follows from the exponential definitions of the hyperbolic functions and makes the odd symmetry explicit: sinh(-x) = -sinh(x).
import math
def sinh_from_definition(x):
return (math.exp(x) - math.exp(-x)) / 2.0
This expression is useful for understanding the function, but math.sinh(x) is the appropriate implementation for general computation. The direct expression can overflow while evaluating an exponential, and for small x the two terms can be so close that their subtraction loses precision.
Near zero, the Taylor expansion begins sinh(x) = x + x**3 / 6 + x**5 / 120 + .... The leading term explains why sinh(x) is close to x for small inputs, while the odd powers preserve the sign symmetry.
Handling large and small inputs
For sufficiently large finite inputs, the mathematical result is outside the range of Python’s floating-point type. In that case, math.sinh raises OverflowError; it does not necessarily return infinity. The threshold is near 710.5 in magnitude for a typical double-precision float.
import math
try:
result = math.sinh(x)
except OverflowError:
result = math.copysign(math.inf, x)
Use this conversion only if infinity is an acceptable representation in the rest of the calculation. Otherwise, propagate the overflow or handle it at the point where the application can choose a meaningful fallback. Inputs that are already positive or negative infinity produce infinities with the same sign, while NaN produces NaN.
For small inputs, sinh(x) is approximately x. The higher-order terms become too small to affect the rounded floating-point result, so a tiny input may produce a result numerically identical to the input. That’s normal rounding behavior, not a reason to evaluate the exponential definition manually.
import math
for x in (1e-10, 1e-100, 1e-320):
y = math.sinh(x)
print(x, y, y == x)
At the very bottom of the floating-point range, results are limited by subnormal representation and may round to zero. If later computations divide by the result or depend on its relative error, test values from the actual operating range rather than assuming that every nonzero input yields a distinguishable nonzero result.
Testing numerical behavior and edge cases
Test the function against known values and mathematical properties, using tolerances rather than exact equality for ordinary floating-point results. Near zero, include an absolute tolerance because relative error alone is not meaningful when the expected value is close to zero.
import math
for x in (-3.0, -0.5, 0.0, 0.5, 3.0):
result = math.sinh(x)
assert math.isclose(
result,
-math.sinh(-x),
rel_tol=1e-14,
abs_tol=1e-15,
)
assert math.sinh(0.0) == 0.0
assert math.sinh(-0.0) == 0.0
Check special values separately. NaN must be tested with math.isnan, since NaN is unequal to itself. Infinities preserve their signs.
import math assert math.isnan(math.sinh(math.nan)) assert math.isinf(math.sinh(math.inf)) assert math.sinh(math.inf) > 0.0 assert math.sinh(-math.inf) < 0.0
Overflow is an exception case rather than a finite-result comparison. Choose an input comfortably beyond the representable range instead of testing the exact boundary, which can vary with the platform’s floating-point implementation.
import math
try:
math.sinh(1000.0)
except OverflowError:
pass
else:
raise AssertionError("expected overflow")
For a wider range of finite inputs, compare against the exponential identity only where both exponentials are safely representable. This checks the implementation without making the reference calculation itself overflow.
import math
for x in (-20.0, -2.0, -0.25, 0.25, 2.0, 20.0):
expected = (math.exp(x) - math.exp(-x)) / 2.0
actual = math.sinh(x)
assert math.isclose(actual, expected, rel_tol=1e-14, abs_tol=1e-15)
For the smallest inputs in an application’s domain, inspect the result directly rather than requiring it to differ from the input. Rounding can make math.sinh(x) equal to x, and subnormal values have reduced precision.
