I am writing a small fixed point arithmetic class with the template parameter for integer and partial bits. When two small fixed point types multiply, capturing the full result result is considered a big fixed point type. like . A 16.16 fixed point number multiplied by two 8.8 fixed point number result
My class looks like this:
of the template & lt; Typename t, unsigned int bits, unsigned int frac & gt; FixedPoint {Public: constexpr FixedPoint (int x = 0): raw_ (x & lt; & lt; frac) {} FixedPoint (double x) constexpr: raw_ (x * (t (1) & lt; ; Frac)} {} Private: T raw_; }
The problem now is the T template parameter, especially for the multiplication, the result types are different from the logic types and can not be sent to them. writing a * b does not work
T template type what I want to do to replace the int & lt ;. Bits + frac & gt; that depends on the number of int8_t, int16_t, int32_t or int64_t bits is required for the total
can I write such a type? I'm actually ok with this limited to 8, 16, 32 or 64 bit.
after simple
No comments:
Post a Comment