BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Java Math.tanh() Method

Last Updated: October 18, 2022 by Chaitanya Singh | Filed Under: java

Java Math.tanh() method returns hyperbolic tangent of the given value. This method accepts double type value as an argument and returns the hyperbolic tangent of this value as a result. Hyperbolic tangent of a value x is defined as (ex – e-x)/(ex + e-x), where e is the Euler’s number whose value is 2.718281828459045.

public class JavaExample
{
  public static void main(String[] args)
  {
    double x = 30;
    System.out.println(Math.tanh(x));
  }
}

Output:

1.0

Syntax of Math.tanh() method

Math.tanh(90); //returns 1.0

tanh() Description

public static double tanh(double x): Returns the hyperbolic tangent of the given value (argument) x.

tanh() Parameters

  • x: A double value whose hyperbolic tangent is to be determined.

tanh() Return Value

  • Returns hyperbolic tangent of argument x.
  • If the argument x is NaN (Not a number), then it returns NaN.
  • If the argument x is zero, then it returns the zero with the same sign.
  • If the argument x is positive infinity, then it returns +1.0.
  • If the argument x is negative infinity, then it returns -1.0.

Example 1

public class JavaExample
{
  public static void main(String[] args)
  {
    double x1 = 1.0;
    double x2 = 0;
    double x3 = -1.0;
    //hyperbolic tangent of different double values.
    System.out.println(Math.tanh(x1));
    System.out.println(Math.tanh(x2));
    System.out.println(Math.tanh(x3));
  }
}

Output: