Boost logo

Boost :

From: Jens Maurer (Jens.Maurer_at_[hidden])
Date: 2001-04-02 14:21:45


nbecker_at_[hidden] wrote:

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

(I haven't looked closely at your code, so the following may be
way off.)

If the bit width is equal to the natural size of "int", how are
you going to detect overflow in the constructor? The overflow
has happened unnoticed during (e.g.) the add, and the overflow
information is gone.

Plus, even for bit widths smaller than "int", I could imagine
that carefully crafted multiplications can result in unnoticed
overflow as well.

Such a "checking" class seems useful (possibly with machine-dependent
specializations), but it should be functional in all cases. And,
I dislike the automatic conversion to "int".

Jens Maurer


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