Value for epsilon in Python
Solution 1:
The information is available in sys.float_info
, which corresponds to float.h in C99.
>>> import sys
>>> sys.float_info.epsilon
2.220446049250313e-16
Solution 2:
As strcat posted, there is sys.float_info.epsilon
.
But don't forget the pitfalls of using it as an absolute error margin for floating point comparisons. E.g. for large numbers, rounding error could exceed epsilon.
If you think you need a refresher, the standard reference is David Goldberg's What Every Computer Scientist Should Know About Floating-Point Arithmetic, or for a simpler review you can check out The Floating Point Guide.