int main(){ bigint* a = int_to_bigint(283743); bigint* b = int_to_bigint(27); printf("substraction : %llx\n",bigint_to_int(subtraction(a, b))); printf("division : %llx\n",bigint_to_int(divide(a, b))); }
/* Read input to the current cell */ void input(Memory *mem) { void *cell; bigint input; int c; char buf[1024]; char *p; if(!(cell = get_cell(mem))) return; if(chario) { /* character io */ fflush(stdout); c = fgetc(stdin); if(c == EOF) goto handle_eof; else { if(wrap) *(unsigned char *)cell = c; else bigint_from_int(cell, c); } } else { /* number io */ bigint_init(&input); /* use bigint for input even if we're reading to wrapping cells */ do { if(prompt) { fprintf(stderr, "Input: "); fflush(stderr); } if(!(fgets(buf, 1024, stdin))) goto handle_eof; if((p = strchr(buf, '\n'))) *p = '\0'; } while(bigint_from_string(&input, buf) == BIGINT_ILLEGAL_PARAM); if(wrap) *(unsigned char *)cell = bigint_to_int(&input); else bigint_copy(cell, &input); bigint_release(&input); } return; handle_eof: if(strcasecmp(eof_value, "nochange") != 0) { bigint_from_string(cell, eof_value); } }
/* Write output from the current cell */ void output(Memory *mem) { void *cell; char *buf; if(!(cell = get_cell(mem))) return; if(chario) { /* character io */ if(wrap) fputc(*(unsigned char *)cell, stdout); else fputc(bigint_to_int(cell), stdout); } else { /* number io */ if(wrap) printf("%d\n", *(unsigned char *)cell); else { buf = malloc(bigint_string_length(cell)); bigint_to_string(cell, buf); fputs(buf, stdout); fputc('\n', stdout); free(buf); } } }