acosh()
方法计算给定数字的双曲反正余弦值并返回它。
示例
// hyperbolic arc-cosine of 5
let number = Math.acosh(5);
console.log(number);
// Output: 2.2924316695611777
acosh() 语法
Math.acosh()
方法的语法是:
Math.acosh(number)
在这里,acosh()
是一个静态方法。因此,我们使用类名 Math
来访问该方法。
acosh() 参数
acosh()
方法接受一个参数:
number
- 要计算其双曲反正余弦值的正数。
acosh() 返回值
acosh()
方法返回:
- 给定正数参数
number
的双曲反正余弦值。 - 对于零、负数和非数字参数,返回 NaN (Not a Number)。
示例 1:JavaScript Math.acosh() 用于正数
// hyperbolic arc-cosine of an integer
let result1 = Math.acosh(32);
console.log(result1);
// hyperbolic arc-cosine of a floating-point number
let result2 = Math.acosh(4.5);
console.log(result2);
// Output:
// 4.158638853279167
// 2.1846437916051085
在上面的示例中,我们对以下值使用了 Math.acosh()
方法:
32
(整数值) - 结果为 4.1586388532791674.5
(浮点数值) - 结果为 2.1846437916051085
示例 2:Math.acosh() 用于零和负数
// hyperbolic arc-cosine of a negative number
let result1 = Math.acosh(-12.5);
console.log(result1);
// Output: NaN
// hyperbolic arc-cosine of zero
let result2 = Math.acosh(0);
console.log(result2);
// Output: NaN
在上面的示例中,我们对负数和零使用了 acosh()
方法。对于这两个值,我们都得到了 NaN 作为输出。
注意:我们只能对正数使用 acosh()
方法。
示例 3:Math.acosh() 用于非数字参数
let string ="Harry";
// acosh() with a string argument
let value = Math.acosh(string);
console.log(value);
// Output: NaN
在上面的示例中,我们对字符串 "Harry"
使用了 acosh()
方法。因此,我们得到了 NaN 作为输出。
另请阅读