Answer the question
In order to leave comments, you need to log in
What is machine epsilon?
Learning Python from Summerfield's book Programming in Python 3 (A Complete Introduction to the Python Language)
I got to machine epsilon.
Python has sys.float_info.epsilon and this value is the native epsilon. I understood it.
I also realized that there are values less than the machine epsilon, but the computer does not work accurately with these values.
In the last line of the code below, I divide the machine epsilon by 2 and get a value less than the machine epsilon, then I add this value with one and as a result I get a number a little more than one, but this is "slightly", less than the number that the computer can represent correctly and therefore the computer rounds this "slightly" to zero, and as a result, in the last line, I get a unit without changes.
x = sys.float_info.epsilon
'''
this is how to work machine epsilon
1.0 + x != 1.0
1.0 + x/2 == 1.0
'''
print (1.0 + x) # output will be 1.0000000000000002
print (1.0 + x/2) # output will be 1.0
Answer the question
In order to leave comments, you need to log in
The correct definition is:
The difference between 1 and the minimum number representable in a float greater than 1. To say that:
A machine epsilon is the smallest difference between numbers that a computer can distinguish.
import sys
from numpy import float32
a = float32(sys.float_info.max)
while a > sys.float_info.max - 10000:
a -= 1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question