0
I made this algorithm to test how Python compares nearby numbers:
x = 2.5 # número arbitrário que escolhi para fazer os testes
y = float(input('Insira o Y ')) #
print('X > Y = {}'.format(x > y)) # mostra se x>y
print('X = Y = {}'.format(x == y)) # mostra se x = y
print('X < Y = {}'.format(x < y)) # mostra se x < y
For y = 2.5 billion thousand thousand, for example, Python returns that X = Y.
Insira o Y 2.50000000000000001
X > Y = False
X = Y = True
X < Y = False
Process finished with exit code 0
How to make Python realize that X is smaller than Y, stopping rounding?
Read Floating-point arithmetic: Problems and limitations.
– Solkarped