From 65f6c7fd314f94441ebe80aa6b87e058d0cd0f48 Mon Sep 17 00:00:00 2001 From: hellerve Date: Mon, 31 Jul 2017 13:18:53 -0400 Subject: [PATCH] conversion: macrofied conversion --- silly.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/silly.c b/silly.c index 5e47bf2..d6f5256 100644 --- a/silly.c +++ b/silly.c @@ -97,22 +97,20 @@ silly make_silly(short sign, int before, int after) { return s; } +#define FROM(n) {\ + silly s;\ + double _;\ + s.sign = signbit(x);\ + x = fabs(x);\ + s.before = trunc(x);\ + s.after = modf(x, &_);\ + 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; + FROM(x); } 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; + FROM(x); }