Boost logo

Boost :

From: Herve Bronnimann (hbr_at_[hidden])
Date: 2000-10-18 14:38:13


On Wed, Oct 18, 2000 at 03:47:30PM +0100, Moore, Paul wrote:
> This gives rise to a question - is there any real-world need
> to access the numerator or denominator of a rational number, in general?
> (And if so, should there be a normalisation guarantee? At present the
> results are normalised, but that's not necessary...)

My .02: if you don't make the normalization guarantee, you'll have to
document the invalidation rules everywhere. Suppose I call
denominator(), then an operation which performs renormalization, then
numerator(), I might have a bad surprise if you haven't told me there
was a possibility of a renormalization.

This seems to indicate that always normalizing is the right thing to do.

> I may look at rewording this section of the documentation. Any suggestions
> would be gratefully received.

When you speak about numerator() and denominator(), you may want to
document that these are const member functions, i.e. they can't be used
to modify the value of the rational.

Finally: one reason you want to provide (at least) denominator: how do I
test if a rational is an integer, other than by denominator()==1 ?

And given that the test succeeds, simply taking numerator() instead of
making a conversion to an integral type seems more efficient. This would
also argue for the presence of numerator() as well.

Regards,

-- 
Hervé

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