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);


_______________________________________________
Bug-prolog mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-prolog

Reply via email to