Java Math sinh()

The Java Math sinh() method returns the hyperbolic sine of the specified value.

The hyperbolic sine is equivalent to (ex - e-x)/2, where e is Euler's number.

The syntax of the sinh() method is:

Math.sinh(double value)

Here, sinh() is a static method. Hence, we are accessing the method using the class name, Math.


sinh() Parameters

The sinh() method takes a single parameter.

  • value - angle whose hyperbolic function is to be determined

Note: The value is generally used in radians.


sinh() Return Values

  • returns the hyperbolic sine of value
  • returns NaN if the argument value is NaN

Note: If the argument is zero or infinity, then the method returns the same value zero or infinity with the same sign as in argument.


Example 1: Java Math sinh()

class Main {
  public static void main(String[] args) {

    // create a double variable
    double value1 = 45.0;
    double value2 = 60.0;
    double value3 = 30.0;

    // convert into radians
    value1 = Math.toRadians(value1);
    value2 = Math.toRadians(value2);
    value3 = Math.toRadians(value3);

    // compute the hyperbolic sine
    System.out.println(Math.sinh(value1));  // 0.8686709614860095
    System.out.println(Math.sinh(value2));  // 1.2493670505239751
    System.out.println(Math.sinh(value3));  // 0.5478534738880397
  }
}

In the above example, notice the expression,

Math.sinh(value1)

Here, we have directly used the class name to call the method. It is because sinh() is a static method.

Note: We have used the Java Math.toRadians() method to convert all the values into radians.


Example 2: sinh() Returns NaN, Zero, and Infinite

class Main {
  public static void main(String[] args) {

    // create a double variable
    double value1 = 0.0;
    double value2 = Double.POSITIVE_INFINITY;
    double value3 = Double.NEGATIVE_INFINITY;
    double value4 = Math.sqrt(-5);

    // convert into radians
    value1 = Math.toRadians(value1);
    value2 = Math.toRadians(value2);
    value3 = Math.toRadians(value3);
    value4 = Math.toRadians(value4);

    // compute the hyperbolic sine
    System.out.println(Math.sinh(value1));  // 0.0
    System.out.println(Math.sinh(value2));  // Infinity
    System.out.println(Math.sinh(value3));  // -Infinity
    System.out.println(Math.sinh(value4));  // NaN
  }
}

Here,

  • Double.POSITIVE_INFINITY - implements positive infinity in Java
  • Double.NEGATIVE_INFINITY - implements negative infinity in Java
  • Math.sqrt(-5) - square root of a negative number is not a number

Note:We have used the Java Math.sqrt() method to calculate the square root of a number.


Recommended Tutorials