On 3 May 2015 at 12:51, <20100.delecr...@gmail.com> wrote: > Hello, > > I would like to know whether it it is possible to compare a mpz_t and a > mpq_t more efficiently than: > - creating a mpq_t with denominator 1 > - swap the numerator with the mpz_t > - call mpq_cmp > - swap back the numerator with the mpz_t > - free the memory of the mpq_t >
Sure. Take a look at the mpq_numref and mpq_denref functions. There is no need to create an mpq_t, though you do need a temporary mpz_t for the result of the multiplication. Of course, any function which performed such a comparison would have to create this internally anyway. So in terms of efficiency, it's about the best you can do. You can special case denominator = 1 or numerator = 0 and a few other cases like that. But it's about the best you can do. > > If not, would it be useful to have this as a standalone function (like > "mpq_cmp_mpz")? There is a need within Sage [1,2] where often integer and > rational types are mixed. > I'd be inclined to just add such a thing as a macro if you need it often. It's only about four lines to implement. Bill. > > Cheers, > Vincent > > [1] http://sagemath.org > [2] downstream ticket: http://trac.sagemath.org/ticket/18304 > > -- > You received this message because you are subscribed to the Google Groups > "mpir-devel" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to mpir-devel+unsubscr...@googlegroups.com. > To post to this group, send email to mpir-devel@googlegroups.com. > Visit this group at http://groups.google.com/group/mpir-devel. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "mpir-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to mpir-devel+unsubscr...@googlegroups.com. To post to this group, send email to mpir-devel@googlegroups.com. Visit this group at http://groups.google.com/group/mpir-devel. For more options, visit https://groups.google.com/d/optout.