Boost logo

Boost :

From: Stephen Silver (boost_at_[hidden])
Date: 2001-01-12 09:42:27


Paul Moore wrote:

> Thanks for the feedback. I've long wanted to have rationals based
> on arbitrary precision integers - that was my long-term goal as the
> "right" thing. Unfortunately, I haven't had access to an arbitrary
> precision integer type (nor the time/expertise to implement one).
> Any chance yours could be submitted to Boost?

I'm just using a simple (and currently incomplete) wrapper around GMP
mpz_t. I can send you a copy if you want to play with it, but it isn't
suitable for submission to Boost, since it won't work without GMP.

> Thanks for pointing this out. I won't use !! though (as someone
> pointed out in a later post, the integer type may not have operator!
> either). My initial preference is for "while (m != 0)" - would
> that cause a problem (I think it requires that the integer type
> be comparable with built-in integers, hardly an unreasonable
> requirement)?

"m != 0" would be OK. There are already places in rational.hpp where
you have used similar comparisons, but the requirement isn't currently
documented. I think the requirement should really be that there is
an implicit conversion from int to IntType (although "m != 0" may
well work without such a conversion). The boost::rational default
constructor already assumes that there is at least an explicit
conversion available.

I suggested "!!m" because operator! is likely to be more efficient than
operator!=. And !m works for all built-in arithmetic types, so it
seems reasonable that a user-defined arithmetic type should allow it.
(In any case, I think it would be a good idea if boost::rational had an
operator!.)

Stephen


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