tan 45 gives me 0.9999

前端 未结 4 710
清酒与你
清酒与你 2021-01-12 08:30

Why does tan 45(0.7853981633974483 in radian) give me 0.9999? What\'s wrong with the following code?

System.out.println(Math.tan(M         


        
4条回答
  •  忘掉有多难
    2021-01-12 09:02

    The closest double to pi/4 is exactly 0x1.921fb54442d18p-1. The tangent of this double, to more bits than you need, is 0x1.fffffffffffff72cece67p-1. Rounding to the nearest double gives you exactly 0x1.fffffffffffffp-1 because 0x1.fffffffffffff72cece67p-1 is less than 0x1.fffffffffffff8p-1.

提交回复
热议问题