×

Java Math tanh() Method

The tanh() method of Java Math class returns the hyperbolic tangent of the specified double value.

Syntax:

public static double tanh(double x)

Parameters:

The parameter ‘x’ represents the number whose hyperbolic tangent is to be determined.

Return Value:

The tanh() method returns the hyperbolic tangent of the argument.

  • It returns zero with same sign as argument, if the argument passed is zero.
  • It returns +1.0, if the argument is positive infinity.
  • It returns -1.0, if the argument is negative infinity.
  • It returns NaN, if the argument is NaN.

Example 1:

public class JavaMathTanhExample1 {
    public static void main(String[] args) {
        double a=30;
        //return the hyperbolic tangent value for a
        System.out.println("Hyperbolic tangent value : "+Math.tanh(a));
    }
}

Output:

Hyperbolic tangent value : 1.0

Example 2:

public class JavaMathTanhExample2 {
    public static void main(String[] args) {
        //returns +1.0, if the argument is positive infinity
        double a=Double.POSITIVE_INFINITY;
        System.out.println("Hyperbolic tangent value for "+a+" = "+Math.tanh(a));
    }
}

Output:

Hyperbolic tangent value for Infinity = 1.0

Example 3:

public class JavaMathTanhExample3 {
    public static void main(String[] args) {
        //returns -1.0, if the argument is negative infinity
        double a=Double.NEGATIVE_INFINITY;
        System.out.println("Hyperbolic tangent value for "+a+" = "+Math.tanh(a));
    }
}

Output:

Hyperbolic tangent value for -Infinity = -1.0

Example 4:

public class JavaMathTanhExample4 {
    public static void main(String[] args) {
        //returns zero with same sign as argument, if the argument passed is zero
        double x = -0d;
        System.out.println("Hyperbolic tangent value for "+x+" = "+Math.tanh(x));
    }
}

Output:

Hyperbolic tangent value for -0.0 = -0.0

Example 5:

public class JavaMathTanhExample5 {
    public static void main(String[] args) {
        //return NaN, if the argument passed is NaN
        double x = Double.NaN;
        System.out.println("Hyperbolic tangent value for "+x+" = "+Math.tanh(x));
    }
}

Output:

Hyperbolic tangent value for NaN = NaN

Related Topics

Java Anon Proxy

The Java Anon Proxy (JAP), also known as JonDonym, is a proxy system designed to enable Web browsing with revocable (the use of or publication under a pseudonym, a false...

4 minutes read.

Java HashSet

HashSet implements the set interface. It uses the hash table to make the collection to store different data types. The hash set is the unordered collection of different data types....

6 minutes read.

Best Java IDE

Applications for desktop, workplace, smartphone, and the internet can be created using Java, one of the most popular programming languages. Java will undoubtedly be a popular programming language for so...

5 minutes read.

Ganesha’s Pattern in Java

This part teaches us how to use stars and other special characters to write Ganesha's Pattern in Java programming. Among the most challenging Java pattern applications to code. The Ganesha will be...

3 minutes read.

Java Extends keyword

Extends Extends is a keyword which is completely depended on the concept of the inheritance of the java programming language.To understand about of the keyword, we need to learn the concept...

3 minutes read.

Program to check whether a given character is present in a string or not

In this article, you will understand the logic to find out whether the given character is present in the string or not and find out the position of the specified...

3 minutes read.

Java Math signum() Method

The signum() method of Java Math class returns the signum function of the value. Syntax: public static double signum(double d)public static float signum (float d) Parameters: The parameter ‘d’ represents the floating-point value whose...

2 minutes read.

Alice and Bob Problem Java

Alice and Bob were two friends who liked to play games. Both together found a game, which has the description below. The game begins with an integer num, used to create...

2 minutes read.

Class definition in Java

The class definition in Java Java is an object-oriented programming language. We essentially know that programming languages based on object-oriented paradigms have classes and objects in their concepts as main, which...

6 minutes read.

JDBC Architecture

JDBC: JDBC stands for Java Database Connectivity. Sun Microsystems has a specification called JDBC. JDBC is a Java API (Application Programming Interface) that enables users to interact or communicate with...

4 minutes read.

How to check data type in Java

In this section, we will learn about the methodology to verify the data type in Java. There are mainly two methods in java called as getClass() and getName(). They are...

3 minutes read.

Java Buffer Reader

When a variable cannot change its value during run time is called a Static way of programming. In this programming, a variable is directly assigned to a value. Program: Import java.io.*; class  A {  ...

4 minutes read.

How to enable java in chrome

The Java module is huge for the Java Runtime Environment (JRE). It permits a program to work with the Java stage to run Java applets. Essentially, each of the undertakings connect...

3 minutes read.

Sleeping Barber Problem in Java

The barbershop in this issue has one barber, one barber chair, and N chairs for customers in the waiting area. We may demonstrate the issue by keeping with the original...

6 minutes read.

Even Odd Program in Java

Even Odd Program in Java The number that are completely divisible by 2 are even and the number that leaves remainder are odd numbers. For example, the numbers 2, 0, 4,...

5 minutes read.

Java Arrays

An array is an object that stores a collection of values. An array can store two types of collection data: objects and primitives. An array is a collection of values which...

2 minutes read.

Java DatagramSocket and Java DatagramPacket

Datagrams TCP/IP style networking specifies a serialized, predictable, and reliable stream of data in the form of a packet. Servers and clients communicate through a reliable channel, such as TCP socket, have a dedicated...

6 minutes read.

Tetranacci Number in Java

This article mainly describes tetranacci number identification and the Java Program for Tetranacci numbers. Tetranacci number Tetranacci numbers and Fibonacci numbers are related. The key contrast is that a Tetranacci number depends...

3 minutes read.

Reverse a String in Java

Reversing a string means that if we have a string called “what is your name”, the reversed format is “eman ruoy si tahw”. Reversing a string involves totally flipping the...

3 minutes read.

Shopping Bill in Java

Java Shopping Bill Here in this program, we are about to create a JAVA class called Products which will have some properties or attributes like prod_name (Product Name ), qty (quantity),...

4 minutes read.