1 /* TomsFastMath, a fast ISO C bignum library.
3 * This project is meant to fill in where LibTomMath
4 * falls short. That is speed ;-)
6 * This project is public domain and free for all purposes.
8 * Tom St Denis, tomstdenis@gmail.com
10 #include <tfm_private.h>
12 int fp_toradix_n(fp_int *a, char *str, int radix, int maxlen)
19 /* check range of the radix */
20 if (maxlen < 2 || radix < 2 || radix > 64)
23 /* quick check for zero */
24 if (fp_iszero(a) == FP_YES) {
32 /* if it is negative output a - */
33 if (t.sign == FP_NEG) {
34 /* we have to reverse our digits later... but not the - sign!! */
37 /* store the flag and mark the number as positive */
46 while (fp_iszero (&t) == FP_NO) {
51 fp_div_d(&t, (fp_digit) radix, &t, &d);
52 *str++ = fp_s_rmap[d];
56 /* reverse the digits of the string. In this case _s points
57 * to the first digit [exluding the sign] of the number]
59 fp_reverse((unsigned char *) _s, digs);
61 /* append a NULL so the string is properly terminated */