void test07(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]; bigSub(); printf("%12d - %12d = ", m[i], m[j]); dump("", bip.res, "\n"); } } }
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 뺄셈연산 }
VAL idris_bigMinus(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 INTOP(-, x, y); } i_int res = vx - vy; if (res >= 1<<30 || res <= -(1 << 30)) { return bigSub(vm, GETBIG(vm, x), GETBIG(vm, y)); } else { return MKINT(res); } } else {
void bigDivide(char num1[] , char num2[] , char quot[]) { if(strcmp(num1 , "0") == 0) { quot[0] = '0'; quot[1] = '\0'; return; } char *temp = (char*)malloc(sizeof(char) * strlen(num1)); int len1 = strlen(num1); int i; int j = 0; for( i = 0 ; i < len1 ; i++) { temp[j] = num1[len1-i-1]; temp[j+1] = '\0'; reverseStr(temp); int cnt = 0; while(isBigger(temp , num2)) { bigSub(temp, num2); cnt++; } reverseStr(temp); quot[i] = cnt + '0'; if(strcmp(temp, "0") == 0) { j = 0; } else { j++; } } quot[i] = '\0'; removeFrontZero(quot); reverseStr(quot); free(temp); }