I tested these calculations
n = 773160767
n*(n+1)
n*(n+1)/2
n*(n+1)//2
n*(n+1)/2 % (10**9+7)
n*(n+1)//2 % (10**9+7)
Output:
597777572401189056
2.9888878620059456e+17
298888786200594528
108373072.0
108373040
Resources I find online all use examples like 3/2 where the result is not a whole number. I read https://docs.python.org/3/tutorial/floatingpoint.html too but it also only describes non-whole numbers but my example here uses evenly divisible whole numbers so I expect the result should also be a whole number exactly representable in base2 (298888786200594528) when using float division(/)?
Is there something wrong with the number being too big? If yes, how big is too big and is there a hardware explanation like below from the link above? (I can't do experiments lowering n because I don't know if what I'm seeing is what is represented under the hood)
almost all platforms map Python floats to IEEE-754 “double precision”.
754 doubles contain 53 bits of precision,
so on input the computer strives to convert 0.1 to the closest fraction
it can of the form J/2**N where J is an integer containing exactly 53 bits