Javascript sin 函数问题
我遇到了 Math.sin
的问题。我认为它会输出给定整数的正弦。所以我尝试了 Math.sin(30)
,我的输出是 -0.9880316240928618
然后我用计算器检查了一下,结果是 0.5。
I have a problem with Math.sin
. I thought it would output the sinus of the given integer. So I tried Math.sin(30)
and my output was -0.9880316240928618
and then I checked with my calculator and it was 0.5.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
假定参数以弧度为单位,而不是度数。
尝试
下面的评论指出,预先计算比率 π/180 是一个好主意。人们可以向
Math.sin
添加一个以这种方式处理度数的同伴:(有些人不喜欢扩展内置对象,但由于人们不实例化 Math 实例 - 至少,我不要——这看起来并不是非常令人反感。)
Parameters are assumed to be in radians, not degrees.
Try
A comment below notes that pre-computing the ratio π/180 is a good idea. One could add a companion to
Math.sin
that works on degrees this way:(Some people don't like extending built-in objects, but since one doesn't instantiate Math instances — at least, I don't — this doesn't seem terribly offensive.)
Math.sin
以弧度工作,我猜你的计算器是以度为单位的。Math.sin
works in radians, I guess your calculator is in degrees.如上所述,Math.sin() 需要使用弧度作为输入。要将度数转换为弧度,请使用:
As was said above, Math.sin() requires the use of radians as input. To convert degrees to radians, use:
Math.sin 接受以弧度为单位的值,而计算器设置为度数。
Math.sin accepts values in radians, while your calculator is set to degrees.