Why is Python 3.4 giving the wrong answer for dividing large numbers, and how can I check for divisibility?

In my program, I use division to check if the result is integer, I check divisibility. However, I am getting the wrong answers. Here is an example:

print(int(724815896270884803/61))

gives 11882227807719424.

print(724815896270884803//61)

gives the correct result 11882227807719423.

Why is the floating point result wrong, and how can I check if a large number is divisible by 61? Do I need to do a whole division, and then multiply it and see if it is equal?

+4
source share
2 answers

, int / float, float. 11882227807719423 :

In [1]: float(11882227807719423)
Out[1]: 1.1882227807719424e+16
+5

(%):

print(724815896270884803 % 61)

( ). 0 , .

+7

Source: https://habr.com/ru/post/1542245/


All Articles