问题描述
有人知道在Python中执行定点运算的库吗?还是有人有示例代码?
Does anyone know of a library to do fixed point arithmetic in Python?Or, does anyone has sample code?
推荐答案
如果您有兴趣进行定点运算,则Python标准库提供了十进制模块可以执行此操作.
If you are interested in doing fixed point arithmetic, the Python Standard Library has a decimal module that can do it.
实际上,它具有比内置功能更灵活的浮点功能.灵活的意思是:
Actually, it has a more flexible floating point ability than the built-in too. By flexible I mean that it:
-
具有用于各种特殊情况的信号"(可以将其设置为在信号处理方面做各种事情)
Has "signals" for various exceptional conditions (these can be set to do a variety of things on signaling)
具有正面和负面影响无穷大,以及NaN(不是号码)
Has positive and negativeinfinities, as well as NaN (not anumber)
可以区分正数负0
允许您设置不同的舍入方案.
Allows you to set different roundingschemes.
允许您设置自己的最小值和最大值.
Allows you to set your own min andmax values.
总而言之,对于数百万家庭使用而言,这很方便.
All in all, it is handy for a million household uses.
这篇关于定点算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!