Exemplo n.º 1
0
lispval
Lminus()
{
	register lispval arg1, handy;
	lispval subbig();

	chkarg(1,"minus");
	arg1 = lbot->val;
	handy = nil;
	switch(TYPE(arg1)) {
	case INT:
		handy= inewint(0 - arg1->i);
		break;
	case DOUB:
		handy = newdoub();
		handy->r = -arg1->r;
		break;
	case SDOT: { struct sdot dummyb;
		handy = (lispval) &dummyb;
		handy->s.I = 0;
		handy->s.CDR = (lispval) 0;
		handy = subbig(handy,arg1);
		break; }

	default:
		error("non-numeric argument",FALSE);
	}
	return(handy);
}
Exemplo n.º 2
0
void egcdbig(int *a,int *b,int *d,int *x,int *xf,int *y,int *yf)
{
	static BG z[2000];
	static BG t;
	int f,now;
	now=++C;
	if(iszero(b)){cpybig(d,a);x[0]=x[1]=y[0]=1;y[1]=0;*xf=*yf=0;return;}
	divmodbig(a,b,z[now]);
	egcdbig(b,a,d,x,xf,y,yf);
	mulbig(z[now],y,t);
	cpybig(z[now],y);
	f=*yf;
	if(*xf==0 && *yf==0)
	{
		if(cmpbig(x,t)>=0)
			subbig(x,t,y);
		else
		{
			subbig(t,x,y);
			*yf=1;
		}
	}
	else if(*xf==0 && *yf==1)
	{
		addbig(x,t,y);
		*yf=0;
	}
	else if(*xf==1 && *yf==0)
	{
		addbig(x,t,y);
		*yf=1;
	}
	else if(*xf==1 && *yf==1)
	{
		if(cmpbig(x,t)>0)
			subbig(x,t,y);
		else
		{
			subbig(t,x,y);
			*yf=0;
		}
	}
	cpybig(x,z[now]);
	*xf=f;
}