added make_silly

This commit is contained in:
2017-07-30 18:41:16 -04:00
parent 10817f077c
commit c3c04b558a
3 changed files with 10 additions and 1 deletions

View File

@@ -11,8 +11,8 @@ Don't. The makefile only includes a test target, because I want to test my code.
```c ```c
silly silly_zeros(); // creates a fixed point value of zero silly silly_zeros(); // creates a fixed point value of zero
silly make_silly(short, int, int); // make a silly number from the triple (negative?, before decimal, after) silly make_silly(short, int, int); // make a silly number from the triple (negative?, before decimal, after)
double silly_to_double(silly); // convert a silly number into a double double silly_to_double(silly); // convert a silly number into a double
silly silly_add(silly, silly); // addition silly silly_add(silly, silly); // addition

View File

@@ -88,3 +88,11 @@ char* silly_to_string(silly s) {
double silly_to_double(silly s) { double silly_to_double(silly s) {
return ((double)s.before + ((double)s.after)/(double)0xffffffff) * (s.sign ? -1 : 1); return ((double)s.before + ((double)s.after)/(double)0xffffffff) * (s.sign ? -1 : 1);
} }
silly make_silly(short sign, int before, int after) {
silly s;
s.sign = sign;
s.before = before;
s.after = after;
return s;
}

View File

@@ -9,6 +9,7 @@ typedef struct {
} silly; } silly;
silly silly_zeros(); silly silly_zeros();
silly make_silly(short, int, int);
silly silly_add(silly, silly); silly silly_add(silly, silly);
silly silly_sub(silly, silly); silly silly_sub(silly, silly);