Problem with assignment operator

Alex Stewart am2stewa at uwaterloo.ca
Wed Jan 12 15:46:30 CET 2005


On Tue, Jan 11, 2005 at 09:27:25PM +0100, Emmanuel Thomé wrote:
> On Tue, Jan 11, 2005 at 08:40:21PM +0100, Linus Nordberg wrote:
> > The denominator mustn't be negative.  From the fine manual, section
> > Rational Number Functions:
> > 
> > Wether a segfault is a reasonable punishment for not obeying this
> > rule or not, I couldn't tell.  Cc to the GMP discussion list.
> 
> You're killed by the copy in mpq_set. Not surprising, as input
> requirements are not met. period.
> 
> The c++ ctor should perhaps call mpq_canonicalize ; sounds reasonable
> to me at least.

No, since mpq_canonicalize removes GCDs and is currently quadratic.

Perhaps something less drastic, like moving a negative sign to the
numerator, would be a better choice.

Alex


More information about the gmp-discuss mailing list