Print positive numbers only.
Add extra word for sign bit. CVS patchset: 6767 CVS date: 2003/04/24 12:23:30
This commit is contained in:
parent
d832d12330
commit
de92f6ba0e
|
@ -355,12 +355,16 @@ rpmbc_format(rpmbcObject * z, uint32 zbase, int withname)
|
||||||
char * te;
|
char * te;
|
||||||
char prefix[5];
|
char prefix[5];
|
||||||
char * tcp = prefix;
|
char * tcp = prefix;
|
||||||
|
uint32 zsign;
|
||||||
|
|
||||||
if (z == NULL || !is_rpmbc(z)) {
|
if (z == NULL || !is_rpmbc(z)) {
|
||||||
PyErr_BadInternalCall();
|
PyErr_BadInternalCall();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_bc_debug)
|
||||||
|
fprintf(stderr, "*** rpmbc_format(%p,%d,%d):\t", z, zbase, withname), mp32println(stderr, z->n.size, z->n.data);
|
||||||
|
|
||||||
assert(zbase >= 2 && zbase <= 36);
|
assert(zbase >= 2 && zbase <= 36);
|
||||||
|
|
||||||
if (withname)
|
if (withname)
|
||||||
|
@ -368,18 +372,25 @@ rpmbc_format(rpmbcObject * z, uint32 zbase, int withname)
|
||||||
else
|
else
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
/* XXX FIXME: mp32bitcnt normalize with signed values. */
|
zsign = mp32msbset(z->n.size, z->n.data);
|
||||||
nt = mp32mszcnt(z->n.size, z->n.data)/32;
|
nt = mp32bitcnt(z->n.size, z->n.data);
|
||||||
zsize = z->n.size - nt;
|
if (nt == 0) {
|
||||||
zdata = z->n.data + nt;
|
|
||||||
|
|
||||||
if (mp32z(zsize, zdata))
|
|
||||||
zbase = 10; /* '0' in every base, right */
|
zbase = 10; /* '0' in every base, right */
|
||||||
else if (mp32msbset(zsize, zdata)) {
|
nt = 1;
|
||||||
|
zsize = 1;
|
||||||
|
zdata = &zsign;
|
||||||
|
} else if (zsign) {
|
||||||
*tcp++ = '-';
|
*tcp++ = '-';
|
||||||
i += 1; /* space to hold '-' */
|
i += 1; /* space to hold '-' */
|
||||||
|
zsize = (nt + 31)/32;
|
||||||
|
zdata = alloca(zsize * sizeof(*zdata));
|
||||||
|
mp32setx(zsize, zdata, zsize, z->n.data + (z->n.size - zsize));
|
||||||
|
mp32neg(zsize, zdata);
|
||||||
|
} else {
|
||||||
|
zsize = (nt + 31)/32;
|
||||||
|
zdata = z->n.data + (z->n.size - zsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
nt = mp32sizeinbase(zsize, zdata, zbase);
|
nt = mp32sizeinbase(zsize, zdata, zbase);
|
||||||
i += nt;
|
i += nt;
|
||||||
|
|
||||||
|
@ -678,7 +689,7 @@ fprintf(stderr, "*** after %p[%d]\n", pdata, psize);
|
||||||
|
|
||||||
/* Calculate size of result. */
|
/* Calculate size of result. */
|
||||||
if (xbits == 0) xbits = 1;
|
if (xbits == 0) xbits = 1;
|
||||||
nsize = (((*pdata) * xbits)+31)/32;
|
nsize = (((*pdata) * xbits) + 31)/32 + 1; /* 1 word for sign bit */
|
||||||
size = ((15 * xbits)+31)/32;
|
size = ((15 * xbits)+31)/32;
|
||||||
|
|
||||||
if (_bc_debug)
|
if (_bc_debug)
|
||||||
|
|
Loading…
Reference in New Issue