Boost logo

Boost :

From: Daryle Walker (darylew_at_[hidden])
Date: 2001-04-01 15:27:06

on 3/30/01 2:05 PM, nbecker_at_[hidden] wrote:

> In working on DSP, I often need to use integer types of particular bit
> widths. Although I have seen some other attempts to develop C++
> classes for this purpose, they usually are not what I am looking for.

Have you checked out "" in the vault?

> In order to simulate the effects of finite-width integers, all that is
> really needed is:
> 1) Check during construction and assignment
> 2) Conversion back to int.
> This of course assumes the bit width is less than or equal to the
> natural size of int.

As I found out during CRCs, bit-shifting by (at least) the bit length leads
to undefined behavior. You may have to special-case when the width equals
int's natural size. This is for Wrap::pmask, Wrap::nmask, and Int::mask.
Or you could make the width >= natural-size cases undefined, and assume the
user sets the width less than that.

> Here is my submission. Please let me know what you think.
[SNIP attachments]

You don't have to hard-code the width around "int," you can use the
templates in <boost/integer.hpp> to find the best type.

You don't have to pass the Assign policy as a template parameter, it can be
passed in as a type parameter ("Wrap<width>" instead of "Wrap"). This
allows non-template classes be used as policies. Also, I don't think any
Boost template yet uses template-based template parameters, so this class
would have to be a test case for adding template-based template parameter
checks to <boost/config.hpp>.

Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com

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