Boost logo

Boost :

Subject: Re: [boost] [rational] Over/underflow checked update ready for comments
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2012-09-05 01:03:55

Le 05/09/12 01:04, Dan Searles a écrit :
>>>> Quick overview of the update: the original usage and
>>>> code of the template class remains mostly as before, ie
>>>> boost::rational<int> RationalVar; should work as
>>>> in the original version. Adding 'true' as a second
>>>> template parameter, however, allows an exception to
>>>> be raised if an operation with a class variable results
>>>> in a value that can't accurately be represented
>>> I haven't looked at anything else, but I dislike using true/false as the template argument. I'd prefer meaningful names.
>> Replaced the bool template parameter with an enum:
>> enum RationalChecktype {RationalNoChecking, RationalCheckforOverflow};
> For those interested in the rational number class, see:
> Requesting comments on the code, and review for
> inclusion in the next release.


the enum type could follow the one defined in

"When an overflow does occur, the desirable behavior depends on the
application, so programmers may specify the overflow mode with a value
of type |enum class overflow|. The possible values are:

    Programmer analysis of the program has determined that overflow
    cannot occur. Uses of this mode should be accompanied by an argument
    supporting the conclusion.
    Programmers are willing to accept undefined behavior in the event of
    an overflow.
    The assigned value is the dynamic value mod the range of the
    variable. This mode makes sense only with unsigned numbers. It is
    useful for angular measures.
    If the dynamic value exceeds the range of the variable, assign the
    nearest representable value.
    If the dynamic value exceeds the range of the variable, throw an
    exception of type |std::overflow_error|.

BTW, I have no access to the link for the examples and the test.

Could you update the History section?

In order to avoid breaking the existing interface, you could define a
class basic_rational that has the new template and define the current
rational using this basic_rational.

template <typename Integer, overflow Ov> class basic_rational;

template <typename Integer> class rational :
basic_rational<Integer,overflow::undefined> {...}


P.S A link to a standard proposal

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