This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author remi.lapeyre
Recipients remi.lapeyre, talha.demirsoy
Date 2020-04-05.23:13:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1586128384.99.0.205573172775.issue40200@roundup.psfhosted.org>
In-reply-to
Content
Hi Talha, you are using floating points division which convert its operands to floats so it loose precision for large numbers. The syntax for integer division in Python 3 is // and it will not change the type of its operands. Notice the difference below:

>>> 100000000000000000000000000/10 % 10
4.0
>>> 100000000000000000000000000.0//10 % 10
4.0
>>> 100000000000000000000000000//10 % 10
0

As you can see, in the first example the operand got changed to float which caused a loss of precision and we get the same result when we try directly with a float. Using // gives the expected result.

Python use perfect arithmetic for integers but IEEE 754 for floating point calculations. You will find that there is a lot of those "quirks" when using either very large or very small numbers and will need to be mindful of them.

In the program you linked, changing '/' to '//' should gives the result you are expecting.
History
Date User Action Args
2020-04-05 23:13:05remi.lapeyresetrecipients: + remi.lapeyre, talha.demirsoy
2020-04-05 23:13:04remi.lapeyresetmessageid: <1586128384.99.0.205573172775.issue40200@roundup.psfhosted.org>
2020-04-05 23:13:04remi.lapeyrelinkissue40200 messages
2020-04-05 23:13:04remi.lapeyrecreate