Subject: Re: [boost] Fixed point implicity
From: Ravi (lists_ravi_at_[hidden])
Date: 2009-07-02 10:28:27
On Thursday 02 July 2009 09:01:22 Phil Endecott wrote:
> As Ravi points out, different applications will have different
> requirements. And it is hard to implement a library that is totally
> flexible because there is nowhere in the syntax of the expression "a+b"
> to specify all the possible options.
> Perhaps what is needed is a "meta-library" that can be instantiated to
> provide fixed point types with different characteristics. Something
> like a layer on top of Boost.Operators. Thoughts anyone?
Why would that be different from a combination of your two guiding principles?
Based on you guideline 1, the return type of A (op) B is one that preserves
all bits where (op) is addition, subtraction or multiplication (ignore
division for now). Then, based on your guideline 2, when the result is
cast/assigned to some type, that type would hold all the information necessary
(trucation, saturation, etc.). The operators themselves need to know only
enough to preserve bits.
For division, one may require explicit casting everywhere, since an integer
divisor which has prime factors other than 2 will require too many bits for
some dividend, and the user must explicitly specify what to do. (The reasoning
can be extended to fixed-point non-integers.)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk