division: added integer division (because i can't figure out how to do it better

This commit is contained in:
2017-07-31 15:55:01 -04:00
parent 6bcacabc3b
commit 6f93ebcb24
4 changed files with 33 additions and 0 deletions

12
silly.c
View File

@@ -77,6 +77,18 @@ silly silly_mul(silly x, silly y) {
return z;
}
silly silly_div(silly x, silly y) {
silly z;
z.sign = x.sign ^ y.sign;
uint64_t x0 = (((uint64_t) x.before) << 32) + x.after;
uint64_t y0 = (((uint64_t) y.before) << 32) + y.after;
z.before = x0 / y0;
z.after = 0;
return z;
}
char* silly_to_string(silly s) {
char* res = malloc(23);