[issue39436] Strange behavior of comparing int and float numbers

2020-01-23 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

Further to what Matthew said, this is not just a Python oddity. It applies to 
just about all programming languages, including C, C++, Java, Javascript, Ruby, 
etc. Some of them have even less precision by default.

Floats are not the same as the real numbers you learned about in school. There 
is a huge amount of resources about the limitations of floating point 
arithmetic on Stackoverflow etc which can be found by googling. A good place to 
start is the Python FAQs and tutorial:

https://docs.python.org/3/faq/design.html#why-are-floating-point-calculations-so-inaccurate

https://docs.python.org/3/tutorial/floatingpoint.html#tut-fp-issues

--
nosy: +steven.daprano

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39436] Strange behavior of comparing int and float numbers

2020-01-23 Thread Matthew Barnett


Change by Matthew Barnett :


--
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39436] Strange behavior of comparing int and float numbers

2020-01-23 Thread Matthew Barnett


Matthew Barnett  added the comment:

Python floats have 53 bits of precision, so ints larger than 2**53 will lose 
their lower bits (assumed to be 0) when converted.

--
nosy: +mrabarnett
resolution:  -> not a bug

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39436] Strange behavior of comparing int and float numbers

2020-01-23 Thread Petr Pisl


New submission from Petr Pisl :

When python compares float and int created from the same int number should be 
equal like 

int(1) == float(1)

but from 9007199254740993 this is not true. 

int(9007199254740993) == float(9007199254740993) is not true. The same behavior 
is for bigger odd numbers. The even numbers are still equal. So it looks like:

int(9007199254740989) == float(9007199254740989) # True
int(9007199254740990) == float(9007199254740990) # True
int(9007199254740991) == float(9007199254740991) # True
int(9007199254740992) == float(9007199254740992) # True
int(9007199254740993) == float(9007199254740993) # False
int(9007199254740994) == float(9007199254740994) # True
int(9007199254740995) == float(9007199254740995) # False
int(9007199254740996) == float(9007199254740996) # True
int(9007199254740997) == float(9007199254740997) # False
int(9007199254740998) == float(9007199254740998) # True

--
messages: 360571
nosy: Petr Pisl
priority: normal
severity: normal
status: open
title: Strange behavior of comparing int and float numbers
type: behavior
versions: Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com