PATCH: Fix sorting problem
Peter Collingbourne <[email protected]>
| Newsgroups | gmane.comp.gnu.prolog.bugs |
|---|---|
| Message-ID | <[email protected]> |
Hello
I've found a problem with the sort/2 (and others) predicate in GProlog.
This problem occurs in 1.2.16, as well as the latest unstable version.
The problem occurs when you try to sort a list containing a negative
number:
| ?- sort([-1,1,2,3],X).
X = [1,2,3,-1]
CLearly the -1 is out of place. I did some investigation and found the
underlying problem was in the Term_Compare function in
BipsPl/term_supp.c. Apparently UnTag_INT is not being called on the
arguments when they are compared. Here is a patch to solve the problem:
--- term_supp.c.old 2004-05-28 11:23:42.000000000 +0100
+++ term_supp.c 2004-05-28 11:51:26.000000000 +0100
@@ -126,7 +126,7 @@
v_tag == FLT)
return 1;
- return (v_tag != INT) ? -1 : u_word - v_word;
+ return (v_tag != INT) ? -1 : UnTag_INT(u_word) - UnTag_INT(v_word);
case ATM:
if (v_tag == REF ||
--
Peter