summaryrefslogtreecommitdiffstats
path: root/libtommath/bn_mp_radix_size.c
diff options
context:
space:
mode:
authorKevin B Kenny <kennykb@acm.org>2005-04-10 23:54:55 (GMT)
committerKevin B Kenny <kennykb@acm.org>2005-04-10 23:54:55 (GMT)
commit9c989aeec930a9251ba5eddc6a81898a5c91ee0e (patch)
tree8809a65920a763a8894572aee81a71eeff4b2c82 /libtommath/bn_mp_radix_size.c
parent2168824a1ddf134001dd68311befeb7d58dddd38 (diff)
downloadtcl-9c989aeec930a9251ba5eddc6a81898a5c91ee0e.zip
tcl-9c989aeec930a9251ba5eddc6a81898a5c91ee0e.tar.gz
tcl-9c989aeec930a9251ba5eddc6a81898a5c91ee0e.tar.bz2
Import of tommath 0.35
Diffstat (limited to 'libtommath/bn_mp_radix_size.c')
-rw-r--r--libtommath/bn_mp_radix_size.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/libtommath/bn_mp_radix_size.c b/libtommath/bn_mp_radix_size.c
index 30b78d9..3d423ba 100644
--- a/libtommath/bn_mp_radix_size.c
+++ b/libtommath/bn_mp_radix_size.c
@@ -35,22 +35,29 @@ int mp_radix_size (mp_int * a, int radix, int *size)
return MP_VAL;
}
- /* init a copy of the input */
- if ((res = mp_init_copy (&t, a)) != MP_OKAY) {
- return res;
+ if (mp_iszero(a) == MP_YES) {
+ *size = 2;
+ return MP_OKAY;
}
/* digs is the digit count */
digs = 0;
/* if it's negative add one for the sign */
- if (t.sign == MP_NEG) {
+ if (a->sign == MP_NEG) {
++digs;
- t.sign = MP_ZPOS;
}
+ /* init a copy of the input */
+ if ((res = mp_init_copy (&t, a)) != MP_OKAY) {
+ return res;
+ }
+
+ /* force temp to positive */
+ t.sign = MP_ZPOS;
+
/* fetch out all of the digits */
- while (mp_iszero (&t) == 0) {
+ while (mp_iszero (&t) == MP_NO) {
if ((res = mp_div_d (&t, (mp_digit) radix, &t, &d)) != MP_OKAY) {
mp_clear (&t);
return res;