• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ divide函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中divide函数的典型用法代码示例。如果您正苦于以下问题:C++ divide函数的具体用法?C++ divide怎么用?C++ divide使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了divide函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: divide

	Rational& operator /=(const Rational& x) {
		Rational res = divide(rhs);
		swap(res);
		return *this;
	}
开发者ID:agul,项目名称:algolib,代码行数:5,代码来源:rational.hpp


示例2: ZZX_div

static CYTHON_INLINE struct ZZX* ZZX_div(struct ZZX* x, struct ZZX* y, int* divisible)
{
    struct ZZX* z = new ZZX();
    *divisible = divide(*z, *x, *y);
    return z;
}
开发者ID:JoseGuzman,项目名称:sage,代码行数:6,代码来源:ntlwrap.cpp


示例3: sort

 ll sort(T *a1,T *b1,int n1){
     a=a1;b=b1;n=n1;
     num=0;
     divide(0,n-1);
     return num;
 }
开发者ID:wintowanti,项目名称:ICPC_fun,代码行数:6,代码来源:d.cpp


示例4: divide

	vec3& vec3::operator/=(const vec3& other){
		return divide(other);
	}
开发者ID:bbaeza10001,项目名称:Game-Engine--Personal-Copy-,代码行数:3,代码来源:Vec3.cpp


示例5: main

