What is the best way to compare floats for almost-equality in Python?

问题:

It's well known that comparing floats for equality is a little fiddly due to rounding and precision issues.众所周知,由于舍入和精度问题,比较浮点数的相等性有点繁琐。

For example: https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/例如: https : //randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/

What is the recommended way to deal with this in Python?在 Python 中处理这个问题的推荐方法是什么?

Surely there is a standard library function for this somewhere?当然在某处有一个标准库函数吗?


解决方案:

参考一: https://en.stackoom.com/question/NTcn
参考二: https://stackoom.com/question/NTcn
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章