[pypy-issue] Issue #2713: Large integer multiplication could be faster. (pypy/pypy)
issues-reply at bitbucket.org
Sat Dec 23 13:55:58 EST 2017
New issue 2713: Large integer multiplication could be faster.
I have noticed that multiplication of large integers (2^1000 or greater) , while faster than `python` is a good bit slower than for integers provided by gmpy2. This is a pretty minor request, as not much code uses numbers this big, but it would be great to have better support.
def mod_mersenne(n, prime, mersenne_prime):
""" Calculates n % 2^prime-1 where mersenne_prime=2**prime-1 """
while n > mersenne_prime:
n = (n & mersenne_prime) + (n >> prime)
return n if n != mersenne_prime else 0
def is_mersenne(prime= 9883)
mersense_prime = 2**prime - 1
s = 4
for _ in range(prime - 2):
s = mod_mersenne(s*s, prime, mersenne_prime) - 2
return s % mersenne_prime == 0:
More information about the pypy-issue