In Java, Math.sinh(x) returns the hyperbolic sine of x, defined as (ex - e-x) / 2. Despite the name, it has nothing to do with angles: x is not in radians or degrees. Math.sinh(0) is 0.0, and Math.sinh(1) is about 1.1752.
The function is zero at 0, odd (sinh(-x) = -sinh(x)), and grows very fast for larger |x|. It appears in physics and engineering, for example in the arc length of a hanging cable, and in some neural-network and signal-processing formulas. It was added in Java 5.
A static method of the java.lang.Math class, added in Java 5 (JDK 1.5). Call it on the class name, as in Math.sinh(...). No import is needed, because classes in java.lang are always visible.
Syntax
Pass any double. The hyperbolic sine comes back as a double.
Java
double a = Math.sinh(0.0); // 0.0
double b = Math.sinh(1.0); // about 1.1752
double c = Math.sinh(-1.0); // about -1.1752
double big = Math.sinh(1000.0); // Infinity
Call
What it does
Math.sinh(0.0)
Returns 0.0.
Math.sinh(-0.0)
Returns -0.0 (zero keeps its sign).
Math.sinh(1.0)
About 1.1752.
Math.sinh(1000.0)
Too large for a double: returns Infinity.
There is only a double version, and it takes any real number: unlike asin or acos it has no restricted domain. The inverse function (asinh) does not exist in java.lang.Math.
Library declarations
Java
// java.lang.Math
public static double sinh(double x)
Parameters
Parameter
Description
x
The number whose hyperbolic sine is wanted. Not an angle.
Return Value
Return Value
Description
double
The hyperbolic sine of x. The result is NaN if x is NaN, an infinity with the same sign as x if x is infinite (or too large), and a zero with the same sign if x is zero.
sinh(0.5) = 0.5211
formula = 0.5211
same within 1e-12? true
sinh matches tiny? true
formula matches tiny? false
How It Works
Same curve. At x = 0.5 both ways give 0.5211, and they differ by far less than 1e-12, so the method is just a more careful version of the textbook definition.
For tiny x, sinh is almost x. The true value of sinh(1e-10) is 1e-10 plus about 1.7E-31, which equals 1e-10 in a double, so the library result is within 1e-20 of tiny.
Subtraction loses digits.exp(1e-10) is stored as roughly 1.0000000001 with only 16 digits, so subtracting exp(-1e-10) leaves an error near 1E-17, far over 1e-20; the formula fails the test.
Example 3 — Arc Length of a Hanging Cable
A uniform cable that hangs under its own weight forms a catenary. The length of cable from its lowest point to a sideways distance x is a * sinh(x / a). Here the constant a is 50.
Java
import java.util.Locale;
public class MathSinhCable {
public static void main(String[] args) {
double a = 50.0;
int[] sideways = {10, 20, 30, 40};
for (int x : sideways) {
double length = a * Math.sinh(x / a);
System.out.println(String.format(Locale.US, "%2d m sideways -> %.2f m of cable", x, length));
}
}
}
Output
10 m sideways -> 10.07 m of cable
20 m sideways -> 20.54 m of cable
30 m sideways -> 31.83 m of cable
40 m sideways -> 44.41 m of cable
How It Works
Divide by the constant.x / a uses double division because a is a double: 10 / 50.0 is 0.2, and sinh(0.2) is about 0.2013.
Close to x when shallow. Near the lowest point the cable is almost flat, so 10 m sideways needs only 10.07 m of cable, barely more than the horizontal distance.
Costs grow quickly. By 40 m sideways the cable has to be 44.41 m long: sinh curves upward faster than a straight line.
Frequently Asked Questions
It returns the hyperbolic sine of a double, defined as (e^x - e^-x) / 2. For example, Math.sinh(1) is about 1.1752.
No. sin works with angles in radians and always returns a value from -1 to 1. sinh is a different, exponential-based function with no upper limit.
Java 5 (JDK 1.5). Older versions have to compute it from Math.exp.
Infinity (or -Infinity for very negative values) once the true result exceeds the largest double, which happens near 710. No exception is thrown.
No. Math.sinh is more accurate, especially for small x, where the hand-written subtraction cancels most of the significant digits.