Boost logo

Boost :

From: Neal Becker (ndbecker2_at_[hidden])
Date: 2008-08-01 07:00:35

Anthony Williams wrote:

> "John C. Femiani" <john.femiani_at_[hidden]> writes:
>> Anthony Williams wrote:
>>> "John C. Femiani" <john.femiani_at_[hidden]> writes:
>>>> Also, do your implementations for /= and *= actually round? You
>>>> actually seem to be using the round policy for conversions, is that
>>>> right? Have you looked at the numeric/conversion stuff? (I haven't
>>>> grokked it yet).
>>> The division throws away the lower "frac_bits" of the result:
>> So why doesn't it use the rounding policy? I kind of expect it to be
>> used anytime quantization occurs.
> I'll leave Neal to answer that (it's his code), but getting division
> right is a pain. If you followed the link to my code, you'll see that
> correct division is not trivial.
> Anthony

Multiplication is a bit easier to understand. I thought about mixed-arith mult, but I think it opens a can of worms. What do you want the result to be? So, I decided to only support arith of like-types. If you want the result of mult to be a larger type, then you simply ask for it:

fixed<8,8> x, y;
fixed<16,16> z = fixed<16,16> (x) * fixed<16,16> (y);

As far as division, I wasn't quite sure and the implementation shown is only a guess. Suggestions welcome.

Boost list run by bdawes at, gregod at, cpdaniel at, john at