2

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?

josliber
  • 43,891
  • 12
  • 98
  • 133
aarthi
  • 85
  • 5

1 Answers1

5

Try creating the bigz value using a string:

> factorize(as.bigz("113423713055421844361000443"))
Big Integer ('bigz') object of length 4:
[1] 67003      29881      9119521    6212157481

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.bigz as a string.

Weeble
  • 17,058
  • 3
  • 60
  • 75