【发布时间】:2016-07-11 19:08:20
【问题描述】:
我的代码将弧度角传递给cos、tan 和sin。除了90 的棕褐色外,一切似乎都运行良好,它出于某种奇怪的原因给出了16331239353195370 的值。示例代码:
import java.text.DecimalFormat;
public class mathtable {
public static void main(String[] args) {
System.out.println("Angle Sin Cos Tan");
System.out.println("----- --- --- ---");
for (double angle = 0.0; angle < 180; angle +=5) {
double angle_rad = Math.toRadians(angle);
double sin = Math.sin(angle_rad);
String sin_4 = new DecimalFormat("#.####").format(sin);
double cos = Math.cos(angle_rad);
String cos_4 = new DecimalFormat("#.####").format(cos);
double tan = Math.tan(angle_rad);
String tan_4 = new DecimalFormat("#.####").format(tan);
System.out.println(angle + " " + sin_4 + " " + cos_4 + " " + tan_4);
}
}
}
为什么返回的值不严格等于 IEEE 无穷大?
【问题讨论】: