[R] Integer bit size and the modulus operator

Ionut Florescu ifloresc at stevens.edu
Mon Jan 30 19:39:56 CET 2006

Thank you for the quick reply, I will look into the R packages.
For crashing R try this:

{a=1:(p-1); b=x^a%%p;
if(all(b[1:(p-2)]!=1)&&(b[p-1]==1)){return(x, " Good ")}
else{return(x, " No Good, try another integer ")}

This checks if element x is a generator of the group Z_p. If you try 
this function for p = 41 and x various increasing values eventually it 
will crash R. That is what I meant by random, at first I started x=2,3 
so on, when I got to 8, R crashed. Now apparently I can get to 15. When 
I tried again I got to 20.

Ionut Florescu

Duncan Murdoch wrote:
> On 1/30/2006 11:32 AM, Ionut Florescu wrote:
>> I am a statistician and I come up to an interesting problem in 
>> cryptography. I would like to use R since there are some statistical 
>> procedures that I need to use.
>> However, I run into a problem when using the modulus operator %%.
>> I am using R 2.2.1 and when I calculate modulus for large numbers 
>> (that I need with my problem) R gives me warnings. For instance if 
>> one does:
>> a=1:40;
>> 8^a %% 41
>> one obtains zeros which is not possible since 8 to any power is not a 
>> multiple of 41.
>> In addition when working with numbers larger that this and with the 
>> mod operator R crashes randomly.
> Could you keep a record of the random crashes, and see if you can make 
> any of them repeatable?  R shouldn't crash.  If you can find a 
> repeatable way to make it crash, then that's a bug that needs to be 
> fixed.  (If it crashes at random it should still be fixed, but it's so 
> much harder to fix that it's unlikely to happen unless the cases are 
> ones that look likely to come up in normal situations.)
>> I believe this is because R stores large integers as real numbers 
>> thus there may be lack of accuracy when applying the modulus operator 
>> and converting back to integers.
>> So my question is this: Is it possible to increase the size of memory 
>> used for storing integers? Say from 32 bits to 512 bits (Typical size 
>> of integers in cryptography).
> No, but there is at least one contributed package that does multiple 
> precision integer arithmetic.  I can't remember the name of it right 
> now, but Google should be able to find it for you...
> Duncan Murdoch
>> Thank you, any help would be greatly appreciated.
>> Ionut Florescu
>> ______________________________________________
>> R-help at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide! 
>> http://www.R-project.org/posting-guide.html

More information about the R-help mailing list