Value for epsilon in Python

后端 未结 4 952
夕颜
夕颜 2020-12-08 09:09

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 differen

4条回答
  •  青春惊慌失措
    2020-12-08 09:34

    If you cannot find a function to do that, remember that the algorithm to calculate the machine epsilon is very easy (you can test with your favourite programming language).E.g, for python:

    eps = 1.0
    while eps + 1 > 1:
        eps /= 2
    eps *= 2
    print("The machine epsilon is:", eps)
    

    In my case, I got:

    The machine epsilon is: 2.220446049250313e-16

提交回复
热议问题