Representing +inf, -inf and nan in mpq_class objects

Roberto Bagnara bagnara at cs.unipr.it
Sat Oct 4 10:29:41 CEST 2003


I need a class of rationals extended with +inf, -inf and nan,
and I also need to minimize memory occupation.
I am wondering if it is safe to represent them with the fractions
1/0, -1/0 and 0/0 as objects of type mpq_class.  All the required
operations (basically addition and comparisons is all I need)
would be redefined so as to test for the special cases first
and handle them in the appropriate way, resorting to normal mpz_class
operations only for normal values.

So I guess the question is: is there something in the present
(and, conceivably, future) design of mpz_class for which

- sticking 1/0, -1/0 or 0/0 into an object and
- testing for the presence of such special values in an object

may cause wrong or undefined behavior?
This may happen, e.g., if the (present or future) implementation
does too much automatic canonicalization.
What do you think?
Cheers,

      Roberto

-- 
Prof. Roberto Bagnara
Computer Science Group
Department of Mathematics, University of Parma, Italy
http://www.cs.unipr.it/~bagnara/
mailto:bagnara at cs.unipr.it



More information about the gmp-discuss mailing list