Skip to content

Commit e2ab25d

Browse files
committed
set GP_DATA.primelimit according to maxprime argument to PariInstance
1 parent 8bd7ca3 commit e2ab25d

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

cypari2/pari_instance.pyx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ cdef class Pari(Pari_auto):
491491

492492
# Take 1MB as minimal stack. Use maxprime=0, which PARI will
493493
# internally increase to some small value like 65537.
494-
pari_init_opts(1000000, 0, INIT_DFTm)
494+
# (see function initprimes in src/language/forprime.c)
495+
pari_init_opts(1000000 * sizeof(long), 0, INIT_DFTm)
495496
after_resize()
496497

497498
# Disable PARI's stack overflow checking which is incompatible
@@ -557,7 +558,7 @@ cdef class Pari(Pari_auto):
557558
558559
When the PARI system is already initialized, the PARI stack is only
559560
grown if ``size`` is greater than the current stack, and the table
560-
of primes is only computed is ``maxprime`` is larger than the current
561+
of primes is only computed if ``maxprime`` is larger than the current
561562
bound.
562563
563564
Examples:
@@ -575,6 +576,11 @@ cdef class Pari(Pari_auto):
575576
>>> pari.stacksize(), pari2.stacksize()
576577
(10000000, 10000000)
577578
579+
>>> Pari().default("primelimit")
580+
500000
581+
>>> Pari(maxprime=20000).default("primelimit")
582+
20000
583+
578584
For more information about how precision works in the PARI
579585
interface, see :mod:`cypari2.pari_instance`.
580586
@@ -603,6 +609,7 @@ cdef class Pari(Pari_auto):
603609
set_pari_stack_size(size, sizemax)
604610

605611
# Increase the table of primes if needed
612+
GP_DATA.primelimit = maxprime
606613
self.init_primes(maxprime)
607614

608615
# Initialize some constants
@@ -1042,15 +1049,15 @@ cdef class Pari(Pari_auto):
10421049
>>> pari = cypari2.Pari()
10431050
>>> pari.init_primes(200000)
10441051
1045-
We make sure that ticket :trac:`11741` has been fixed::
1052+
We make sure that ticket :trac:`11741` has been fixed:
10461053
1047-
>>> pari.init_primes(2**30)
1048-
Traceback (most recent call last):
1049-
...
1050-
ValueError: Cannot compute primes beyond 436273290
1054+
>>> pari.init_primes(2**30)
1055+
Traceback (most recent call last):
1056+
...
1057+
ValueError: Cannot compute primes beyond 436273290
10511058
"""
1052-
# Hardcoded bound in PARI sources
1053-
if M > 436273290:
1059+
# Hardcoded bound in PARI sources (language/forprime.c)
1060+
if M > 436273289:
10541061
raise ValueError("Cannot compute primes beyond 436273290")
10551062

10561063
if M <= maxprime():

cypari2/paripriv.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ cdef extern from "pari/paripriv.h":
2323
struct gp_data:
2424
pariout_t *fmt
2525
unsigned long flags
26+
ulong primelimit # deprecated
2627

2728
extern gp_data* GP_DATA
2829

0 commit comments

Comments
 (0)