Is There the Equivalent of FLT_EPS of C In Python?

jburgy jburgy at gmail.com
Fri Sep 16 07:34:54 EDT 2005


A. L. wrote:
> I am writing the code involved in numerical computation. When I need a
> float epsilon similar to FLT_EPS in C, eps in matlab, I fail to find
> the equivalent in python. Could somebody here can give me some advices?

Have you searched the documentation? I you can't find anything there,
you can always calculate it yourself. Epsilon is usually defined as
follows:

>>> eps = 1.
>>> while 1. + eps != 1.:
...     eps /= 2.
...
>>> eps
1.1102230246251565e-16

Then some people actually multiply the above number by 2. In other
words (on my machine), eps is math.ldexp(1, -52). YMMV

Jan




More information about the Python-list mailing list