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>
28 m_add(MINT
*a
, MINT
*b
, MINT
*c
)
34 cval
= _mp_xalloc(a
->len
+ 1, "m_add");
36 for (i
= 0; i
< b
->len
; i
++) {
37 x
= carry
+ a
->val
[i
] + b
->val
[i
];
40 cval
[i
] = (short)(x
& 077777);
46 for (; i
< a
->len
; i
++) {
47 x
= carry
+ a
->val
[i
];
49 cval
[i
] = (short)(x
& 077777);
68 mp_madd(MINT
*a
, MINT
*b
, MINT
*c
)
100 c
->len
= sign
* c
->len
;
106 m_sub(MINT
*a
, MINT
*b
, MINT
*c
)
116 c
->val
= _mp_xalloc(a
->len
, "m_sub");
118 for (i
= 0; i
< b
->len
; i
++) {
119 x
= borrow
+ a
->val
[i
] - b
->val
[i
];
122 c
->val
[i
] = (short)(x
& 077777);
125 c
->val
[i
] = (short)x
;
128 for (; i
< a
->len
; i
++) {
129 x
= borrow
+ a
->val
[i
];
131 c
->val
[i
] = (short)(x
& 077777);
134 c
->val
[i
] = (short)x
;
138 for (i
= 0; i
< a
->len
; i
++) {
142 mp_madd(c
, &mone
, c
);
144 for (i
= a
->len
-1; i
>= 0; --i
) {
158 mp_msub(MINT
*a
, MINT
*b
, MINT
*c
)
170 if (x
.len
>= y
.len
) {
191 c
->len
= sign
* c
->len
;