From bcd202ed8bddd393d640aa3864c72e09ab2f422c Mon Sep 17 00:00:00 2001 From: tomcombriat Date: Mon, 13 Nov 2023 22:29:12 +0100 Subject: [PATCH] Added initial constructors (untested) for FixMath2 --- FixMath2.h | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/FixMath2.h b/FixMath2.h index 48849d599..a5f176c51 100644 --- a/FixMath2.h +++ b/FixMath2.h @@ -18,19 +18,25 @@ #define SHIFTR(x,bits) (bits > 0 ? (x) >> (bits) : (x) << (-bits)) // shift right for positive shift numbers, and left for negative ones. -template -class FixMath2 +template // NI and NF being the number of bits for the integral and the fractionnal parts respectively. +class UFixMath2 { public: + /** Constructor + */ + UFixMath2() {;} + UfixMath2(float fl) {internal_value = static_cast>3)> > (fl * (1 << NF));} + UfixMath2(typename IntegerType<((NI)>>3)> integral_part, typename IntegerType<((NF)>>3)>fractionnal_part) + { + internal_value = (integral_part << NI) + fractionnal_part; + } // probably a more confusing than anything constructor! + + float asFloat() { return (static_cast(internal_value)) / (1<>3) >::unsigned_type getInt() { return internal_value; } private: - // use of the IntegerType for that? + typename IntegerType< ((NI+NF)>>3) >::unsigned_type internal_value; + }; - - - - - - #endif