1 #ifndef GINAC_CHINREM_GCD_PRIMES_FACTORY_H
2 #define GINAC_CHINREM_GCD_PRIMES_FACTORY_H
3 #include <cln/integer.h>
4 #include <cln/numtheory.h>
6 #include "smod_helpers.h"
13 * Find a `big' prime p such that lc mod p != 0. Helper class used by modular
19 // These primes need to be large enough, so that the number of images
20 // we need to reconstruct the GCD (in Z) is reasonable. On the other
21 // hand, they should be as small as possible, so that operations on
22 // coefficients are efficient. Practically this means we coefficients
23 // should be native integers. (N.B.: as of now chinrem_gcd uses cl_I
24 // or even numeric. Eventually this will be fixed).
26 // This ensures coefficients are immediate.
27 static const int immediate_bits = 8*sizeof(void *) - __alignof__(void *);
28 static const long opt_hint = (1L << (immediate_bits >> 1)) - 1;
32 last = cln::nextprobprime(cln::cl_I(opt_hint));
35 bool operator()(long& p, const cln::cl_I& lc)
37 static const cln::cl_I maxval(std::numeric_limits<long>::max());
38 while (last < maxval) {
39 long p_ = cln::cl_I_to_long(last);
40 last = cln::nextprobprime(last + 1);
42 if (!zerop(smod(lc, p_))) {
50 bool has_primes() const
52 static const cln::cl_I maxval(std::numeric_limits<long>::max());
59 #endif /* GINAC_CHINREM_GCD_PRIMES_FACTORY_H */