Java的价值有多精确';s Math.PI是什么?

Java的价值有多精确';s Math.PI是什么?,java,math,Java,Math,我能得到π的第N位数的最大N是多少?请参见公共静态最终双π=3.141592653589793d 因此N=16 这就是API在这里所说的: 但是确实数学的源代码。课堂上说: 公共静态最终双PI=3.14159265358979323846 这里N=21 无论如何——这有点奇怪;) 这是源代码中编写的内容: /** * The {@code double} value that is closer than any other to * <i>pi</i>, the

我能得到π的第N位数的最大N是多少?

请参见

公共静态最终双π=3.141592653589793d

因此
N=16

这就是API在这里所说的:


但是确实数学的源代码。课堂上说


公共静态最终双PI=3.14159265358979323846

这里
N=21



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

这是源代码中编写的内容:

/**
 * 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;
/**
 * 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;
/**
*比任何其他值更接近的{@code double}值
*圆周率,圆周长与圆周长的比值
*直径。
*/
公共静态最终双PI=3.14159265358979323846;
来自

它看起来好像被定义为小数点后15位。关于这个问题,我们在第二节中有更多的讨论

在源代码中:

/**
 * 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;
/**
 * 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;
/**
*比任何其他值更接近的{@code double}值
*圆周率,圆周长与圆周长的比值
*直径。
*/
公共静态最终双PI=3.14159265358979323846;

Pi的Java常数是一个近似值。Pi的精确值在大多数计算中都是无关的。

你是在问浮点表示吗?如果是这样的话,Java参考手册或维基百科上的浮点定义有什么问题?你是在问PI的定义有多远?来源:公共静态最终双PI=3.14159265358979323846;它和任何双精度一样精确。IEEE 754 64位双精度约为16位,这正是
3.141592653589793d
中的位数,这一点也不奇怪。这仅仅意味着输入了21位数字。这并不意味着21位数字被准确地存储在数字中,如果您将该值写回的话。它是16位数字-下面是如何: