AppDividend
Latest Code Tutorials

JavaScript Math acosh Function | Math.acosh() In Javascript

0

Javascript Math acosh() is an inbuilt function that is used to find the hyperbolic arccosine value of a given argument. The Math.acosh() function returns the hyperbolic arc-cosine of a number.

JavaScript Math acosh

If you want to find the hyperbolic arccosine value of a given argument in JavaScript, the Math.acosh() method is used. The acosh() method comes handy in programming contexts dealing with any trigonometric expressions. The acosh() is a static method of Math, and it can be used without creating an object.

Syntax

Math.acosh(x)

Parameter(s)

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

Return Value

It returns the hyperbolic arccosine value.

Polyfill

Math.acosh = Math.acosh || function(x) {
      return Math.log(x + Math.sqrt(x*x-1));
};

See the following figure.

 

JavaScript Math acosh

Note:

  • If the passed value is less than 1, the method returns NaN.

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:

JavaScript Math acosh() Code Example

The following example demonstrates the use of the Math.acosh() method.

// example1.js

var a = 1;
var b = 2;
var c = 3;
var d = 10;

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

Output

node example1
0
1.3169578969248166
1.7627471740390859
2.993222846126381

Example 2

The following example demonstrates the case where values less than 1 are passed.

// example2.js

var a = -1;
var b = 0;

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

Output

node example2
NaN
NaN

Example 3

The Math.acosh() 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.acosh(2+i));

Output

ReferenceError: i is not defined

Example 4

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

//example4.js

var a = 1;
var b = 2;
var c = 3;
var d = 10;

function myfunc(x){
	return Math.log(x + Math.sqrt(x*x-1));
}

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

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

Output

node example4
0
1.3169578969248166
1.7627471740390859
2.993222846126381
0
1.3169578969248166
1.7627471740390859
2.993222846126381

Conclusion

The hyperbolic arc-cosine is known with many names such as hyperbolic inverse cosine and acosh. It is inverse of the hyperbolic cosine function, i.e., The inverse hyperbolic cosine of any value say x is the value y for which the hyperbolic cosine of y is x.

See Also

JavaScript Math asin()

Javascript Math asinh()

JavaScript Math atan()

JavaScript Math atanh()

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.