Mercurial > dropbear
comparison bn_mp_radix_size.c @ 190:d8254fc979e9 libtommath-orig LTM_0.35
Initial import of libtommath 0.35
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 06 May 2005 08:59:30 +0000 |
parents | d29b64170cf0 |
children |
comparison
equal
deleted
inserted
replaced
142:d29b64170cf0 | 190:d8254fc979e9 |
---|---|
33 /* make sure the radix is in range */ | 33 /* make sure the radix is in range */ |
34 if (radix < 2 || radix > 64) { | 34 if (radix < 2 || radix > 64) { |
35 return MP_VAL; | 35 return MP_VAL; |
36 } | 36 } |
37 | 37 |
38 /* init a copy of the input */ | 38 if (mp_iszero(a) == MP_YES) { |
39 if ((res = mp_init_copy (&t, a)) != MP_OKAY) { | 39 *size = 2; |
40 return res; | 40 return MP_OKAY; |
41 } | 41 } |
42 | 42 |
43 /* digs is the digit count */ | 43 /* digs is the digit count */ |
44 digs = 0; | 44 digs = 0; |
45 | 45 |
46 /* if it's negative add one for the sign */ | 46 /* if it's negative add one for the sign */ |
47 if (t.sign == MP_NEG) { | 47 if (a->sign == MP_NEG) { |
48 ++digs; | 48 ++digs; |
49 t.sign = MP_ZPOS; | |
50 } | 49 } |
51 | 50 |
51 /* init a copy of the input */ | |
52 if ((res = mp_init_copy (&t, a)) != MP_OKAY) { | |
53 return res; | |
54 } | |
55 | |
56 /* force temp to positive */ | |
57 t.sign = MP_ZPOS; | |
58 | |
52 /* fetch out all of the digits */ | 59 /* fetch out all of the digits */ |
53 while (mp_iszero (&t) == 0) { | 60 while (mp_iszero (&t) == MP_NO) { |
54 if ((res = mp_div_d (&t, (mp_digit) radix, &t, &d)) != MP_OKAY) { | 61 if ((res = mp_div_d (&t, (mp_digit) radix, &t, &d)) != MP_OKAY) { |
55 mp_clear (&t); | 62 mp_clear (&t); |
56 return res; | 63 return res; |
57 } | 64 } |
58 ++digs; | 65 ++digs; |