Exemple #1
0
void instructions_tests() {
	/* 32 bit copy */
	setl(42, eax);
	assert(*(int32_t *)eax == 42);
	setl(1000000, eax);
	assert(*(int32_t *)eax == 1000000);
	movl(eax, edx);
	assert(*(int32_t *)edx == 1000000);

	/* addition */
	setl(3, eax);
	setl(5, edx);
	addl(edx, eax);
	assert(*(int32_t *)eax == 8);

	/* division */
	setl(15, eax);
	setl(5, edx);
	divl(edx, eax);
	assert(*(int32_t *)eax == 3);

	/* multiplication */
	setl(3, eax);
	setl(5, edx);
	mull(edx, eax);
	assert(*(int32_t *)eax == 15);

	/* subtraction */
	setl(3, eax);
	setl(5, edx);
	subl(edx, eax);
	assert(*(int32_t *)eax == -2);
}
//**********(G-4)*********************
largeInt add_primes(largeInt min,largeInt max) //store all prime no.s ranging (>min && <=max) and return last prime no. added to the file
{
	//largeNum nmin,nmax,ntemp,nptemp;
	largeInt itemp,iptemp,irem,lprime,zero;
	div_result temp_result;
	fp=fopen("prime_tab.txt","r+");
	zero.sign=0;
	zero.len=1;
	zero.line[0]='0';

	lprime=zero;
	
	iptemp=increment1(min);
	
	printf("\n");
	while(greaterthan(max,iptemp)==1)
	{
		rewind(fp);
		itemp=freadI(fp);
		
		while(!feof(fp))
		{
			temp_result=divl(iptemp,itemp);
			if(Nequal_to_zero(temp_result.rem)==1)
			{
				break;
			}
			itemp=freadI(fp);
			if(feof(fp)==1)
			{
				fwriteI(iptemp,fp);
				lprime=iptemp;
			}
		}
		iptemp=increment1(iptemp);
	}
	return(lprime);
	
}
Exemple #3
0
long double
tanhl(long double x)
{
	long double hi,lo,s,x2,x4,z;
	double dx2;
	int16_t jx,ix;

	GET_LDBL_EXPSIGN(jx,x);
	ix = jx&0x7fff;

    /* x is INF or NaN */
	if(ix>=0x7fff) {
	    if (jx>=0) return one/x+one;    /* tanh(+-inf)=+-1 */
	    else       return one/x-one;    /* tanh(NaN) = NaN */
	}

	ENTERI();

    /* |x| < 40 */
	if (ix < 0x4004 || fabsl(x) < 40) {	/* |x|<40 */
	    if (__predict_false(ix<BIAS-(LDBL_MANT_DIG+1)/2)) {	/* |x|<TINY */
		/* tanh(+-0) = +0; tanh(tiny) = tiny(-+) with inexact: */
		return (x == 0 ? x : (0x1p200 * x - x) * 0x1p-200);
	    }
	    if (ix<0x3ffd) {		/* |x|<0.25 */
		x2 = x*x;
#if LDBL_MANT_DIG == 64
		x4 = x2*x2;
		RETURNI(((T19*x2 + T17)*x4 + (T15*x2 + T13))*(x2*x*x2*x4*x4) +
		    ((T11*x2 + T9)*x4 + (T7*x2 + T5))*(x2*x*x2) +
		    T3*(x2*x) + x);
#elif LDBL_MANT_DIG == 113
		dx2 = x2;
#if 0
		RETURNI(((((((((((((((T33*dx2 + T31)*dx2 + T29)*dx2 + T27)*dx2 +
		    T25)*x2 + T23)*x2 + T21)*x2 + T19)*x2 + T17)*x2 +
		    T15)*x2 + T13)*x2 + T11)*x2 + T9)*x2 + T7)*x2 + T5)*
		    (x2*x*x2) +
		    T3*(x2*x) + x);
#else
		long double q = ((((((((((((((T33*dx2 + T31)*dx2 + T29)*dx2 + T27)*dx2 +
		    T25)*x2 + T23)*x2 + T21)*x2 + T19)*x2 + T17)*x2 +
		    T15)*x2 + T13)*x2 + T11)*x2 + T9)*x2 + T7)*x2 + T5)*
		    (x2*x*x2);
		RETURNI(q + T3*(x2*x) + x);
#endif
#endif
	    }
	    k_hexpl(2*fabsl(x), &hi, &lo);
	    if (ix<0x4001 && fabsl(x) < 1.5)	/* |x|<1.5 */
		z = divl(hi, lo, -0.5, hi, lo, 0.5);
	    else
		z = one - one/(lo+0.5+hi);
    /* |x| >= 40, return +-1 */
	} else {
	    z = one - tiny;		/* raise inexact flag */
	}
	s = 1;
	if (jx<0) s = -1;
	RETURNI(s*z);
}
int main(void)
{
	largeInt l1, l2,l3,sum,diff,product;
	largeNum n1, n2,sumn;
	div_result divi;
	int x,prime_n1,prime_n2;
	printf("Enter 1st number:");
	readint(&l1);
	
	printf("\n");
	printf("Enter 2nd number:");
	readint(&l2);
	printf("\nThe 1st number is :\n");
	showI(l1);
	printf("\nThe 2nd number is :\n");
	showI(l2);
	printf("\n");
	
//	printf("chk_equal=%d",chk_equal(l1,l2));
//	printf("\n");

	
//	showI(increment1(l1));
	
//	fwriteI(l3);

//	printf("\nequal zero: %d",equal_to_zero(n1));

//	shift(&n1,3);
//	showN(n1);
//	shift(&n1,-2);
//	showN(n1); 

//	printf("\nAfter removing all zeroes from left;"); 	
//	rem_all_zeros_from_left(&n1);
//	showN(n1);	
	
//	x=equal_to_zero(l1);
//	printf("\n Value of x: %d\n",x);

//	x=greaterthan(l1,l2);
//	printf("\n Value of x: %d\n",x);
	
	sum=addl(l1,l2); // Addition..
	printf("\n\nSum=");
	showI(sum);
	
//	sumn=add_n_times(n1,2);
//	printf("\nSUM_N=");
//	showN(sumn);
	
	diff=subl(l1,l2);
	printf("\n\nDifference=");
	showI(diff);
	
	product=multl(l1,l2);
	printf("\n\nproduct=");
	showI(product);
	
	printf("\n\n");

//	append_n_zeros_right(&n1,2);
//	showN(n1);
//	remove_one_zero_right(&n1);
//	printf("\n");
//	showN(n1);

	divi=divl(l1,l2);
	showDiv(divi);
	
	printf("\nmodulus of 1st and 2nd number:");
	showI(modl(l1,l2));
	
	x=Isprime(l1);
	if(x==1)
		printf("\nPRIME");
	else
		printf("\nNOT PRIME\n");
	
	return 0;
}	
//*****(F-5)*****
largeInt modl(largeInt dividend,largeInt divisor) // MODULO OPEARATION
{
	largeInt irem;
	NumToInt(divl(dividend,divisor).rem,&irem);
	return(irem);
}