From: jbj Date: Thu, 24 Apr 2003 23:02:35 +0000 (+0000) Subject: fix: 15^8 had sign problems in intermediate. X-Git-Tag: rpm-4.4-release~588 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d55b8e03bc4ae98674595bb5cac6804c358cb80f;p=platform%2Fupstream%2Frpm.git fix: 15^8 had sign problems in intermediate. CVS patchset: 6771 CVS date: 2003/04/24 23:02:35 --- diff --git a/python/bc.py b/python/bc.py index 635344b..6dc78c9 100644 --- a/python/bc.py +++ b/python/bc.py @@ -8,7 +8,7 @@ i = 1 for i in range(30): a = rpm.bc(i) - for j in range(48): + for j in range(100): b = rpm.bc(j) print i, '^', j, '=', rpm.bc.__pow__(a, b) diff --git a/python/rpmbc-py.c b/python/rpmbc-py.c index 461be61..41003b0 100644 --- a/python/rpmbc-py.c +++ b/python/rpmbc-py.c @@ -691,12 +691,11 @@ static void mp32npow_w(mp32number* n, uint32 xsize, const uint32* xdata, { uint32 xbits = mp32bitcnt(xsize, xdata); uint32 pbits = mp32bitcnt(psize, pdata); + uint32 nbits; uint32 *slide; uint32 nsize; uint32 size; - assert(pbits < 16); - /* Special case X**0 */ if (pbits == 0) { mp32nsetw(n, 1); @@ -705,17 +704,19 @@ static void mp32npow_w(mp32number* n, uint32 xsize, const uint32* xdata, /* Other special cases, like X**1 */ -if (_bc_debug) -fprintf(stderr, "*** before %p[%d]\n", pdata, psize); /* Normalize (to uint32 boundary) exponent. */ pdata += psize - ((pbits+31)/32); psize -= (pbits/32); -if (_bc_debug) -fprintf(stderr, "*** after %p[%d]\n", pdata, psize); /* Calculate size of result. */ if (xbits == 0) xbits = 1; - nsize = (((*pdata) * xbits) + 31)/32 + 1; /* 1 word for sign bit */ + nbits = (*pdata) * xbits; + nsize = (nbits + 31)/32; + + /* XXX Add 1 word to carry sign bit */ + if (!mp32msbset(xsize, xdata) && (nbits & (32 -1)) == 0) + nsize++; + size = ((15 * xbits)+31)/32; if (_bc_debug) @@ -831,6 +832,11 @@ static int rpmbc_init(rpmbcObject * z, PyObject *args, PyObject *kwds) const unsigned char * hex = PyString_AsString(o); /* XXX TODO: check for hex. */ mp32nsethex(&z->n, hex); + } else if (is_rpmbc(o)) { + rpmbcObject *a = (rpmbcObject *)o; + mp32nsize(z, a->n.size); + if (a->n.size > 0) + mp32setx(z->n.size, z->n.data, a->n.size, a->n.data); } else { PyErr_SetString(PyExc_TypeError, "non-numeric coercion failed (rpmbc_init)"); return -1;