×

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 Byte intValue() method

The intValue()  method of Java Integer class returns an int value for this Integer.  Syntax public int intValue()  Parameters NA  Specified by This method is specified by intValue in class Number  Return Value This method returns the numeric...

1 minute read.

Types of Assignment Operators in Java

In this tutorial, we are going to study assignment operators and their types in Java language. Before proceeding to the types, let us know the term ‘assignment operator’.  The assignment...

5 minutes read.

Computing Digit Sum of all Numbers from 1 to n in Java

In this tutorial, we will discuss various methods to compute the sum of digits of all numbers beginning from 1 to n through a Java program. We will achieve it through...

7 minutes read.

Java String length() method

Java String length() method returns length of the characters in a String. Syntax: public int length() Returns It returns length of the characters Java String length() method example 1          public class JavaStringLengthEx1  ...

1 minute read.

String Matches in Java

Firstly we have to know something about String? Strings are a bundle of different characters that are normally used in Java programming language. Strings are regarded as objects in the Java...

3 minutes read.

How to compare characters in Java

In this tutorial, we will learn about how to compare characters in Java. To compare characters in Java, we will learn about what is a character in Java Char The character is...

4 minutes read.

Radix Sort in Java

Radix Sort in Java Radix sort in Java uses the digits of the numbers given in the sorted array to sort the numbers. The radix sort uses the place value of...

5 minutes read.

Java Integer lowestOneBit()

The lowestOneBit () method of Java Integer class returns an int value with at most a single one-bit, in the position of the lowest-order one-bit in the specified int value.  Syntax public...

2 minutes read.

Java Image

For all other classes used for representing graphical images, Java's Image class serves as an abstract superclass. For images in Java, a specific form of object known as a BufferedImage...

4 minutes read.

Java Math ceil() Method

The ceil() method of Math class returns the smallest double value which is closest to negative infinity and is greater than or equal to the argument. Syntax: public static double ceil(double a) Parameters: The...

2 minutes read.

Spliterator in Java 8

In this tutorial, we will understand the meaning of spliterator in java 8. It is just like any other iterator available in java used to traverse the elements of either...

4 minutes read.

Access Modifier in Java

The access modifiers in java are used to change the accessibility and scope of a method, constructor, class, and fields. If you are aware of C++ language, when we declare any member...

2 minutes read.

How to Calculate Time Difference Between Two Dates in Java?

Date is being used extensively in Java to calculate date differences. While constructing an application, the date of joining an organisation, admission date, appointment date, and others might be included....

4 minutes read.

Types of Statements in Java

In natural languages, statements and sentences are roughly equivalent. In general, statements are similar to valid English sentences. We will talk about a statement in Java and the different kinds...

11 minutes read.

Compare Two Times in Java

Definition The compareTo() function of the LocalTime class is used to compare times. The class's compareTo() method compares two LocalTime objects. Here we have two objects that have to be compared: the...

4 minutes read.

Access specifiers in Java

What are access specifiers in Java? Access specifiers in Java are used to determine whether other classes can use a particular field or invoke a particular method. Access specifiers mainly specify...

7 minutes read.

MessageDigest in Java

The compression of mathematical numbers is accomplished using hash functions. In almost every data security application, hash functions are employed. The hashing, often called has values, returns a value called...

3 minutes read.

Virtual Function in Java

In the Operated Oriented Programming language, a virtual function or virtual method is a collection of functions that overrides the functionality of a function in an inheriting class with the same...

4 minutes read.

How to Convert long to String in Java

How to Convert long to String in java It is used if we have to display a long number in the text field because everything is displayed as a String. A...

3 minutes read.

Zigzag Array in Java

In this tutorial, we discuss, what is zigzag array and its example. Even we will create the java program. In this program, we convert the simple array into a zigzag...

4 minutes read.