在Python中的epsilon价值 [英] Value for epsilon in Python

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

问题描述

在Python中有(或获取方法)epsilon的标准值吗?我需要比较浮点值,并希望与最小的可能差异进行比较。

Is there a standard value for (or method for obtaining) epsilon in Python? I need to compare floating point values and want to compare against the smallest possible difference.

在C ++中,提供了 numeric_limits :: epsilon() 任何给定数据类型的ε值。

In C++ there's a function provided numeric_limits::epsilon( ) which gives the epsilon value for any given data type. Is there an equivalent in Python?

推荐答案

这些信息可以在 sys.float_info ,对应于C99中的float.h。

The information is available in sys.float_info, which corresponds to float.h in C99.

>>> import sys
>>> sys.float_info.epsilon
2.220446049250313e-16

这篇关于在Python中的epsilon价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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