Python:计算浮点精度作为浮点值的函数

时间:2018-04-24 14:21:01

标签: python numpy

我想从wikipedia's page on the IEEE 754 standard重现以下情节:

enter image description here

不幸的是,维基百科的文章没有说明他们如何生成这些数据,而且计算起来似乎并不容易。

1 个答案:

答案 0 :(得分:2)

我不能100%确定那里到底绘制了什么,但np.nextafter似乎给出了相似的结果:

>>> x = 10**np.linspace(-12, 12, 50)
>>> y = np.nextafter(x, 2*x) - x

>>> x = 10**np.linspace(-12, 12, 50, dtype=np.float32)
>>> y = np.nextafter(x, 2*x) - x