首页 > 解决方案 > 在仿射中使用极小的数字。在python中仿射

问题描述

Affine.scale 中的小数始终为零

例如,

from affine import Affine

# This line will show
#| 0.00, 0.00, 0.00|
#| 0.00, 0.00, 0.00|
#| 0.00, 0.00, 1.00|
print(Affine.scale(1/(2**19)))

但是,我需要 1.9073486328125e-06 而不是 0。

我怎样才能解决这个问题?

(我使用的仿射版本是2.3.0。)

标签: pythonfloating-pointprecisionaffinetransform

解决方案


打印仿射变换矩阵将使其打印四舍五入的数字。

我们应该使用 index 来获取存储在 metirx 中的确切数字。

print(Affine.scale(1/(2**19))[0])
# got: 1.9073486328125e-06

推荐阅读