tanh() in Java

tanh(): This method is available in the Math class of Java.

Syntax:

double java.lang.Math.tanh(double x)

This method takes one argument of type double as its parameter. This method returns the hyperbolic tangent of a double value.The hyperbolic tangent of x is defined to be(e^x - e^-x)/(e^x + e^-x),in other words, sinh(x)/cosh(x)

Note: The absolute value of the exact tanh is always less than 1.

Special cases:

1. If the argument is NaN, then the result is NaN.

2. If the argument is zero, then the result is a zero with the same sign as the argument.

3. If the argument is positive infinity, then the result is +1.0.

4. If the argument is negative infinity, then the result is -1.0.

Parameters: One parameter is required for this method.

x: The number whose hyperbolic tangent is to be returned.

Returns: The hyperbolic tangent of x.

For Example:

Math.tanh(0.5) = > It returns 0.46211715726000974

Approach

Java

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

        double x = 0.5;
        System.out.println(Math.tanh(x));

    }
}

Output:

0.46211715726000974

No comments:

Post a Comment