1
/* TomsFastMath, a fast ISO C bignum library.
2
* That project is public domain and free for all purposes.
3
* fp_toradix_n included in TomsFastMath specification (tfm.h), but unimplemented until now.
4
* It is based on conversion of mp_toradix_n from libtommath
5
* Will send the body of this function back to the LibTom projects, if they want it
7
#include "bignum_fast.h"
9
int fp_toradix_n(fp_int *a, char *str, int radix, int maxlen)
16
/* check range of the maxlen, radix */
17
if (maxlen < 2 || radix < 2 || radix > 64) {
21
/* quick out if its zero */
22
if (fp_iszero(a) == 1) {
30
/* if it is negative output a - */
31
if (t.sign == FP_NEG) {
39
while (fp_iszero (&t) == FP_NO) {
44
fp_div_d (&t, (fp_digit) radix, &t, &d);
45
*str++ = fp_s_rmap[d];
49
/* reverse the digits of the string. In this case _s points
50
* to the first digit [exluding the sign] of the number]
52
fp_reverse ((unsigned char *)_s, digs);
54
/* append a NULL so the string is properly terminated */