You are using float division, which cannot handle large numbers with as much precision, after which you are flooring the result by casting it back to an int()
.
Don't do that, that causes data loss. Use integer (floor) division with //
instead:
>>> 6008514751432349174082765599289028910605977570 // 2 * 2
6008514751432349174082765599289028910605977570
This still can lead to rounding errors of course, if the input value is not divisible by 2 without flooring:
>>> 6008514751432349174082765599289028910605977571 // 2 * 2
6008514751432349174082765599289028910605977570
but floating point values are limited in precision based on your exact CPU support; see sys.float_info
to see what exact limitations your platform imposes on float numbers.
On my Mac, sys.float_info.dig
tells me my platform supports 15 digits of precision, but you are dividing a 46-digit integer number. This means that you throw away the bottom 30 digits from your large integer when using float division:
>>> len(str(int(6008514751432349174082765599289028910605977570 / 2) - (6008514751432349174082765599289028910605977570 // 2)))
30
That is a lot of precision loss there. :-)