JavaScript Math.acosh: Complete Guide
The acosh() method comes in 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.
JavaScript Math.acosh()
To find the hyperbolic arccosine value of a given argument in JavaScript, use the Math.acosh() method. Javascript 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.
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.
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 the 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.