什么定义在Python中的浮点精度? [英] What defines floating point precision in python?

查看:151
本文介绍了什么定义在Python中的浮点精度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Erlang学到了完全相同的操作符,比较只有值,而且还有数据的数据类型,我很好奇Python是如何工作的,以及它的唯一等于运算符。因此,在确定

 >>> 1 == 1.0 
True

我想知道浮点精度,

 >>> 0.9999999999999999 == 1 
False
>>> 0.99999999999999999 == 1
True
>>>

有人可以解释浮点精度是如何确定的吗?它在2.7.1和3.1.2中都是一样的。

解决方案

请检查Python文档:



http://docs.python.org/tutorial/floatingpoint .html


I learnt of the "exactly equal to" operator in Erlang, which compares not only values, but also data types of numbers, and I was curious about how things work in Python and its lone "equals to" operator. So after making sure that

>>> 1 == 1.0 
True

I wondered about the floating point precision, and got to this

>>> 0.9999999999999999 == 1
False
>>> 0.99999999999999999 == 1
True
>>>

Could someone explain how floating point precision is determined here? It works the same in both 2.7.1 and 3.1.2

解决方案

Please check with the Python documentation:

http://docs.python.org/tutorial/floatingpoint.html

这篇关于什么定义在Python中的浮点精度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