gprolog mishandles 3 mod -1
Paul Eggert <[email protected]>
| Newsgroups | gmane.comp.gnu.prolog.bugs |
|---|---|
| Message-ID | <[email protected]> |
gprolog 1.2.16 (and 1.2.19) mishandle the evaluation of 3 mod -1: $ gprolog GNU Prolog 1.2.16 By Daniel Diaz Copyright (C) 1999-2002 Daniel Diaz | ?- N is 3 mod -1. N = -1 The correct answer is 0. Here's a proposed (albeit untested) patch. 2006-05-04 Paul Eggert <[email protected]> * src/BipsPl/arith_inl_c.c (Fct_Fast_Mod): Fix bug where A mod B was mishandled when B was negative and A was a multiple of B. --- src/BipsPl/arith_inl_c.c~ 2002-06-24 03:26:24.000000000 -0700 +++ src/BipsPl/arith_inl_c.c 2006-05-04 22:27:10.421012000 -0700 @@ -487,7 +487,7 @@ Fct_Fast_Mod(WamWord x, WamWord y) m = vx % vy; - if ((m ^ vy) < 0) /* have m and vy different signs ? */ + if (m != 0 && (m ^ vy) < 0) /* have m and vy different signs ? */ m += vy; return Tag_INT(m);