Boost logo

Boost :

From: Anthony Williams (anthony.ajw_at_[hidden])
Date: 2008-08-01 02:54:24


"John C. Femiani" <john.femiani_at_[hidden]> writes:

> Neal Becker wrote:

>> I have the beginning of a fixed-pt binary lib. Fixed-pt is popular
>> in DSP applications. It is integer arithmetic, but keeping track
>> of the binary pt.

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

  self operator/=(self const& x) {
    base_type tmp = (base_type)val / (base_type)x.val;
    val = tmp << (frac_bits);
    return *this; }

I published a more fully-fledged fixed point type here a few months
ago. You can get it from my website (along with a link to the DDJ
article where I describe how it works):

http://www.justsoftwaresolutions.co.uk/news/optimizing-applications-with-fixed-point-arithmetic.html

It has a fixed number if integer and fractional bits (35.28). However,
this allows it to support sin, cos, exp and log by using lookup tables.

Anthony

-- 
Anthony Williams            | Just Software Solutions Ltd
Custom Software Development | http://www.justsoftwaresolutions.co.uk
Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL

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