JavaScript Math.atanh() Method



The JavaScript Math.atanh() method accepts a numeric value and calculates the hyperbolic arctangent (inverse hyperbolic tangent) of the number. The provided numeric value is expected to be in between -1 and 1, if the number is outside the range of [-1, 1], the result is NaN.

This method returns positive Infinity, if the argument is 1 and negative Infinity, if the argument is -1.

The formula for the inverse hyperbolic tangent function is −

atanh(x) = (1/2) * ln((1 + x) / (1 - x))

Here, "x" The input value for which we want to find the inverse hyperbolic tangent.

Syntax

Following is the syntax of JavaScript Math.atanh() method −

Math.atanh(x)

Parameters

This method accepts only one parameter. The same is described below −

  • x: A numeric value (between -1 and 1, inclusive) for which to calculate the hyperbolic arctangent.

Return value

This method returns the inverse hyperbolic tangent of the provided number.

Example 1

In the following example, we are demonstrating the usage of Math.atanh() method in JavaScript −

<html>
<body>
<script>
   const result1 = Math.atanh(0.5);
   const result2 = Math.atanh(-0.5);
   document.write(result1, "<br>", result2);
</script>
</body>
</html>

Output

If we execute the above program, this method returns the inverse hyperbolic tangent of 0.5 and -0.5.

Example 2

Here, we are retrieving the inverse hyperbolic tangent of "1" and "1" −

<html>
<body>
<script>
   const result1 = Math.atanh(1);
   const result2 = Math.atanh(-1);
   document.write(result1, "<br>", result2);
</script>
</body>
</html>

Output

This method returns Infinity and -Infinity after executing.

Example 3

If the provided number is less than -1 or greater than 1, this method returns "NaN" as result −

<html>
<body>
<script>
   const result1 = Math.atanh(2);
   const result2 = Math.atanh(-2);
   document.write(result1, "<br>", result2);
</script>
</body>
</html>

Output

As we can see in the output, it returns NaN as result.