Math.tan()
Math.tan() 静态方法返回以弧度表示的数字的正切值。
¥The Math.tan() static method returns the tangent of a number in radians.
Try it
语法
参数
返回值
¥Return value
x 的正切。如果 x 是 Infinity、-Infinity 或 NaN,则返回 NaN。
¥The tangent of x. If x is Infinity, -Infinity, or NaN, returns NaN.
注意:由于浮点精度,不可能获得精确的值 π/2,因此如果不是
NaN,结果总是有限的。¥Note: Due to floating point precision, it's not possible to obtain the exact value π/2, so the result is always finite if not
NaN.
描述
示例
使用 Math.tan()
Math.tan() 和 π/2
将 Math.tan() 与度值结合使用
¥Using Math.tan() with a degree value
由于 Math.tan() 函数接受弧度,但使用度数通常更容易,因此以下函数接受以度为单位的值,将其转换为弧度并返回正切值。
¥Because the Math.tan() function accepts radians, but it is often easier to work with degrees, the following function accepts a value in degrees, converts it to radians and returns the tangent.
js
function getTanDeg(deg) {
const rad = (deg * Math.PI) / 180;
return Math.tan(rad);
}
规范
| Specification |
|---|
| ECMAScript Language Specification # sec-math.tan |
浏览器兼容性
BCD tables only load in the browser