diff options
author | Kevin B Kenny <kennykb@acm.org> | 2005-04-10 23:54:55 (GMT) |
---|---|---|
committer | Kevin B Kenny <kennykb@acm.org> | 2005-04-10 23:54:55 (GMT) |
commit | 163b211fb73a0d795aa73236805b5b97386dd4f3 (patch) | |
tree | 99103342350cd1fb4776a60684221ad722fdec52 /libtommath/bn_mp_radix_size.c | |
parent | 8df47fab3cdd02f03283e22c2b2226f0fe7a2ab4 (diff) | |
download | tcl-163b211fb73a0d795aa73236805b5b97386dd4f3.zip tcl-163b211fb73a0d795aa73236805b5b97386dd4f3.tar.gz tcl-163b211fb73a0d795aa73236805b5b97386dd4f3.tar.bz2 |
Import of tommath 0.35
Diffstat (limited to 'libtommath/bn_mp_radix_size.c')
-rw-r--r-- | libtommath/bn_mp_radix_size.c | 19 |
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; |