python数字精度自动变化_如何在python中将一个数字转换成12位精度?
正如其他答案中提到的,這并不存在
在純python數據類型中,see the docs
但是,您可以使用numpy來指定顯式的data types,例如numpy.float16
numpy.float32
numpy.float64
您還可以使用numpy.float96的extended precision,這似乎是您想要的,因為12字節是96位import numpy as np
high_prec_array = np.array([1,2,3], dtype=np.float96)
注意事項
正如在評論和鏈接中指出的,這不是真正的12字節精度。相反,80位(10字節)由2個零字節填充。如果您只關心兼容性,這就足夠了。在In the tables below, platform? means that the type may not be
available on all platforms. Compatibility with different C or Python
types is indicated: two types are compatible if their data is of the
same size and interpreted in the same way.
也可以閱讀這篇關于使用這種異域類型的注意事項
我覺得這很有啟發性。我的結論是,如果您想絕對保證96bit精度,那么python不是正確的選擇,因為可用擴展精度中的固有歧義來自于C分布中的歧義。考慮到你的物理背景,如果你想保證穩定性,我建議使用^{}。在
在C++中定義自己的類型< /H1 >
對于感興趣的高級用戶,可以定義自己的數據類型。關于user defined types states的numpy指南As an example of what I consider a useful application of the ability
to add data-types is the possibility of adding a data-type of
arbitrary precision floats to NumPy.
因此,如果您非常希望將代碼保存在python中,可以嘗試使用^{}。在
總結
以上是生活随笔為你收集整理的python数字精度自动变化_如何在python中将一个数字转换成12位精度?的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: Comet OJ - Contest #
 - 下一篇: 计算机表格怎么同时选中分开的两项,exc