Math.cos()给出了错误的结果 [英] Math.cos() gives wrong result
本文介绍了Math.cos()给出了错误的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
根据Wolfram Mathematica:
cos(50) = 0.6427876096865394 ;
According to Wolfram Mathematica: cos(50) = 0.6427876096865394;
但是这Java中的代码:
But this code in Java:
System.out.println(Math.cos(50));
给出 0.9649660284921133 。
java.lang.Math
有什么问题?
推荐答案
Math.cos()
期望参数以弧度为单位。这将返回您需要的结果:
Math.cos()
expects the parameter to be in radians. This will return the result you need:
Math.cos(Math.toRadians(50));
这篇关于Math.cos()给出了错误的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文