The class RandomFFTPrime has a method randomPrime taking k as parameter and returning a prime such that p-1 is divisible by 2^k.
The constructor of the class RandomFFTPrime has a parameter pbound.
One could expected that the prime returned by an instance of this class initialized with pbound=2^b returns a random prime less than 2^b but it is not the case.
I wrote the simple test below. With the two following sets of arguments, it returns a prime that is larger than 2^b:
-b 27 -k 16 -s 42 : the test program returns 2^27 + 33554433
-b 16 -k 15 : the test program returns 2^16+1
The second case is more annoying. Let's assume I want a prime less than 16 bits in order to perform the FFT with Modular<uint16_t, uint32_t>.
Calling RandomFFTPrime(1<<16).randomPrime (15) returns 2^16+1 which does not fit in an uint16_t.
[ Note that there is no prime p less than 2^16 such that 2^15 | p-1, the function fails to detected this but this is another problem].
After reading the code, it seems that, given pbound as parameter, the actual bound is 2^floor(log_2(pbound)). So with pbound=2^b the actual bound is 2^(b+1).
Another problem is the fact that if k>=b (in the clear case where there is no solution) and that the code is compile with -NDEBUG, the method randomPrime fails with a Floating point exception. It would be better to raise a more explicit exception or to return 0 (instead of a prime).
Finally, if the code is compile with -NDEBUG (this implies that the linbox_check macro is an empty macro), the method randomPrime could return a non prime without any indication that it fails to find a prime.
The class
RandomFFTPrime
has a methodrandomPrime
taking k as parameter and returning a prime such that p-1 is divisible by 2^k. The constructor of the classRandomFFTPrime
has a parameterpbound
. One could expected that the prime returned by an instance of this class initialized withpbound=2^b
returns a random prime less than2^b
but it is not the case. I wrote the simple test below. With the two following sets of arguments, it returns a prime that is larger than2^b
:2^27 + 33554433
2^16+1
The second case is more annoying. Let's assume I want a prime less than 16 bits in order to perform the FFT with
Modular<uint16_t, uint32_t>
. CallingRandomFFTPrime(1<<16).randomPrime (15)
returns2^16+1
which does not fit in anuint16_t
. [ Note that there is no primep
less than2^16
such that2^15 | p-1
, the function fails to detected this but this is another problem].After reading the code, it seems that, given
pbound
as parameter, the actual bound is2^floor(log_2(pbound))
. So withpbound=2^b
the actual bound is2^(b+1)
.Another problem is the fact that if
k>=b
(in the clear case where there is no solution) and that the code is compile with-NDEBUG
, the methodrandomPrime
fails with aFloating point exception
. It would be better to raise a more explicit exception or to return 0 (instead of a prime).Finally, if the code is compile with
-NDEBUG
(this implies that thelinbox_check
macro is an empty macro), the method randomPrime could return a non prime without any indication that it fails to find a prime.Code used for testing: