Value for epsilon in Python

thornate picture thornate · Mar 2, 2012 · Viewed 74.2k times · Source

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.

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?

Answer

strcat picture strcat · Mar 2, 2012

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

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