Boost logo

Boost :

Subject: Re: [boost] Fixed point integer proposal
From: Soren Holstebroe (holstebroe_at_[hidden])
Date: 2009-06-25 12:53:43


> 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.

In my template N bit x N bit equals N bit per default.
The number one design criteria was speed. Why would you use fixed
point instead of floats if not for speed?
I agree that you should be explicit if you want to promote the return
type of a multiplication.
That said, my template actually work with a promotion framework I
wrote, where you can specify the promoted type of different kind of
operations for different types.
In the image processing library where the class was used, the
promotion framework was set to promote N bit * N bit to 2N bit, but
only up till the maximum number of bits natively supported by the CPU
architecture. It was combined with an overflow check in debug mode to
avoid surprises when the promotion was at the bit loft.
That worked pretty well (and speedy).

> 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).

I can't see a way to support run time bit width without sacrificing performance.

Soren


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk