chiark / gitweb /
math/pfilt.c (pfilt_jump): Fix off-by-one error in reduction.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 26 Jun 2016 10:44:36 +0000 (11:44 +0100)
commita28748f8e0b2a820666b72f4a022cba19ba70c51
tree0a40f9c5d4d06f350d0415ea015c09d711f2f78f
parent998e6c3d87d35a8728b46985b2f7c220cec21963
math/pfilt.c (pfilt_jump): Fix off-by-one error in reduction.

Oh, dear.  This is quite a bad one.  The loop added the residues for the
jump to the candidate, and reduced each if the result was strictly
higher than the modulus.  It then reports failure (or immediate success)
if any residue is zero, otherwise reporting a candidate for subsequent
testing.  Obviously, this is a stupid bug, with the result that,
effectively, every step reports a candidate for further testing.

This bug has two bad consequences.

  * Candidates with small factors aren't weeded out, so prime searching
    takes an unnecessarily long time.  I'd spotted this, but didn't have
    a way in to investigate the problem.

  * Candidates which actually have small factors, but are in fact below
    the `smallenough' threshold, are reported as being verified as
    prime, so the overall procedure erroneously returns known
    composites.
math/pfilt.c