diff --git a/src/integer.c b/src/integer.c index b34d6c382b..f35b2cae42 100644 --- a/src/integer.c +++ b/src/integer.c @@ -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; } diff --git a/tst/testinstall/intarith.tst b/tst/testinstall/intarith.tst index af5c5a3281..fdaa556acd 100644 --- a/tst/testinstall/intarith.tst +++ b/tst/testinstall/intarith.tst @@ -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 @@ -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