conversion: added from_* methods

This commit is contained in:
2017-07-31 13:16:40 -04:00
parent 80756ebb7a
commit 53bf408e1b
3 changed files with 34 additions and 2 deletions

20
silly.c
View File

@@ -96,3 +96,23 @@ silly make_silly(short sign, int before, int after) {
s.after = after;
return s;
}
silly silly_from_float(float x) {
silly s;
double _;
s.sign = signbit(x);
x = fabs(x);
s.before = trunc(x);
s.after = modf(x, &_);
return s;
}
silly silly_from_double(double x) {
silly s;
double _;
s.sign = signbit(x);
x = fabs(x);
s.before = trunc(x);
s.after = modf(x, &_);
return s;
}