根据数学钨: COS(50)=0.6427876096865394;Math.cos()给出错误的结果
但这个代码在Java中:
System.out.println(Math.cos(50));
给0.9649660284921133。
java.lang.Math
有什么问题?
根据数学钨: COS(50)=0.6427876096865394;Math.cos()给出错误的结果
但这个代码在Java中:
System.out.println(Math.cos(50));
给0.9649660284921133。
java.lang.Math
有什么问题?
Math.cos()
期望参数以弧度表示。这将返回的结果,你需要:
Math.cos(Math.toRadians(50));
Math.cos()
使用弧度,所以让你期望的结果,你需要做的
System.out.println(Math.cos(Math.toRadians(50)));
大部分Java三角函数都需要参数为弧度。可以,请使用Math.toRadians()转换:
System.out.println(Math.cos(Math.toRadians(50)));
我...
System.out.println(Math.cos(50));
System.out.println(Math.cos(new Double(50)));
System.out.println(Math.cos(Math.toRadians(50)));
System.out.println(Math.cos(Math.toRadians(new Double(50))));
回报
0.9649660284921133
0.9649660284921133
0.6427876096865394
0.6427876096865394
http://www.wolframalpha.com/input/?i=cos%2850deg%29
cos(50deg)
得到相同的结果。cos(50)
...所以钨是默认的程度。
+1。仅供参考,因为OP在谈论wolfram http://www.wolframalpha.com/input/?i=cos%2850rad%29 –
Java中有Math.cos()与Degrees一起使用的版本吗?我们经常需要记住手动将度数转换为弧度? –