Java Math.PI的价值有多精确?

And*_*eev 2 java math

我能获得PI的第N位数的最大N是多少?

dan*_*uch 6

public static final double PI = 3.141592653589793d

所以 N = 16

这就是API在这里所说的:http://docs.oracle.com/javase/6/docs/api/constant-values.html#java.lang.Math.PI


确实Math.class的源代码说:

public static final double PI = 3.14159265358979323846;

和这里 N = 21


无论如何 - 这有点奇怪;)

  • IEEE 754 64位双精度约为16位,这正是"3.141592653589793d"中的位数. (3认同)
  • 没什么奇怪的.这只是意味着输入了21位数字.这并不意味着21位数字准确存储在数字中,您是否要将该值写回. (3认同)

Eng*_*uad 5

这是源代码中写的:

/**
 * The {@code double} value that is closer than any other to
 * <i>pi</i>, the ratio of the circumference of a circle to its
 * diameter.
 */
public static final double PI = 3.14159265358979323846;
Run Code Online (Sandbox Code Playgroud)