Is x%(1e9 + 7) and x%(10**9 + 7) different in Python? If yes, why? Is x%(1e9 + 7) and x%(10**9 + 7) different in Python? If yes, why? python-3.x python-3.x

Is x%(1e9 + 7) and x%(10**9 + 7) different in Python? If yes, why?


But I still don't understand how a zero after decimal point can cause difference.

Where the decimal point isn't important. It's floating!

Why is this difference arising?

Because floating point numbers in Python are the usual hardware ones which means they have limited storage and precision:

>>> int(123123123123123123123.0)123123123123123126272#                ^^^^ different!

But integer numbers in Python have infinite storage and precision ("bignum"):

>>> int(123123123123123123123)123123123123123123123

So:

>>> 123123123123123123123 % 10**9123123123>>> 123123123123123123123 % 1e9123126272.0

In the second case both sides are converted to floating point because one of them is.