Mark Roberts wrote:
> mjr::mjr$ gcj --main=Test -o test BigInteger.java Test.java ; ./test
> -193777487871550603802886620051223065684360061219665906255308989122864946160997365672261816618860360252622577515551548542184701363470270624007177647259538860643091504310327081344962114919427392852996299736514123723159307151561050854215732124890528507748420958460751229013619680798445437564005061662750554072049469772786792714325591967543809251820954350423827422639100041962237582007598963943407454570694092539420011326781748166365585036273383824881872855
> mjr::mjr$ javac Test.java ; java -cp . Test
> 367417105895394016159154787313270662212024192865627354929903779273790475448015789586251477566499147933827828993175451736204011419593248732059558975428536352923147799454938474886826728465908014291590615212928094348062380180678090626190405785338510862566219882367271848354528305975332648128732693695418736716973797590695732844596436204184266800584120723714967834374864490790434309625243649395288704661308708314268453615305198754248602412105555586454917161
I think I see the problem on this one. The bignum package stores values
in two's complement form. That means that if the high bit on the high
word is set, the value is considered negative. When you need to store a
value which has its high bit set (which is the case with the answer here)
you need to store another word of zero beyond the high bit. I.e. instead
of storing 0x87654321, you store 0x00000000, 0x87654321 and it is clear
that it is positive.
In this case the remainder value is not being set with this assurance.
At line 858 it does
remainder.set(ywords, rlen);
where rlen is copied from ylen. Initially ylen counts the leading zero,
but it will be decremented at line 742. So ylen is one too small in this
case and the remainder looks negative.
I think the fix would be to change the remainder.set line to:
if (ywords[rlen-1] < 0)
{
ywords[rlen] = 0;
remainder.set(ywords, rlen+1);
}
else
{
remainder.set(ywords, rlen);
}
This will make sure that remainder is set positive.
Hal
_______________________________________________
Devl mailing list
Devl at freenetproject.org
http://www.uprizer.com/mailman/listinfo/devl