AppDividend
Latest Code Tutorials

JavaScript Math.atanh() Function: Complete Guide

The atanh() method comes in handy in programming contexts dealing with trigonometric expressions. Since atanh() is a static method of Math, it can be used without creating an object.

JavaScript atanh()

The Math atanh() is a built-in JavaScript function used to get the hyperbolic arctangent of the number. The hyperbolic arctangent is known by many names, such as the hyperbolic inverse tangent and atanh.

It is an inverse of a hyperbolic tangent function, i.e., an inverse hyperbolic tangent of any value, say x is the value y for which a hyperbolic tangent of y is x.

To find the hyperbolic arctangent value of a given argument in JavaScript, use the Math.atanh() method.

Syntax

Math.atanh(x)

Parameter(s)

The variable x, whose hyperbolic arctangent value is to be determined.

Return Value

It returns the hyperbolic arctangent value.

Polyfill

Math.atanh = Math.atanh || function(x) {
      return Math.log( (1+x) / (1-x) ) /2 ;
};

See the following figure.

JavaScript atanh() Function

Note:

  • If the passed value is outside the range [-1,1], the method returns NaN.
  • If the parameter is 1, the method returns Infinity.

If the parameter is -1, the method returns -Infinity.

Compatibility

  • Google Chrome
  • Firefox
  • Opera
  • Safari
  • Android webview
  • Chrome for Android
  • Edge Mobile
  • Firefox for Android
  • Opera for Android
  • Safari on iOS
  • Samsung Internet
  • Node.js

Non-compatible with: Internet Explorer

JavaScript version: ECMAScript 6

Consider the following examples.

example1.js

See the following code.

// example1.js

var a = 0;
var b = 0.5;
var c = 0.1;
var d = 0.25;

console.log(Math.atanh(a));
console.log(Math.atanh(b));
console.log(Math.atanh(c));
console.log(Math.atanh(d));

Output

node example1
0
0.5493061443340548
0.10033534773107558
0.25541281188299536

example2.js

The following example demonstrates the case where values outside the range [-1,1] are passed.

// example2.js

var a = -1.5;
var b = 1.5;

console.log(Math.atanh(a));
console.log(Math.atanh(b));

Output

node example2
NaN
NaN

example3.js

The atanh() method cannot be used with complex arguments as only integer arguments are accepted.

// example3.js

// Complex values cannot be passed as arguments as follows
// since only integer arguments are accepted.

console.log(Math.atanh(2 + i));

Output

node example3
ReferenceError: i is not defined

example4.js

The following example demonstrates the use of polyfill for this method.

//example4.js

var a = 0;
var b = 0.5;
var c = 0.1;
var d = 0.25;

function myfunc(x) {
  return Math.log((1 + x) / (1 - x)) / 2;
}

console.log(Math.atanh(a));
console.log(Math.atanh(b));
console.log(Math.atanh(c));
console.log(Math.atanh(d));

console.log(myfunc(a));
console.log(myfunc(b));
console.log(myfunc(c));
console.log(myfunc(d));

Output

node example4
0
0.5493061443340548
0.10033534773107558
0.25541281188299536
0
0.5493061443340548
0.10033534773107562
0.25541281188299536

example5.js

The following example demonstrates the case where values 1 and -1 are passed.

// example5.js

var a = 1;
var b = -1;

console.log(Math.atanh(a));
console.log(Math.atanh(b));

Output

node example5
Infinity
-Infinity

Conclusion

The atanh() is an inverse of the hyperbolic tangent function. To find a hyperbolic arctangent value of a given argument in JavaScript, then use the Math.atanh() method.

See also

JavaScript Math atan2()

Javascript math cos()

Javascript math.cosh()

Javascript Math.abs()

Javascript Math.round()

Javascript Math.random()

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.