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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章