silly: added silly_to_raw and silly_to_uraw

This commit is contained in:
2017-08-03 19:01:23 -04:00
parent a8db572c5f
commit 3f3a0da4b8
3 changed files with 16 additions and 4 deletions

View File

@@ -18,6 +18,8 @@ silly silly_from_float(float); // creates a silly number from a float
silly silly_from_double(double); // creates a silly number from a double
double silly_to_double(silly); // convert a silly number into a double
uint64_t silly_to_uraw(silly); // convert the silly struct to a raw value (without sign)
int64_t silly_to_raw(silly); // convert the silly struct to a raw value (with sign)
silly silly_add(silly, silly); // addition
silly silly_sub(silly, silly); // subtraction

16
silly.c
View File

@@ -81,8 +81,8 @@ silly silly_idiv(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;
uint64_t x0 = silly_to_uraw(x);
uint64_t y0 = silly_to_uraw(y);
z.before = x0 / y0;
z.after = 0;
@@ -97,8 +97,8 @@ int count_zeroes(uint64_t x) {
}
silly silly_div(silly x, silly y) {
uint64_t x0 = (((uint64_t) x.before) << 32) + x.after;
uint64_t y0 = (((uint64_t) y.before) << 32) + y.after;
uint64_t x0 = silly_to_uraw(x);
uint64_t y0 = silly_to_uraw(y);
uint64_t rem = x0;
uint64_t div = y0;
@@ -144,6 +144,14 @@ double silly_to_double(silly s) {
return ((double)s.before + ((double)s.after)/(double)0xffffffff) * (s.sign ? -1 : 1);
}
uint64_t silly_to_uraw(silly s) {
return (((uint64_t) s.before) << 32) + s.after;
}
int64_t silly_to_raw(silly s) {
return silly_to_uraw(s) * (s.sign ? -1 : 1);
}
silly make_silly(short sign, int before, int after) {
silly s;
s.sign = sign;

View File

@@ -21,5 +21,7 @@ silly silly_div(silly, silly);
silly silly_from_float(float);
silly silly_from_double(double);
double silly_to_double(silly);
uint64_t silly_to_uraw(silly);
int64_t silly_to_raw(silly);
char* silly_to_string(silly);