BSD 3 development
[unix-history] / usr / src / cmd / lisp / pbignum.c
CommitLineData
18d1c3cd
JF
1#include "global.h"
2
3pbignum(current, useport)
4register lispval current;
5register FILE *useport;
6{
7 int *top, *bot, *work, negflag = 0, *sp(), *alloca();
8 register int *digitp, *binp;
9 register lispval last;
10
11 /* copy bignum onto stack */
12 top = sp() - 1;
13 do {
14 stack(current->I);
15 } while(current = current->CDR);
16
17 bot = sp();
18 if (top==bot) {
19 fprintf(useport,"%d",*bot);
20 return;
21 }
22
23 /* save space for printed digits*/
24 work = alloca((top-bot)*2*sizeof(int));
25 if( *bot < 0) {
26 negflag = 1;
27 dsneg(top,bot);
28 }
29
30 /* figure out nine digits at a time by destructive division*/
31 for(digitp = work; bot <= top; digitp++) {
32 *digitp = dodiv(top,bot);
33 if(*bot==0) bot += 1;
34 }
35
36 /* print them out */
37
38 if(negflag) putc('-',useport);
39 fprintf(useport,"%d",*--digitp);
40 while ( digitp > work) fprintf(useport,"%09d",*--digitp);
41}