1 // Convert bignum to string
6 static int divby1billion(unsigned int *);
18 str
= (char *) malloc(1000);
22 // estimate string size
24 n
= 10 * MLENGTH(a
) + 2;
28 str
= (char *) malloc(n
);
44 sprintf(str
+ k
, "%09d", r
);
50 // remove leading zeroes
70 // Returns remainder as function value, quotient returned in a.
73 divby1billion(unsigned int *a
)
76 unsigned long long kk
;
80 for (i
= MLENGTH(a
) - 1; i
>= 0; i
--) {
82 if (little_endian()) {
83 ((unsigned int *) &kk
)[1] = ((unsigned int *) &kk
)[0];
84 ((unsigned int *) &kk
)[0] = a
[i
];
86 ((unsigned int *) &kk
)[0] = ((unsigned int *) &kk
)[1];
87 ((unsigned int *) &kk
)[1] = a
[i
];
90 a
[i
] = (int) (kk
/ 1000000000);
92 kk
-= (unsigned long long) 1000000000 * a
[i
];
97 for (i
= MLENGTH(a
) - 1; i
> 0; i
--)
104 return ((unsigned int *) &kk
)[0];
106 return ((unsigned int *) &kk
)[1];