예제 #1
0
파일: testbip.c 프로젝트: ProofTyler/ksp
void test17(void) {
  /* prepare two big integers with 8 and 4 digits, respectively */
  bigFromInt(0x11111111);
  bip.op1 = bip.res;
  bip.op2 = bip.res;
  bigMul();
  bip.op1 = bip.res;
  /* set all 8 digits of dividend */
  bip.op1->data[5 + 0] = 0xF2;
  bip.op1->data[5 + 1] = 0xFB;
  bip.op1->data[5 + 2] = 0xE3;
  bip.op1->data[5 + 3] = 0x46;
  bip.op1->data[5 + 4] = 0x7C;
  bip.op1->data[5 + 5] = 0xC2;
  bip.op1->data[5 + 6] = 0x54;
  bip.op1->data[5 + 7] = 0xF8;
  /* set all 4 digits of divisor */
  bip.op2->data[5 + 0] = 0x1B;
  bip.op2->data[5 + 1] = 0xE8;
  bip.op2->data[5 + 2] = 0xE7;
  bip.op2->data[5 + 3] = 0x8D;
  /* divide */
  dump("", bip.op1, " / ");
  dump("", bip.op2, " =\n");
  bigDiv();
  dump("", bip.res, " R. ");
  dump("", bip.rem, "\n");
  /* verify */
  bip.op1 = bip.res;
  bigMul();
  bip.op1 = bip.res;
  bip.op2 = bip.rem;
  bigAdd();
  dump("quotient * divisor + remainder =\n", bip.res, "\n");
}
예제 #2
0
파일: testbip.c 프로젝트: ProofTyler/ksp
void test16(void) {
  int n1, n2, n3, m;

  n1 = 0x12345678;
  n2 = 0x66554433;
  n3 = 12;
  bigFromInt(n1);
  bip.op1 = bip.res;
  bigFromInt(n2);
  bip.op2 = bip.res;
  bigMul();
  bip.op1 = bip.res;
  bigFromInt(n3);
  bip.op2 = bip.res;
  bigMul();
  bip.op1 = bip.res;
  m = 0x5764;
  bigFromInt(m);
  bip.op2 = bip.res;
  dump("", bip.op1, " / ");
  dump("", bip.op2, " =\n");
  bigDiv();
  dump("", bip.res, " R. ");
  dump("", bip.rem, "\n");
  bip.op1 = bip.res;
  bigMul();
  bip.op1 = bip.res;
  bip.op2 = bip.rem;
  bigAdd();
  dump("quotient * divisor + remainder =\n", bip.res, "\n");
}
예제 #3
0
파일: testbip.c 프로젝트: ProofTyler/ksp
void test05(void) {
  int m[5];
  ObjRef n[5];
  int i, j;

  m[0] = +0x12345678;
  m[1] = +1;
  m[2] = 0;
  m[3] = -1;
  m[4] = -0x12345678;

  for (i = 0; i < 5; i++) {
    bigFromInt(m[i]);
    n[i] = bip.res;
  }

  for (i = 0; i < 5; i++) {
    for (j = 0; j < 5; j++) {
      bip.op1 = n[i];
      bip.op2 = n[j];
      bigAdd();
      printf("%12d + %12d = ", m[i], m[j]);
      dump("", bip.res, "\n");
    }
  }
}
예제 #4
0
파일: testbip.c 프로젝트: ProofTyler/ksp
void test18(void) {
  /* prepare two big integers with 8 and 4 digits, respectively */
  bigFromInt(0x11111111);
  bip.op1 = bip.res;
  bip.op2 = bip.res;
  bigMul();
  bip.op1 = bip.res;
  /* set all 8 digits of dividend */
  bip.op1->data[5 + 0] = 0x4D;
  bip.op1->data[5 + 1] = 0xCC;
  bip.op1->data[5 + 2] = 0x8C;
  bip.op1->data[5 + 3] = 0x18;
  bip.op1->data[5 + 4] = 0x34;
  bip.op1->data[5 + 5] = 0xDF;
  bip.op1->data[5 + 6] = 0x1D;
  bip.op1->data[5 + 7] = 0xFD;
  /* set all 4 digits of divisor */
  bip.op2->data[5 + 0] = 0x69;
  bip.op2->data[5 + 1] = 0xF4;
  bip.op2->data[5 + 2] = 0x94;
  bip.op2->data[5 + 3] = 0x37;
  /* divide */
  dump("", bip.op1, " / ");
  dump("", bip.op2, " =\n");
  bigDiv();
  dump("", bip.res, " R. ");
  dump("", bip.rem, "\n");
  /* verify */
  bip.op1 = bip.res;
  bigMul();
  bip.op1 = bip.res;
  bip.op2 = bip.rem;
  bigAdd();
  dump("quotient * divisor + remainder =\n", bip.res, "\n");
}
예제 #5
0
VAL idris_bigPlus(VM* vm, VAL x, VAL y) {
    if (ISINT(x) && ISINT(y)) {
        i_int vx = GETINT(x);
        i_int vy = GETINT(y);
        if ((vx <= 0 && vy >=0) || (vx >=0 && vy <=0)) {
            return ADD(x, y);
        }
        i_int res = vx + vy;
        if (res >= 1<<30 || res <= -(1 << 30)) {
            return bigAdd(vm, GETBIG(vm, x), GETBIG(vm, y));
        } else {
            return MKINT(res);
        }
    } else {
        return bigAdd(vm, GETBIG(vm, x), GETBIG(vm, y));
    }
}
예제 #6
0
파일: testbip.c 프로젝트: ProofTyler/ksp
void test08(void) {
  int i;

  bigFromInt(1);
  for (i = 1; i < 100; i++) {
    bip.op1 = bip.res;
    bip.op2 = bip.res;
    bigAdd();
    printf("2 ^ %2d = ", i);
    dump("", bip.res, "\n");
  }
}
예제 #7
0
파일: main.c 프로젝트: kingkwung/MyLab
int main(void)
{
    int i;
    
    
    int* a=0; //피연산자 1
    int* b=0; //피연산자 2
    
    int cip=0; //자릿수
    
    printf("Enter the the CIPHER : "); //자릿수 입력받는다
    scanf("%d",&cip);
    
    n=ceil((double)cip/(double)4); //받은 자리수에 기반하여 배열생성을 위한 크기값을 구해낸다
    printf("length of array : [%d]\n",n);
    
    a = (int*)malloc(sizeof(int)*n); // 동적할당으로 메모리할당하는 과정
    b = (int*)malloc(sizeof(int)*n);
    
    //test case
    a[0]=9999;
    a[1]=4444;
    a[2]=7777;
    a[3]=2222;
    a[4]=9999;
    
    b[0]=9111;
    b[1]=6666;
    b[2]=3333;
    b[3]=8888;
    b[4]=1111;
    
    
    printf("first : ");
    for(i=0;i<n;i++)
        printf("%d ",a[i]);
    printf("\n");
    
    printf("second : ");
    for(i=0; i<n;i++)
        printf("%d ",b[i]);
    printf("\n\n");
    
    
    printf("add : ");
    bigAdd(a, b); // big int 덧셈연산
    
    printf("\n");
    
    printf("sub : ");
    bigSub(a, b); // big int 뺄셈연산
}
예제 #8
0
파일: testbip.c 프로젝트: ProofTyler/ksp
void test14(void) {
  int n, m;
  ObjRef dividend;
  ObjRef divisor;
  int ok;

  printf("divisor");
  for (m = 0; m < 256; m++) {
    if (m % 8 == 0) {
      printf("\n%3d to %3d:   ", m, m + 7);
    }
    if (m == 0) {
      printf(" ");
      fflush(stdout);
      continue;
    }
    bigFromInt(m);
    divisor = bip.res;
    ok = 1;
    for (n = 0; n < (1 << 18); n++) {
      bigFromInt(n);
      dividend = bip.res;
      bip.op1 = dividend;
      bip.op2 = divisor;
      bigDiv();
      bip.op1 = bip.res;
      bigMul();
      free(bip.op1);
      bip.op1 = bip.res;
      bip.op2 = bip.rem;
      bigAdd();
      free(bip.op1);
      free(bip.op2);
      bip.op1 = bip.res;
      bip.op2 = dividend;
      if (bigCmp() != 0) {
        ok = 0;
      }
      free(bip.op1);
      free(dividend);
    }
    free(divisor);
    printf("%c", ok ? '.' : '?');
    fflush(stdout);
  }
  printf("\n");
}
예제 #9
0
파일: b115.c 프로젝트: gsrr/Programs
void bigMulChar(char fir[], char sec[], char ret[])
{
	if(strcmp(fir , "0") == 0 || strcmp(sec , "0") == 0)
	{
		ret[0] = '0';
		ret[1] = '\0';
		return;
	}
	int lenSec = strlen(sec);
	int i;
	for( i = 0 ; i < lenSec; i++)
	{
		char *temp = (char*)malloc(sizeof(char) * (strlen(fir) + 1 + i));
		strcpy(temp, fir);
		getMultTemp(temp, i);
		bigMul_char(temp, sec[i] - '0', strlen(temp));
		bigAdd(ret, temp);
		free(temp);
	}
}
예제 #10
0
int main(int argc, char *argv[])
{
	char bigfilename[BF_MAX_FILENAME_LENGTH + 1];
	int numOpts = 0;
	int numFiles;
	char **filenames;

	verDisplay();

	if (argc < 3)
	{
		HelpDisplay();
		return 0;
	}

	// establish defaults for command line options
	optDefaultsSet();

	// override defaults with user options
	while ((numOpts+1) < argc && 
			optProcessArgument(argv[numOpts+1]))
		++numOpts;

	if (!numOpts)
	{
		printf("ERROR: No options specified\n");
		return 0;
	}

	strcpy(bigfilename, argv[numOpts + 1]);
	numFiles = argc - (numOpts + 2);
	filenames = argv + numOpts + 2;

	// execute primary command, with any applicable options
	if (toupper(OptCommand) == 'A')
		bigAdd(bigfilename, numFiles, filenames, 
			OptCompression, OptNewer, OptMove, OptPathnames, 1);
	else if (toupper(OptCommand) == 'F')
		bigFastCreate(bigfilename, numFiles, filenames, 
			OptCompression, OptNewer, OptMove, OptPathnames, 1);
	else if (toupper(OptCommand) == 'U')
	{
		char oldfilename[BF_MAX_FILENAME_LENGTH + 1],
			newfilename[BF_MAX_FILENAME_LENGTH + 1],
			patchfilename[BF_MAX_FILENAME_LENGTH + 1];

		if (numOpts != 1 || argc != 5)
		{
			printf("ERROR: Invalid patch option\n");
			return 0;
		}
		strcpy(oldfilename, argv[numOpts+1]);
		strcpy(newfilename, argv[numOpts+2]);
		strcpy(patchfilename, argv[numOpts+3]);
		bigPatch(oldfilename, newfilename, patchfilename, 1);
	}
	else if (toupper(OptCommand) == 'D')
		bigDelete(bigfilename, numFiles, filenames, 1);
	else if (toupper(OptCommand) == 'V')
		bigView(bigfilename, 1);
	else if (toupper(OptCommand) == 'X')
		bigExtract(bigfilename, numFiles, filenames, 
			OptNewer, OptMove, OptPathnames, OptOverwrite, 1);
	else 
		printf("ERROR: Unrecognized command\n");

	return 0;
}
예제 #11
0
 bool check(string a, string b, string c) {
     string sum = bigAdd(a, b);
     if (sum == c) return true;
     if (sum.size() >= c.size() || sum != c.substr(0, sum.size())) return false;
     return check(b, c.substr(0, sum.size()), c.substr(sum.size()));
 }