Open In App

Java Math sinh() Method

Last Updated : 12 May, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In Java, the sinh() method is a part of the java.util.Math class. This method is used to calculate the hyperbolic sine of a given value. In this article, we are going to discuss how this method works for regular values and for special cases such as infinity and NaN.

Mathematical Definition:

The hyperbolic sine of any value a is defined as:

(ea - e-a)/2

where, e is Euler's number and a is the value for which we are going to calculate the hyperbolic sine.

Special Cases:

The sinh() method handles various cases, which are listed below:

  • If the argument is NaN, then the result is NaN.
  • If the argument is infinity then the result will also be infinity with the same sign as the argument.
  • If the argument is zero, then the result is a zero with the same sign as the argument.

These special cases make sure that the Math.sinh() methods work correctly.

Syntax of sinh() Method

public static double sinh(double a)

  • Parameter: This method takes a single parameter a, of type double, for which the hyperbolic sine is to be calculated.
  • Return Type: This method returns the hyperbolic sine value of the argument.

Now, we are going to discuss some examples for better understanding.

Examples of Java Math sinh() Method

Example 1: In this example, we will see the basic usage of sinh() method with regular values.

Java
// Java program to demonstrate working
// Math.sinh() method
import java.lang.Math;

class Geeks {

    public static void main(String args[])
    {

        double a = 3.5;

        System.out.println(Math.sinh(a));

        a = 90.328;

        System.out.println(Math.sinh(a));
    }
}

Output
16.542627287634996
8.470751974588509E38

Explanation: Here, we are calculating the hyperbolic sinh of a given number. First we are calculating the hyperbolic sinh of 3.5 and after that we are calculating the sinh of 90.328 and then we are printing the result.

Example 2: In this example, we will see how sinh() method handles NaN and Infinity.

Java
// Java program to demonstrate working
// Math.sinh() method infinity case
import java.lang.Math;

public class Geeks {
    
    public static void main(String[] args) {
        
        double p = Double.POSITIVE_INFINITY;
        double n = Double.NEGATIVE_INFINITY;
        double nan = Double.NaN;
        double res;

        // here argument is negative infinity
        res = Math.sinh(n);
        System.out.println(res);

        // here argument is positive infinity
        res = Math.sinh(p);
        System.out.println(res);

        // here argument is NaN
        res = Math.sinh(nan);
        System.out.println(res);
    }
}

Output
-Infinity
Infinity
NaN

Explanation: Here, we are handling the special cases like NaN and infinity values. For n= Double.NEGATIVE_INFINITY, the result is -Infinity and for p=Double.POSITIVE_INFINITY, the result is Infinity and for nan=Double.NaN the result is NaN.


Practice Tags :

Similar Reads