Problem with precision in R
When I multiply a high precision double value number in R the precision seems to change or something weird happens. Look at the last 4 digits.
x <- 1608781598.186771296
y<-1000000000.00
print(x*y)
#1608781598186771456
#turns out that R is converting the precision like so
print(as.double(1608781598.186771296),digits=19)
#1608781598.186771393
#if I use the above value and multiply by a billion I can reproduce the incorrect value
print(1608781598.186771393*1000000000.0)
#1608781598186771456
Similar problem in python
In fact similar thing is happening in Python as well
import numpy as np
print("{:.0f}".format(np.float128(1608781598.186771296)*np.float128(1000000000)))
#1608781598186771456
Whereas I am expecting a value of 1608781598186771296. What the heck is going on in here?