
Patrick Mihelich wrote:
On Wed, Jun 24, 2009 at 12:51 PM, Soren Holstebroe <holstebroe@gmail.com>wrote:
Would there be public interest in a template like that in the boost library?
Yes, very much so. My main use case is also image processing.
It would be useful if you could compare your work to other implementations, such as: * Phil Endecott's related proposal last year, and the ensuing discussion: http://lists.boost.org/Archives/boost/2007/04/120082.php * Dr. Dobbs, "Fixed-Point Arithmetic Types for C++," http://www.ddj.com/cpp/184401992
How are multiplication and division handled?
Is overflow detection and/or saturation arithmetic supported?
I have posted here before some code based on constrained_value. One difficulty with this area is that users have different opinions on what the semantics should be. For example, does a(24bit) x b(24bit) -> c(24bit), or c(48bit)? My preference is to be explicit about these issues, meaning 24bit x 24bit -> 24 bit. If you want more, you cast the operands first. Similarly there were some questions on division. My implementation also uses boost::operators. In addition, I have 2 versions, one which the bit-widths are set at compile time, and the other set at runtime (I use the latter to expose to python). Since it is small, I am attaching the runtime version