Skip to content

Commit

Permalink
Added initial constructors (untested) for FixMath2
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcombriat committed Nov 13, 2023
1 parent 1833e1e commit bcd202e
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions FixMath2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<byte IP, byte FP>
class FixMath2
template<byte NI, byte NF> // 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<typename IntegerType< ((NI+NF)>>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<float>(internal_value)) / (1<<NF); }
typename IntegerType< ((NI+NF)>>3) >::unsigned_type getInt() { return internal_value; }

private:
// use of the IntegerType for that?
typename IntegerType< ((NI+NF)>>3) >::unsigned_type internal_value;

};







#endif

0 comments on commit bcd202e

Please sign in to comment.