diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index 842bcf58c..743ff4d88 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -56,6 +56,7 @@ strings.c translation.c umlaut.c unicode.c +variant.c xml.c ) FOREACH(_FILE ${_FILES}) diff --git a/src/util/variant.c b/src/util/variant.c new file mode 100644 index 000000000..e3461f861 --- /dev/null +++ b/src/util/variant.c @@ -0,0 +1,36 @@ +#include "variant.h" +#include + +static int lcd(int a, int b) { + return a * b; +} + +variant frac_add(variant a, variant b) +{ + int num, den; + variant v; + den = lcd(a.sa[1], b.sa[1]); + num = a.sa[0] * lcd / a.sa[1] + b.sa[0] * lcd / b.sa[1]; + assert(num >= SHRT_MIN && num <= SHRT_MAX); + assert(den >= SHRT_MIN && den <= SHRT_MAX); + v.sa[0] = (short)num; + v.sa[1] = (short)den; + return v; +} + +variant frac_mul(variant a, variant b) +{ + variant v = a; + return v; +} + +variant frac_div(variant a, variant b) +{ + variant v = a; + return v; +} + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/util/variant.h b/src/util/variant.h index b65ee0868..8c78bc3ac 100644 --- a/src/util/variant.h +++ b/src/util/variant.h @@ -1,3 +1,5 @@ +#pragma once + #ifndef STRUCT_VARIANT_H #define STRUCT_VARIANT_H #ifdef __cplusplus @@ -19,6 +21,10 @@ extern "C" { VAR_FLOAT } variant_type; + variant frac_add(variant a, variant b); + variant frac_mul(variant a, variant b); + variant frac_div(variant a, variant b); + #ifdef __cplusplus } #endif