Why can adding one leave a large floating number unchanged?

spacing reports the local separation of representable numbers. For positive values the upward gap changes with magnitude.

numpy.spacing in practice

At two to the power of 53 the upward float64 spacing is two. Adjacent ledger identifiers can collapse in a floating column. Preserve them as integers or text.

import numpy as np
np.spacing(np.float64(2**53))

Result 2.0

中文

为什么大数加一在浮点数组里可能没有变化?

spacing 可查询某个数附近的浮点间距。对正数,向上的相邻值距离会随数量级变化。

numpy.spacing 算例

在 float64 的 2 的 53 次方处,向上间距为 2。把链上大整数编号存入浮点列可能合并相邻编号,应保留整数或文本。

import numpy as np
np.spacing(np.float64(2**53))

结果 2.0

References / 参考来源

Keep reading / 继续阅读