Saturday, November 22, 2025
HomeLanguagesJavaStrictMath tanh() Method in Java

StrictMath tanh() Method in Java

The java.lang.StrictMath.tanh() method is used to return the hyperbolic tan of a double value passed as parameter to the function. The hyperbolic tan of x is defined by the formula $(e^x-e^{-x})/(e^x+e^{-x})$ where e denotes the Euler’s number.

Syntax:

public static double tanh(double x)

Parameters: The function accepts a single parameter x of double type and refers to the value whose hyperbolic tangent equivalence is to be returned.

Return Values: This method returns a double value which is the hyperbolic tangent of x. The absolute value of exact tanh never exceeds 1. The following cases are considered:

  • The function returns NaN if the argument is NaN.
  • The function returns +1.0 and -1.0 for positive infinity and negative infinity respectively.
  • The function returns zero with the same sign as the argument if the argument is zero

Examples:

Input: 0.7853981633974483
Output: 0.6557942026326724

Input: 4.0
Output: 0.999329299739067

Below programs illustrate the java.lang.StrictMath.tanh() method:
Program 1:




// Java Program to demonstrate tanh()
import java.io.*;
import java.math.*;
import java.lang.*;
  
class GFG {
    public static void main(String[] args)
    {
  
        double x = (45 * Math.PI) / 180;
  
        // Display the hyperbolic tan of the value
        System.out.println("Hyperbolic tan of "
                + x + " = " + StrictMath.tanh(x));
    }
}


Output:

Hyperbolic tan of 0.7853981633974483 = 0.6557942026326724

Program 2:




// Java Program to illustrate 
// StrictMath.tanh() function 
  
import java.io.*;
import java.math.*;
import java.lang.*;
  
class GFG {
    public static void main(String[] args)
    {
  
        double x1 = 180 / (0.0), x2 = 0;
  
        // Display the hyperbolic tan of the values
        System.out.println("Hyperbolic tan of "
               + x1 + " = " + StrictMath.tanh(x1));
        System.out.println("Hyperbolic tan of "
               + x2 + " = " + StrictMath.tanh(x2));
    }
}


Output:

Hyperbolic tan of Infinity = 1.0
Hyperbolic tan of 0.0 = 0.0

Reference: https://docs.oracle.com/javase/8/docs/api/java/lang/StrictMath.html#tanh()

RELATED ARTICLES

Most Popular

Dominic
32407 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6784 POSTS0 COMMENTS
Nicole Veronica
11931 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11999 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7168 POSTS0 COMMENTS
Thapelo Manthata
6863 POSTS0 COMMENTS
Umr Jansen
6848 POSTS0 COMMENTS