/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*/
/* Portions Copyright(c) 1988, Sun Microsystems Inc. */
/* All Rights Reserved */
/*
* Copyright (c) 1997, by Sun Microsystems, Inc.
* All rights reserved.
*/
#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
/* LINTLIBRARY */
#include <mp.h>
#include "libmp.h"
#include <stdlib.h>
static void
{
int carry, i;
int x;
short *cval;
carry = 0;
for (i = 0; i < b->len; i++) {
if (x & 0100000) {
carry = 1;
cval[i] = (short)(x & 077777);
} else {
carry = 0;
cval[i] = (short)x;
}
}
for (; i < a->len; i++) {
if (x & 0100000) {
cval[i] = (short)(x & 077777);
} else {
carry = 0;
cval[i] = (short)x;
}
}
if (carry == 1) {
cval[i] = 1;
c->len = i + 1;
} else {
}
if (c->len == 0) {
}
}
void
{
MINT x, y;
int sign;
_mp_move(a, &x);
_mp_move(b, &y);
_mp_xfree(c);
sign = 1;
if (x.len >= 0) {
if (y.len >= 0) {
m_add(&x, &y, c);
} else {
m_add(&y, &x, c);
}
} else {
mp_msub(&x, &y, c);
}
} else {
if (y.len <= 0) {
sign = -1;
mp_madd(&x, &y, c);
} else {
mp_msub(&y, &x, c);
}
}
_mp_xfree(&x);
_mp_xfree(&y);
}
static void
{
int x, i;
int borrow;
short one;
one = 1;
borrow = 0;
for (i = 0; i < b->len; i++) {
if (x & 0100000) {
borrow = -1;
c->val[i] = (short)(x & 077777);
} else {
borrow = 0;
c->val[i] = (short)x;
}
}
for (; i < a->len; i++) {
if (x & 0100000) {
c->val[i] = (short)(x & 077777);
} else {
borrow = 0;
c->val[i] = (short)x;
}
}
if (borrow < 0) {
for (i = 0; i < a->len; i++) {
c->val[i] ^= 077777;
}
}
for (i = a->len-1; i >= 0; --i) {
if (c->val[i] > 0) {
if (borrow == 0) {
c->len = i + 1;
} else {
c->len = -i - 1;
}
return;
}
}
}
void
{
MINT x, y;
int sign;
_mp_move(a, &x);
_mp_move(b, &y);
_mp_xfree(c);
sign = 1;
if (x.len >= 0) {
if (y.len >= 0) {
m_sub(&x, &y, c);
} else {
sign = -1;
mp_msub(&y, &x, c);
}
} else {
mp_madd(&x, &y, c);
}
} else {
if (y.len <= 0) {
mp_msub(&y, &x, c);
} else {
mp_madd(&x, &y, c);
sign = -1;
}
}
_mp_xfree(&x);
_mp_xfree(&y);
}