How to find the machine epsilon in Python

Machine Epsilon describes the round-off error for a floating-point number with a certain amount of precision. It is the upper bound on the relative approximated error caused due to rounding off floating numbers. It is also defined as the gap between the number 1 and the next largest floating point number.

Note: Machine epsilon is also called macheps and represented by ϵϵ.

The reason why machine epsilon is important is that no matter how carefully we do operations like addition, subtraction, multiplication, or division with floating point numbers, we end up making an error when we round off our answer. That is what machine epsilon measures.

Code example

A code example of how we can find ϵ\epsilon in Python using NumPy is shown below:

import numpy as np
epss = np.finfo(np.float32).eps
print("Machine epeilon for single precision : ",epss)
epsd = np.finfo(np.float64).eps
print("Machine epeilon for double precision : ",epsd)

In the above code, we calculate the ϵ\epsilon for both single (32-bit) and double (64-bit) precision floating-point numbers.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved