From: Phil Endecott (spam_from_boost_dev_at_[hidden])
Date: 2007-04-26 14:33:09
Last week I posted some fixed-point arithmetic code for potential
boostification. Thanks for all your comments. The most common
suggestion was that it ought to offer overflow detection, so I have
just thrown together some proof-of-concept code to do this.
I have added a third template parameter to the fixed<> class which
allows you to specify an integer implementation type; it defaults to
boost::int_t<>::least as before giving you no checking an no overhead.
If you want to check for overflow you need to supply a checking integer
type, and I've implemented a simple safe_int<N> class that can be used
This is just a proof of concept with some obvious holes, but I think it
shows what's possible. It should also be usable on its own in integer applications.
The other main issues that were raised were:
- The alternative approach of using proto to provide something more
sophisticated. I would be very interested to see what can be achieved
by this approach (and at what cost) compared to my simplistic version.
- The need for <cmath>-like functions. This is rather beyond my ability.
- What implicit and/or explicit conversions should be included?
- My concerns about how to do, for example, a 32x32->64-bit multiply
efficiently without actually doing a 64x64->64-bit multiply.
I look forward to hearing your comments. I'm keen to maintain
momentum; if people think that something not too different in scope
from what I am currently proposing would be acceptable then I will
start thinking about the other things that are needed (docs, tests etc).
The fixed<> class itself can be found at: