Boost logo

Boost :

From: Jonathan Wakely (cow_at_[hidden])
Date: 2004-12-13 11:44:56


On Mon, Dec 13, 2004 at 01:51:20AM +0100, Andras Erdei wrote:

> maybe i'm not describing the problem clearly (or misunderstand something):
>
> every other finite precision type rounds or truncates
> the result, while rational<> returns unrelated garbage
> when it is not exactly representable

The garbage is not completely unrelated - it's caused by overflow.

There is no rounding or truncating in this operation:

    int i = INT_MAX * INT_MAX;

but the result is wrong.

> it is important that we are not talking about overflow
> (results out of the representable range), but "sideflow",
> when the result falls between two representable numbers

I disagree - the problem is that an intermediate value overflows, not
that the final result is not an integer.

Maybe boost::rational could be made to use a large type for all builtin
integral types. That way the intermediate result would be found using a
higher precision than the final result and the chances of the
intermediate result overflowing would be lessened.

For all signed integral types use long and for all unsigned use unsigned
long. Could even use long long where available, but that might affect
performance negatively.

jon

-- 
"Reality is that which, when you stop believing in it, doesn't go away."
	- Phillip K. Dick

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