Skip to content

Commit

Permalink
Fix \< for equal but not identical large integers
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed May 30, 2019
1 parent 5fbcf2b commit 5d81b55
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/integer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1199,18 +1199,18 @@ Int LtInt(Obj opL, Obj opR)

/* signs are equal; compare sizes and absolute values */
if (SIZE_INT(opL) < SIZE_INT(opR))
res = 1;
res = -1;
else if (SIZE_INT(opL) > SIZE_INT(opR))
res = 0;
res = +1;
else
res = mpn_cmp((mp_srcptr)CONST_ADDR_INT(opL),
(mp_srcptr)CONST_ADDR_INT(opR), SIZE_INT(opL)) < 0;
(mp_srcptr)CONST_ADDR_INT(opR), SIZE_INT(opL));

/* if both arguments are negative, flip the result */
if (IS_INTNEG(opL))
res = !res;
res = -res;

return res;
return res < 0;
}


Expand Down
14 changes: 13 additions & 1 deletion tst/testinstall/intarith.tst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#@local POWERMODINT_GAP,b,bigPos,bigNeg,checkPValuationInt,data,dataHex
#@local dataInv,dataNonZero,e,f,g,i,k,m,mysource,pow,r,smlNeg,smlPos,x,y
#@local naivQM,ps,checkROOT_INT,P,a,n,p
#@local naivQM,ps,checkROOT_INT,P,a,n,p,x1,x2
gap> START_TEST("intarith.tst");
gap> 1 + 1;
2
Expand Down Expand Up @@ -70,6 +70,18 @@ gap> List(data, x -> smlPos = x);
gap> List(data, x -> bigPos = x);
[ false, false, false, false, false, false, false, true, false ]

# Check for < on equal, but not identical large numbers
# See issue #3474
gap> x1 := 2^80;; x2 := 2^80;;
gap> x1 < x2;
false
gap> x1 = x2;
true
gap> -x1 < -x2;
false
gap> -x1 = -x2;
true

# check symmetry
gap> ForAll(data, x -> ForAll(data, y -> (x=y) = (y=x)));
true
Expand Down

0 comments on commit 5d81b55

Please sign in to comment.