int main(void)
{
	struct 
	{
		ULONG a;
		UWORD b;
		ULONG r;
	} div[] =
	{
		{0,1,0x00000000},
		{1,1,0x00000001},
		{1,2,0x00010000},
		{1,3,0x00010000},
		{1,4,0x00010000},
		{1,1000,0x00010000},
		{1,6000,0x00010000},
		{10000,666,0x000a000f},
		{80000,666,0x01de0015},
		{80000,1,0x00003880},
	};
	const div_numof = sizeof(div) / sizeof(div[0]);
	int i;
	UBYTE tmp[256], *p;
	UBYTE t2[64];

	printf("\ndivide:\n");

	for (i = 0; i< div_numof; i++)
	{
		printf("%d / %d = 0x%08x\n", div[i].a, div[i].b, divide(div[i].a, div[i].b));
		if (divide(div[i].a, div[i].b) != div[i].r)
		{
			printf("failed!\n");
			return 5;
		}
	}

	printf("\nctodstr:\n");
	ctodstr("", tmp);
	if (tmp[0] != 0 || memcmp(tmp+1, "", 1)) { printf("failed \"\"!\n"); return 5; }
	ctodstr("foobar", tmp);
	if (tmp[0] != 6 || memcmp(tmp+1, "foobar", 6)) { printf("failed \"foobar\"!\n"); return 5; }

	printf("\nstcu_d:\n");
	stcu_d(tmp, 0);
	if (strcmp(tmp, "0")) { printf("failed 0\n"); return 5; }
	stcu_d(tmp, 123456);
	if (strcmp(tmp, "123456")) { printf("failed 123456\n"); return 5; }
	stcu_d(tmp, 10000000);
	if (strcmp(tmp, "10000000")) { printf("failed 10000000\n"); return 5; }

	printf("\nstpcpy:\n");
	p = stpcpy(tmp, "");
	if (p != tmp || strcmp(tmp, "")) { printf("failed \"\"\n"); return 5; }
	p = stpcpy(tmp, "foobar");
	if (p != tmp + 6 || strcmp(tmp, "foobar")) { printf("failed \"foobar\"\n"); return 5; }

	printf("\nintltoupper:\n");

	ctodstr("", tmp);
	intltoupper(tmp);
	if (tmp[0] != 0) { printf("failed \"\"\n"); return 5; }
	ctodstr("fooBarφδείπ[email protected]£", tmp);
	intltoupper(tmp);
	if (tmp[0] != 14 || memcmp(tmp + 1, "FOOBARΦΔΕίΠ[email protected]£", 14)) { printf("failed \"fooBarφδείπ[email protected]£\"\n"); return 5; }

	printf("\nintlcmp:\n");
	ctodstr("foo", tmp);
	intltoupper(tmp);
	if (intlcmp(tmp, tmp) != 1) { printf("failed \"foo\" selfcompare\n"); return 5; }
	ctodstr("foo", tmp);
	intltoupper(tmp);
	ctodstr("foo", t2);
	if (intlcmp(tmp, t2) != 1) { printf("failed \"FOO\" vs \"foo\"\n"); return 5; }
	ctodstr("fooBarφδείπ[email protected]£", tmp);
	intltoupper(tmp);
	if (intlcmp(tmp, tmp) != 1) { printf("failed \"fooBarφδείπ[email protected]£\" selfcompare\n"); return 5; }
	ctodstr("fooBar", t2);
	intltoupper(t2);
	if (intlcmp(tmp, t2) != 0) { printf("failed \"fooBarφδείπ[email protected]£\" vs \"fooBar\"\n"); return 5; }
	ctodstr("fooBarφδείπ[email protected]£xxx", t2);
	intltoupper(t2);
	if (intlcmp(tmp, t2) != 0) { printf("failed \"fooBarφδείπ[email protected]£\" vs \"fooBarφδείπ[email protected]£xxx\"\n"); return 5; }
	ctodstr("fooBaxφδείπ[email protected]£", t2);
	if (intlcmp(tmp, t2) != 0) { printf("failed \"fooBarφδείπ[email protected]£\" vs \"fooBaxφδείπ[email protected]£\"\n"); return 5; }
	ctodstr("fooBar", t2);
	if (intlcmp(tmp, t2) != 0) { printf("failed \"fooBarφδείπ[email protected]£\" vs \"fooBar\"\n"); return 5; }
	ctodstr("fooBarφδείπ[email protected]£xxx", t2);
	if (intlcmp(tmp, t2) != 0) { printf("failed \"fooBarφδείπ[email protected]£\" vs \"fooBarφδείπ[email protected]£xxx\"\n"); return 5; }
	ctodstr("fooBaxφδείπ[email protected]£", t2);
	if (intlcmp(tmp, t2) != 0) { printf("failed \"fooBarφδείπ[email protected]£\" vs \"fooBaxφδείπ[email protected]£\"\n"); return 5; }

	printf("\nintlcdcmp:\n");
	ctodstr("", tmp);
	intltoupper(tmp);
	if (intlcdcmp("", tmp) != 1) { printf("failed \"\"\n"); return 5; }
	ctodstr("A", tmp);
	if (intlcdcmp("A", tmp) != 1) { printf("failed \"A\" vs \"A\"\n"); return 5; }
	ctodstr("a", tmp);
	if (intlcdcmp("A", tmp) != 1) { printf("failed \"A\" vs \"a\"\n"); return 5; }
//.........这里部分代码省略.........
开发者ID:michalsc,项目名称:AROS,代码行数:101,代码来源:assroutines_unittest.c


示例6: WndProc

LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
				 WPARAM wParam, LPARAM lParam)
{	

	switch(message){
		case WM_DESTROY:{ PostQuitMessage(0); break;}
		case WM_CREATE:{
			infoEdit = CreateWindow("edit","0",WS_CHILD|WS_VISIBLE|WS_BORDER|ES_RIGHT|ES_READONLY, 10, 30, 265, 20, hWnd,(HMENU)201,hInst,0);
			buttons[0] =  CreateWindow("button","7", WS_CHILD|WS_VISIBLE, 10,70,65,65, hWnd, (HMENU)107, hInst, 0);
			buttons[1] =  CreateWindow("button","8", WS_CHILD|WS_VISIBLE, 75,70,65,65, hWnd, (HMENU)108, hInst, 0);
			buttons[2] =  CreateWindow("button","9", WS_CHILD|WS_VISIBLE, 140,70,65,65, hWnd, (HMENU)109, hInst, 0);
			buttons[3] =  CreateWindow("button","+", WS_CHILD|WS_VISIBLE, 205,70,65,65, hWnd, (HMENU)110, hInst, 0);
			buttons[4] =  CreateWindow("button","4", WS_CHILD|WS_VISIBLE, 10,135,65,65, hWnd, (HMENU)104, hInst, 0);
			buttons[5] =  CreateWindow("button","5", WS_CHILD|WS_VISIBLE, 75,135,65,65, hWnd, (HMENU)105, hInst, 0);
			buttons[6] =  CreateWindow("button","6", WS_CHILD|WS_VISIBLE, 140,135,65,65, hWnd, (HMENU)106, hInst, 0);
			buttons[7] =  CreateWindow("button","-", WS_CHILD|WS_VISIBLE, 205,135,65,65, hWnd, (HMENU)111, hInst, 0);
			buttons[8] =  CreateWindow("button","1", WS_CHILD|WS_VISIBLE, 10,200,65,65, hWnd, (HMENU)101, hInst, 0);
			buttons[9] =  CreateWindow("button","2", WS_CHILD|WS_VISIBLE, 75,200,65,65, hWnd, (HMENU)102, hInst, 0);
			buttons[10] =  CreateWindow("button","3", WS_CHILD|WS_VISIBLE, 140,200,65,65, hWnd, (HMENU)103, hInst, 0);
			buttons[11] =  CreateWindow("button","*", WS_CHILD|WS_VISIBLE, 205,200,65,65, hWnd, (HMENU)112, hInst, 0);
			buttons[12] =  CreateWindow("button","C", WS_CHILD|WS_VISIBLE, 10,265,65,65, hWnd, (HMENU)113, hInst, 0);
			buttons[13] =  CreateWindow("button","0", WS_CHILD|WS_VISIBLE, 75,265,65,65, hWnd, (HMENU)100, hInst, 0);
			buttons[14] =  CreateWindow("button","=", WS_CHILD|WS_VISIBLE, 140,265,65,65, hWnd, (HMENU)114, hInst, 0);
			buttons[15] =  CreateWindow("button","/", WS_CHILD|WS_VISIBLE, 205,265,65,65, hWnd, (HMENU)115, hInst, 0);
			break;
		}
		case WM_COMMAND:{
			if(HIWORD(wParam)==BN_CLICKED){
				switch (LOWORD(wParam)){
					case 100: case 101: case 102: case 103: case 104: 
					case 105: case 106: case 107: case 108: case 109:{
						if(count<9&&second<214748364){
							if(znak==0)	second=0;
							second=second*10+LOWORD(wParam)-100;
							itoa(second, buff, 10);
							SetWindowText(infoEdit, buff); 
							count++;
						}
						break;
					}
					case 110: case 111: case 112: case 115:{
						switch(znak){
							case 0: result=second; break;
							case 1: {   if(plus(result, second))
											result=plus(result, second); 
									else {
										result=0;
										count=0;
										znak=1;
										strcpy(buff, "!Error!");
										SetWindowText(infoEdit, buff); 
									}  
									break;
								}
							case 2: {   if(minus(result, second))
											result=minus(result, second); 
									else {
										result=0;
										count=0;
										znak=1;
										strcpy(buff, "!Error!");
										SetWindowText(infoEdit, buff); 
									}  
									break;
								}
							case 3: {   if(multiply(result, second))
											result=multiply(result, second); 
									else {
										result=0;
										count=0;
										znak=1;
										strcpy(buff, "!Error!");
										SetWindowText(infoEdit, buff); 
									}  
									break;
								}
							case 4: {
									if(second){   
										if(divide(result, second))
											result=divide(result, second); 
										else {
											result=0;
											count=0;
											znak=1;
											strcpy(buff, "!Error!");
											SetWindowText(infoEdit, buff); 
										}  
									}
									else{
										result=0;
										count=0;
										znak=1;
										strcpy(buff, "!Dev by 0!");
										SetWindowText(infoEdit, buff); 
									}
									break;
									}
							default: break;
						};
						if(strcmp(buff, "!Dev by 0!")&&strcmp(buff, "!Error!")){
//.........这里部分代码省略.........
开发者ID:D-Moskalyov,项目名称:WinAPI_Calculator,代码行数:101,代码来源:Исходный+код.cpp


示例7: euclid

static int euclid(_MIPD_ big x,int num)
{ /* outputs next c.f. quotient from gcd(w5,w6) */
    mr_small sr,m;
#ifdef MR_FP
    mr_small dres;
#endif
    mr_small lr,lq;
    big t;
#ifndef MR_GENERIC_MT
    miracl *mr_mip=get_mip();
#endif
    if (num==0)
    {
        mr_mip->oldn=(-1);
        mr_mip->carryon=FALSE;
        mr_mip->last=FALSE;
        if (compare(mr_mip->w6,mr_mip->w5)>0)
        { /* ensure w5>w6 */
            t=mr_mip->w5,mr_mip->w5=mr_mip->w6,mr_mip->w6=t;
            return (mr_mip->q=0);
        }
    }
    else if (num==mr_mip->oldn || mr_mip->q<0) return mr_mip->q;
    mr_mip->oldn=num;
    if (mr_mip->carryon) goto middle;
start:
    if (size(mr_mip->w6)==0) return (mr_mip->q=(-1));
    mr_mip->ndig=(int)mr_mip->w5->len;
    mr_mip->carryon=TRUE;
    mr_mip->a=1;
    mr_mip->b=0;
    mr_mip->c=0;
    mr_mip->d=1;
    if (mr_mip->ndig==1)
    {
        mr_mip->last=TRUE;
        mr_mip->u=mr_mip->w5->w[0];
        mr_mip->v=mr_mip->w6->w[0];
    }
    else
    {
        m=mr_mip->w5->w[mr_mip->ndig-1]+1;
        if (mr_mip->base==0)
        {
#ifndef MR_NOFULLWIDTH
            if (m==0)
            {
                mr_mip->u=mr_mip->w5->w[mr_mip->ndig-1];
                mr_mip->v=mr_mip->w6->w[mr_mip->ndig-1];
            }
            else
            {
                mr_mip->u=muldvm(mr_mip->w5->w[mr_mip->ndig-1],mr_mip->w5->w[mr_mip->ndig-2],m,&sr);
                mr_mip->v=muldvm(mr_mip->w6->w[mr_mip->ndig-1],mr_mip->w6->w[mr_mip->ndig-2],m,&sr);
            }
#endif
        }
        else
        {
            mr_mip->u=muldiv(mr_mip->w5->w[mr_mip->ndig-1],mr_mip->base,mr_mip->w5->w[mr_mip->ndig-2],m,&sr);
            mr_mip->v=muldiv(mr_mip->w6->w[mr_mip->ndig-1],mr_mip->base,mr_mip->w6->w[mr_mip->ndig-2],m,&sr);
        }
    }
    mr_mip->ku=mr_mip->u;
    mr_mip->kv=mr_mip->v;
middle:
    forever
    { /* work only with most significant piece */
        if (mr_mip->last)
        {
            if (mr_mip->v==0) return (mr_mip->q=(-1));
            lq=MR_DIV(mr_mip->u,mr_mip->v);
        }
        else
        {
            if (((mr_mip->v+mr_mip->c)==0) || ((mr_mip->v+mr_mip->d)==0)) break;
            lq=MR_DIV((mr_mip->u+mr_mip->a),(mr_mip->v+mr_mip->c));
            if (lq!=MR_DIV((mr_mip->u+mr_mip->b),(mr_mip->v+mr_mip->d))) break;
        }
        if (lq>=(mr_small)(MR_TOOBIG/mr_abs(mr_mip->d))) break;

        mr_mip->q=(int)lq;
        mr_mip->r=mr_mip->a-mr_mip->q*mr_mip->c;
        mr_mip->a=mr_mip->c;
        mr_mip->c=mr_mip->r;
        mr_mip->r=mr_mip->b-mr_mip->q*mr_mip->d;
        mr_mip->b=mr_mip->d;
        mr_mip->d=mr_mip->r;
        lr=mr_mip->u-lq*mr_mip->v;
        mr_mip->u=mr_mip->v;
        mr_mip->v=lr;
        return mr_mip->q;
    }
    mr_mip->carryon=FALSE;
    if (mr_mip->b==0)
    { /* update w5 and w6 */
        mr_mip->check=OFF;
        divide(_MIPP_ mr_mip->w5,mr_mip->w6,mr_mip->w7);
        mr_mip->check=ON;
        if (mr_lent(mr_mip->w7)>mr_mip->nib) return (mr_mip->q=(-2));
//.........这里部分代码省略.........
开发者ID:karllen,项目名称:Windows_Program,代码行数:101,代码来源:MRROUND.C


示例8: divide

int divide(struct NUMBER *a,struct NUMBER *b,struct NUMBER *c,struct NUMBER *d)
{
	int k,res = 0;
	struct NUMBER tmp_a,n,m,l,abs_a,abs_b;

	copyNumber(a,&tmp_a);//aが破壊されないようにtmp_aにコピー

	if(isZero(b) == 0)//isZeroは0か-1が返るので
		return(-1);

	clearByZero(c);
	clearByZero(d);//c,dを0でクリア
	clearByZero(&n);
	clearByZero(&m);
	clearByZero(&l);//作業用変数n,m,lを0でクリア

	setInt(&n,1);//適当な変数に1を突っ込む
	if(numComp(b,&n) == 0)//除数が1ならば
	{
		copyNumber(a,c);//c = a;
		return(0);
	}


	getAbs(a,&abs_a);
	getAbs(b,&abs_b);//a,bの絶対値をとる

	if((getSign(a) == 1) && (getSign(b) == 1))
	{
		while(1)//xから何回yを引けるか調べる
		{
			if(numComp(&tmp_a,b) == -1)//a < bならば
				break;
			copyNumber(b,&n);//bを作業用変数nに代入
			setInt(&m,1);//作業用変数mに1を代入
			while(1)
			{
				copyNumber(&n,&l);
				mulBy10(&l,&n);
				copyNumber(&m,&l);
				mulBy10(&l,&m);//mとnを10倍
				if(numComp(&tmp_a,&n) == -1)//a < nならば
				{
					copyNumber(&n,&l);
					divBy10(&l,&n);
					copyNumber(&m,&l);
					divBy10(&l,&m);//10倍しちゃったので10で割る。いい方法を模索中、一時的に保存する?
					break;
				}
			}
			while(1)
			{
				copyNumber(&tmp_a,&l);//lに現在のaを代入
				sub(&l,&n,&tmp_a);//a = l -n; すなわち a -= n; 
				copyNumber(c,&l);//lにcを代入
				add(&l,&m,c);//c = l + m;すわなち c += m;
				if(numComp(&tmp_a,&n) == -1)
					break;
			}
		}
		copyNumber(&tmp_a,d);//残ったtmp_aがすなわち剰余
	}


	if((getSign(a) == 1) && (getSign(b) == -1)) 
	{
		res = divide(a,&abs_b,c,d);
		setSign(c,-1);//+ / -は解が負であるため
	}
	if((getSign(a) == -1) && (getSign(b) == 1))
	{
		res = divide(&abs_a,b,c,d);
		setSign(c,-1);//- / +は解が負であるため
		setSign(d,-1);//- / +は剰余が負であるため
	}
	if((getSign(a) == -1)&& (getSign(b) == -1))
	{
		res = divide(&abs_a,&abs_b,c,d);//-x / -yは解が正であるためなにもしない
		setSign(d,-1);//- / -は剰余が負であるため
	}
	return(res);
}
开发者ID:sa2taka,项目名称:alogorithm,代码行数:82,代码来源:machin.c


示例9: divide

void point::normalize()
{
    divide(length());
}
开发者ID:jhedin,项目名称:MultiSpringSimulator,代码行数:4,代码来源:point.cpp


示例10: divide

 Quat Quat::operator / ( const Real& scalar)
 {
  Quat r;
  divide(r, *this, scalar);
  return r;
 }
开发者ID:EdCampion,项目名称:nxogre,代码行数:6,代码来源:NxOgreQuat.cpp


示例11: divide

Polynom& Polynom::operator %= (const Polynom& _another) {
	Polynom result = divide(_another).second;
	a = result.a;

	return *this;
}
开发者ID:HPotter,项目名称:ProgrammingLessons,代码行数:6,代码来源:polynom.cpp


示例12: main

int main(int argc, char* argv[]){
	
	DynArr *dyn;
	dyn = createDynArr(2);
	double a,b,c,d,e,f,g,h;
	a = 3;
	b = 4;
	c = 10;
	d = 6;
	e = 5; 
	f = 20;
	printf("\n\nTesting addDynArr...\n");
	addDynArr(dyn, a);
	addDynArr(dyn, b);
	addDynArr(dyn, c);
	addDynArr(dyn, d);
	addDynArr(dyn, e);
	
	printf("The array's content: [3,4,10,6,5]\n");
	assertTrue(EQ(getDynArr(dyn, 0), a), "Test 1st element == 3");
	assertTrue(EQ(getDynArr(dyn, 1), b), "Test 2nd element == 4");
	assertTrue(EQ(getDynArr(dyn, 2), c), "Test 3rd element == 10");
	assertTrue(EQ(getDynArr(dyn, 3), d), "Test 4th element == 5");
	assertTrue(EQ(getDynArr(dyn, 4), e), "Test 5th element == 6");
	assertTrue(sizeDynArr(dyn) == 5, "Test size = 5");
	
	printf("\n\nTesting add...\nCalling addDynArr(dyn)\n");
	add(dyn); 
	printf("The array's content: [3,4,7,6,5]\n");
	assertTrue(EQ(getDynArr(dyn, 3), (double)11), "Test 3rd element == 11");
	assertTrue(sizeDynArr(dyn) == 4, "Test size = 4");
	
	//removing result of add test and restoring array
	removeDynArr(dyn, 3);
	addDynArr(dyn, d);
	addDynArr(dyn, e);
	
	printf("\n\nTesting sub...");
	subtract(dyn); 
	printf("The array's content: [3,4,7,6,5]\n");
	assertTrue(EQ(getDynArr(dyn, 3), (double)1), "Test 3rd element == 1");
	assertTrue(sizeDynArr(dyn) == 4, "Test size = 4");	
	//printf("%d \n", sizeDynArr(dyn));
	printf("Top: %f \n", topDynArr(dyn));	
		//removing result of add test and restoring array
	popDynArr(dyn);
	printf("Top: %f \n", topDynArr(dyn));
	pushDynArr(dyn, f);
	pushDynArr(dyn, e);
	printf("Top: %f \n", topDynArr(dyn));
	
	printf("\n\nTesting divide...");
	divide(dyn); 
	//printf("The array's content: [3,4,10,20,5]\n");
	//assertTrue(EQ(getDynArr(dyn, 3),(double)4), "Test 3rd element == 4");
	//assertTrue(sizeDynArr(dyn) == 4, "Test size = 4");	
/* 	printf("At 4: %f \n", topDynArr(dyn));
	removeDynArr(dyn,4);
	printf("At 3: %f \n", topDynArr(dyn));
	removeDynArr(dyn,3);
	printf("At 2: %f \n", topDynArr(dyn));	
	removeDynArr(dyn,2);
	printf("At 1: %f \n", topDynArr(dyn));	
	printf("%d \n",sizeDynArr(dyn)); */
	
			//removing result of add test and restoring array
	printf("\nTop: %f \n", topDynArr(dyn));
	popDynArr(dyn);
	printf("Top: %f \n", topDynArr(dyn));
	pushDynArr(dyn, f);
	pushDynArr(dyn, e);
	printf("Top: %f \n", topDynArr(dyn));
	
	printf("\n\nTesting multiply...\nCalling addDynArr(dyn)\n");
	multiply(dyn); 
	//printf("The array's content: [3,4,10,6,5]\n");
	//assertTrue(EQ(getDynArr(dyn, 3),(float)30), "Test 3rd element == 30");
	//assertTrue(sizeDynArr(dyn) == (float)4, "Test size = 4");
	
	
	printf("Before pop Top: %f \n", topDynArr(dyn));			//removing result of add test and restoring array
	popDynArr(dyn);
	printf("After pop Top: %f \n", topDynArr(dyn));
	pushDynArr(dyn,(double) 2);
	pushDynArr(dyn,(double) 1);
	printf("After 2 push Top: %f \n", topDynArr(dyn));	
	printf("\n\nTesting power of...n");
	powerOf(dyn); 
	//printf("The array's content: [3,4,10,6,5]\n");
	//assertTrue(EQ(getDynArr(dyn, 3),(float)2), "Test 3rd element == 2");
	//assertTrue(sizeDynArr(dyn) == (float)4, "Test size = 4");
	


	
}
开发者ID:fitzsimk,项目名称:dynamic_data_structures_c,代码行数:96,代码来源:testCalc.c


示例13: cosine_of_angle

void
cosine_of_angle(void)
{
	int n;
	double d;

	if (car(p1) == symbol(ARCCOS)) {
		push(cadr(p1));
		return;
	}

	if (isdouble(p1)) {
		d = cos(p1->u.d);
		if (fabs(d) < 1e-10)
			d = 0.0;
		push_double(d);
		return;
	}

	// cosine function is symmetric, cos(-x) = cos(x)

	if (isnegative(p1)) {
		push(p1);
		negate();
		p1 = pop();
	}

	// cos(arctan(x)) = 1 / sqrt(1 + x^2)

	// see p. 173 of the CRC Handbook of Mathematical Sciences

	if (car(p1) == symbol(ARCTAN)) {
		push_integer(1);
		push(cadr(p1));
		push_integer(2);
		power();
		add();
		push_rational(-1, 2);
		power();
		return;
	}

	// multiply by 180/pi

	push(p1);
	push_integer(180);
	multiply();
	push_symbol(PI);
	divide();

	n = pop_integer();

	if (n < 0) {
		push(symbol(COS));
		push(p1);
		list(2);
		return;
	}

	switch (n % 360) {
	case 90:
	case 270:
		push_integer(0);
		break;
	case 60:
	case 300:
		push_rational(1, 2);
		break;
	case 120:
	case 240:
		push_rational(-1, 2);
		break;
	case 45:
	case 315:
		push_rational(1, 2);
		push_integer(2);
		push_rational(1, 2);
		power();
		multiply();
		break;
	case 135:
	case 225:
		push_rational(-1, 2);
		push_integer(2);
		push_rational(1, 2);
		power();
		multiply();
		break;
	case 30:
	case 330:
		push_rational(1, 2);
		push_integer(3);
		push_rational(1, 2);
		power();
		multiply();
		break;
	case 150:
	case 210:
		push_rational(-1, 2);
		push_integer(3);
//.........这里部分代码省略.........
开发者ID:AnderainLovelace,项目名称:Taumath,代码行数:101,代码来源:cos.c


示例14: while

	// ----------------------------------------------------------------------------
	//	parses the next command from m_instrStream
	// ----------------------------------------------------------------------------
	void CRPNCalc::parse()
	{
		double number = 0;
		while (m_buffer.length() != 0)
		{
			bool delDecimal = false;
			//erase the spaces at the beginning of the string
			while(m_buffer[0] == ' ')
				m_buffer.erase(m_buffer.begin());
			number = atof(m_buffer.c_str());
			//if it is a number
			if((number != 0 && m_buffer[0] != '+') || m_buffer[0] == '0')
			{
				if(m_buffer[0] == '-')
					m_buffer.erase(m_buffer.begin());
				while((m_buffer[0] >= '0' && m_buffer[0] <= '9')
					|| m_buffer[0] == '.')
				{
					if(m_buffer[0] == '.')
						if(delDecimal == false)
							delDecimal = true;
						else
							break;
					m_buffer.erase(m_buffer.begin());
					if(m_buffer.length() == 0)
						break;
				}
				m_stack.push_front(number);
			}
			else
			{
				string token;
				//if the beginning is a character
				if(m_buffer.length() >= 2)
				{
					//special situation with CE
					if(toupper(m_buffer[0]) == 'C' 
						&& toupper(m_buffer[1]) == 'E')
					{
						m_buffer.erase(m_buffer.begin(),m_buffer.begin() + 2);
						clearAll();
						continue;
					}
					//special situation with -0
					else if(m_buffer[0] == '-' && m_buffer[1] == '0')
					{
						m_buffer.erase(m_buffer.begin());
						while(m_buffer[0] == '0')
						{
							m_buffer.erase(m_buffer.begin());
							if(m_buffer.length() == 0)
								break;
						}
						m_stack.push_front(number);
						neg();
						continue;
					}
					//special situation with S0-9
					else if(toupper(m_buffer[0]) == 'S' && 
						m_buffer[1] >= '0' && m_buffer[1] <= '9')
					{
						m_buffer.erase(m_buffer.begin()); // delete the 'S' to get the number
						char index = m_buffer[0];
						setReg(static_cast<int>(index) - ZEROINASCII);
						m_buffer.erase(m_buffer.begin()); // delete the number
						continue;
					}
					//special situation with G0-9
					else if(toupper(m_buffer[0]) == 'G' && 
						m_buffer[1] >= '0' && m_buffer[1] <= '9')
					{
						m_buffer.erase(m_buffer.begin()); // delete the 'G' to get the number
						char index = m_buffer[0];
						getReg(static_cast<int>(index) - ZEROINASCII);
						m_buffer.erase(m_buffer.begin()); // delete the number
						continue;
					}
				}
				if (m_buffer.length() != 0)
				{
					token = m_buffer[0];
					if (0 == token.compare("+"))
						add();
					else if (0 == token.compare("-"))
						subtract();
					else if (0 == token.compare("*"))
						multiply();
					else if (0 == token.compare("/"))
						divide();
					else if (0 == token.compare("^"))
						exp();
					else if (0 == token.compare("%"))
						mod();
					else if (0 == token.compare("c") || 0 == token.compare("C"))
						clearEntry();
					else if (0 == token.compare("d") || 0 == token.compare("D"))
						rotateDown();
//.........这里部分代码省略.........
开发者ID:sonminhtran1997,项目名称:C-project,代码行数:101,代码来源:RPNCalcStart.cpp


示例15: main


//.........这里部分代码省略.........
            if (phase==1)
            { /* looking for all factors of p+1 < LIMIT1 */
                p=mip->PRIMES[i];
                if (mip->PRIMES[i+1]==0)
                { /* now change gear */
                    phase=2;
                    printf("\nphase 2 - trying last prime less than %ld\n"
                           ,LIMIT2);
                    printf("prime= %8ld",p);
                    copy(b,fu[1]);
                    copy(b,fp);
                    mad(b,b,b,n,n,fd);
                    decr(fd,2,fd);     
                    negify(b,t);
                    mad(fd,b,t,n,n,fn);
                    for (m=5;m<=MULT/2;m+=2)
                    { /* store fu[m] = Vm(b) */
                        negify(fp,t);
                        mad(fn,fd,t,n,n,t);
                        copy(fn,fp);
                        copy(t,fn);
                        if (!cp[m]) continue;
                        copy(t,fu[m]);
                    }
                    convert(MULT,t);    
                    lucas(b,t,n,fp,fd);
                    iv=(int)(p/MULT);
                    if (p%MULT>MULT/2) iv++;
                    interval=(long)iv*MULT;
                    p=interval+1;
                    convert(iv,t);
                    lucas(fd,t,n,fp,fvw);
                    negify(fp,fp);
                    subtract(fvw,fu[p%MULT],q);
                    marks(interval);
                    btch*=100;
                    i++;
                    continue;
                }
                pa=p;
                while ((LIMIT1/p) > pa) pa*=p;
                convert((int)pa,t);   
                lucas(b,t,n,fp,q);
                copy(q,b);
                decr(q,2,q);
            }
            else
            { /* phase 2 - looking for last large prime factor of (p+1) */
                p+=2;
                pos=(int)(p%MULT);
                if (pos>MULT/2)
                { /* increment giant step */
                    iv++;
                    interval=(long)iv*MULT;
                    p=interval+1;
                    marks(interval);
                    pos=1;
                    copy(fvw,t);
                    mad(fvw,fd,fp,n,n,fvw);
                    negify(t,fp);
                }
                if (!cp[pos]) continue;

        /* if neither interval+/-pos is prime, don't bother */
                if (!plus[pos] && !minus[pos]) continue;
                subtract(fvw,fu[pos],t);
                mad(q,t,t,n,n,q);  /* batching gcds */
            }
            if (i++%btch==0)
            { /* try for a solution */
                printf("\b\b\b\b\b\b\b\b%8ld",p);
                fflush(stdout);
                egcd(q,n,t);
                if (size(t)==1)
                {
                    if (p>LIMIT2) break;
                    else continue;
                }
                if (compare(t,n)==0)
                {
                    printf("\ndegenerate case");
                    break;
                }
                printf("\nfactors are\n");
                if (isprime(t)) printf("prime factor     ");
                else          printf("composite factor ");
                cotnum(t,stdout);
                divide(n,t,n);
                if (isprime(n)) printf("prime factor     ");
                else          printf("composite factor ");
                cotnum(n,stdout);
                return 0;
            }
        } 
        if (nt>=NTRYS) break;
        printf("\ntrying again\n");
    }
    printf("\nfailed to factor\n");
    return 0;
}
开发者ID:karllen,项目名称:Windows_Program,代码行数:101,代码来源:WILLIAMS.C


示例16: main

int main() {
    char char_response = 0;
    unsigned int first_operand = 0;
    unsigned int second_operand = 0;
    int end_of_operand_flag = 0;
    int operand_success = 0;
    int operation_success = 0;
    char operation = 0;

    printf("Let's test some simple expressions. Type \'N\' at any time to exit.\nPlease input an expression: ");
    while ((char_response = getchar()) != EOF) {
        putchar(char_response);

        if (char_response == 'N') {
            printf("\nThanks for playing. Goodbye.\n");
            break;
        }
        if (isNumChecker(char_response)) {
            if (operand_success == 0) {
                first_operand = makeOperand(char_response, first_operand);
                // printf("\nfirst_operand = %d\n", first_operand);
            }
            if (operand_success == 1) {
                second_operand = makeOperand(char_response, second_operand);
                // printf("\nsecond_operand = %d\n", second_operand);
            }
            end_of_operand_flag = 1;
        }
        if (!isNumChecker(char_response) && end_of_operand_flag == 1) {
            operand_success++;
            end_of_operand_flag = 0;
        }
        if (isOperator(char_response)) {
            if (operation_success == 0 && operand_success == 1) operation = char_response;
            // printf ("\noperator = %c\n", operation);
            operation_success++;
        }
        if (char_response == '\n') {
            // printf("Successful operands = %d\nSuccessful operations = %d\n", operand_success, operation_success);
            if (operation == 0 || operation_success > 1) printf("Invalid expression.\n");
            if (operand_success == 2 && operation_success == 1) {
                if (operation == '+') add(first_operand, second_operand);
                if (operation == '-') subtract(first_operand, second_operand);
                if (operation == '*') multiply(first_operand, second_operand);
                if (operation == '/') divide(first_operand, second_operand);
                if (operation == '%') modulo(first_operand, second_operand);
            }
            printf("Please input a valid expression: ");

            /* Reset all variables */
            first_operand = 0;
            second_operand = 0;
            end_of_operand_flag = 0;
            operand_success = 0;
            operation_success = 0;
            operation = 0;
        }
    }

    return 0;
}
开发者ID:shiftf8,项目名称:cs539,代码行数:61,代码来源:lab3bSimpleCalc.refIO.c


示例17: modulus

Bignum* modulus(Bignum *n1, Bignum *n2, Bignum *r) {
	Bignum aux1, aux2;
	return subtract(n1,multiply(divide(n1,n2,&aux1),n2,&aux2),r);
}
开发者ID:tgoulart,项目名称:maratona-lib,代码行数:4,代码来源:bignum.c


示例18: divide

Complex Complex::operator/(Complex c){
    return divide(c);
}
开发者ID:StevenAnderson,项目名称:EX06_05,代码行数:3,代码来源:Complex.cpp


示例19: divide

CompositeWeight<W1, W2, W3> divide(CompositeWeight<W1, W2, W3> const& x, CompositeWeight<W1, W2, W3> const& y) {
  W1 w1(divide(x.weight1(), y.weight1()));
  W2 w2(divide(x.weight2(), y.weight2()));
  W3 w3(divide(x.weight3(), y.weight3()));
  return CompositeWeight<W1, W2, W3>(w1, w2, w3);
}
开发者ID:anibalanto,项目名称:hyp,代码行数:6,代码来源:CompositeWeight.hpp


示例20: main

int main()
{
    int a[] = {120, 140, 20, 30 ,40 , 50 ,60 ,70 , 800 , 1000, 10, 5};

    divide(a, sizeof(a)/ sizeof(int));
}
开发者ID:kodingmach12,项目名称:MyCodes,代码行数:6,代码来源:minDiff_two_subsets.c



注:本文中的divide函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ divup函数代码示例发布时间:2022-05-30
下一篇:
C++ div_u64_rem函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap