Java 计算sincos&;的精度不足;谭(爪哇)

Java 计算sincos&;的精度不足;谭(爪哇),java,Java,当我运行这段代码时 System.out.println( Math.cos(8.8485279795) ); // should be : 0.988098452127 System.out.println( Math.sin(23.437101628) ); // should be :0.397742095267 System.out.println( Math.tan(52.2166666666667) ); // should be : 1.289966871548 System.ou

当我运行这段代码时

System.out.println( Math.cos(8.8485279795) ); // should be : 0.988098452127
System.out.println( Math.sin(23.437101628) ); // should be :0.397742095267
System.out.println( Math.tan(52.2166666666667) ); // should be : 1.289966871548
System.out.println( Math.cos(23.437101628) ); // should be :0.917497261932
System.out.println( Math.sin(8.8485279795) ); //should be : 0.153822784089
输出是这样的

-0.8385118249144639
-0.9922171619691422
-2.500855651260892
-0.12451949041776937
0.5448833998926885

我该如何解决这个问题呢?

这并不是因为缺少精度,而是因为你正在将度传递给需要弧度的函数。用于修复。像

System.out.println(Math.cos(Math.toRadians(8.8485279795)));
System.out.println(Math.sin(Math.toRadians(23.437101628)));
System.out.println(Math.tan(Math.toRadians(52.2166666666667)));
System.out.println(Math.cos(Math.toRadians(23.437101628)));
System.out.println(Math.sin(Math.toRadians(8.8485279795)));
我得到了(如你所料)


这些函数以弧度表示角度,而不是度。它起作用了!,thx;)
0.9880984521266581
0.39774209526711635
1.2899668715484742
0.9174972619318948
0.1538227840890365