
Vicente J. Botet Escriba wrote:
Le 11/04/12 14:37, Neal Becker a écrit : ...
* fixed point<-> flt should be provided. fixed.as_double() for example. Should the
fixed point -> flt conversion take care of the rounding policy?
In my prototype code, every time a right shift is used, rounding policy is applied. rounding policy is a template parameter, with one default (the only one I care about). The default is, template<typename base_type=int> struct rnd { static base_type apply (base_type x, int frac_bits) { return ((x >> (frac_bits-1)) + 1) >> 1; } }; To shift right by 'frac_bits' places, with rounding, we shift right 1 less place, add 1, then shift 1 more place. When followed by saturation, this is the most common rounding operation I use for 2's complement hardware.
Also, fixed (double, integer_bits, frac_bits) constructor, or something like it. Could you be more precise, please?
I want to be able to construct a fixed from a float, specifying the number of integer and fractional bits (or equivalent).