1 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
2 /* All Rights Reserved */
6 * Copyright (c) 1980 Regents of the University of California.
7 * All rights reserved. The Berkeley software License Agreement
8 * specifies the terms and conditions for redistribution.
10 /* Portions Copyright(c) 1988, Sun Microsystems Inc. */
11 /* All Rights Reserved */
14 * Copyright (c) 1997, by Sun Microsystems, Inc.
15 * All rights reserved.
18 #ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
24 #include <sys/types.h>
29 m_in(MINT
*a
, short b
, FILE *f
)
43 while ((c
= getc(f
)) != EOF
)
60 if (c
>= '0' && c
<= '9') {
67 (void) ungetc(c
, stdin
);
76 m_out(MINT
*a
, short b
, FILE *f
)
94 (void) fprintf(f
, "0\n");
98 x
.val
= _mp_xalloc(xlen
, "m_out");
99 for (i
= 0; i
< xlen
; i
++)
100 x
.val
[i
] = a
->val
[i
];
101 obuf
= malloc(7 * (size_t)xlen
);
102 bp
= obuf
+ 7 * xlen
- 1;
105 for (i
= 0; i
< 10 && x
.len
> 0; i
++) {
106 mp_sdiv(&x
, b
, &x
, &r
);
107 *bp
-- = (char)(r
+ '0');
114 (void) fprintf(f
, "%s\n", bp
+ 1);
119 static void s_div(MINT
*, short, MINT
*, short *);
122 mp_sdiv(MINT
*a
, short n
, MINT
*q
, short *r
)
141 q
->len
= sign
* y
.len
;
146 s_div(MINT
*a
, short n
, MINT
*q
, short *r
)
156 q
->val
= _mp_xalloc(qlen
, "s_div");
157 aval
= a
->val
+ qlen
;
158 qval
= q
->val
+ qlen
;
159 for (i
= qlen
- 1; i
>= 0; i
--) {
160 x
= x
* 0100000 + *--aval
;
161 *--qval
= (short)(x
/ n
);
165 if (qlen
&& q
->val
[qlen
-1] == 0)
175 return (m_in(a
, 10, stdin
));
181 return (m_in(a
, 8, stdin
));
187 m_out(a
, 10, stdout
);
197 mp_fmout(MINT
*a
, FILE *f
)
203 mp_fmin(MINT
*a
, FILE *f
)
205 return (m_in(a
, 10, f
));