I am trying to factorize a big integer with the following code:
library(gmp)
as.bigz(factorize( 113423713055421844361000443))
Big Integer ('bigz') object of length 38:
# [1] 2 2 2 2 2 2 2 2 2 2 2
# [12] 2 2 2 2 2 2 2 2 2 2 2
# [23] 2 2 2 2 2 2 2 2 2 2 2
# [34] 2 3 647 1134247 2998823
This is clearly not the correct factorization, because my integer is odd but factorize is returning 2 as a factor. What is the problem?
Try creating the bigz value using a string:
I believe what's going wrong for you is that when you enter the numeric literal, R stores it in a floating point representation, losing precision. You need to create the bigz representation before passing it to factorize, and in order to keep full precision, you have to pass it to
as.bigzas a string.