robert
robert

Reputation: 3726

Incorrect calculation result (possible overflow)

Performing (-954437177*4294895519) %% 4294967296 in R gives 1908882432 instead of 1908882329. Is there a way in R to compute the correct value?

Upvotes: 0

Views: 34

Answers (1)

Joshua Ulrich
Joshua Ulrich

Reputation: 176648

Use a package that supports larger integers (e.g. gmp):

library(gmp)
> mod.bigz(-as.bigz(954437177)*as.bigz(4294895519), as.bigz(4294967296))
Big Integer ('bigz') :
[1] 1908882329

Upvotes: 2

Related Questions