How can you test the representable value just below a threshold?

nextafter returns the adjacent representable floating value in the requested direction.

numpy.nextafter in practice

One step from one toward zero exercises the strict-below-one branch. Use the production data type because neighboring values are spaced differently across precisions.

import numpy as np
float(np.nextafter(1.,0.))

Result 0.9999999999999999

中文

如何构造恰好低于阈值的浮点测试点?

nextafter 从给定浮点值朝指定方向移动到相邻的可表示数。

numpy.nextafter 算例

从 1.0 朝 0.0 移动一次可测试严格小于 1 的分支。选用与线上计算相同的数据类型,否则相邻值间距会不同。

import numpy as np
float(np.nextafter(1.,0.))

结果 0.9999999999999999

References / 参考来源

Keep reading / 继续阅读