From 86fe5cfe4de95a44b949db9be105e78497318804 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 14 Jun 2011 13:57:33 -0700 Subject: [PATCH] * fns.c (next_almost_prime): Don't return a multiple of 3 or 5. The previous code was bogus. For example, next_almost_prime (32) returned 39, which is undesirable as it is a multiple of 3; and next_almost_prime (24) returned 25, which is a multiple of 5 so why was the code bothering to check for multiples of 7? --- src/ChangeLog | 6 ++++++ src/fns.c | 10 +++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 54fe58d1118..7bd1d47b328 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,11 @@ 2011-06-14 Paul Eggert + * fns.c (next_almost_prime): Don't return a multiple of 3 or 5. + The previous code was bogus. For example, next_almost_prime (32) + returned 39, which is undesirable as it is a multiple of 3; and + next_almost_prime (24) returned 25, which is a multiple of 5 so + why was the code bothering to check for multiples of 7? + * bytecode.c (exec_byte_code): Use ptrdiff_t, not int, for vector length. * eval.c, doprnt.c (SIZE_MAX): Remove; inttypes.h defines this now. diff --git a/src/fns.c b/src/fns.c index 0e98a8d3425..333a75ac2b2 100644 --- a/src/fns.c +++ b/src/fns.c @@ -3379,13 +3379,9 @@ check_hash_table (Lisp_Object obj) EMACS_INT next_almost_prime (EMACS_INT n) { - if (n % 2 == 0) - n += 1; - if (n % 3 == 0) - n += 2; - if (n % 7 == 0) - n += 4; - return n; + for (n |= 1; ; n += 2) + if (n % 3 != 0 && n % 5 != 0 && n % 7 != 0) + return n; } -- 2.39.2