new beta-0.90.0
[luatex.git] / source / libs / gmp / gmp-src / mpq / cmp_si.c
blobf21382e5b0460a7564f811ccfd93685b07f3c667
1 /* _mpq_cmp_si -- compare mpq and long/ulong fraction.
3 Copyright 2001, 2013, 2014 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
7 The GNU MP Library is free software; you can redistribute it and/or modify
8 it under the terms of either:
10 * the GNU Lesser General Public License as published by the Free
11 Software Foundation; either version 3 of the License, or (at your
12 option) any later version.
16 * the GNU General Public License as published by the Free Software
17 Foundation; either version 2 of the License, or (at your option) any
18 later version.
20 or both in parallel, as here.
22 The GNU MP Library is distributed in the hope that it will be useful, but
23 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 for more details.
27 You should have received copies of the GNU General Public License and the
28 GNU Lesser General Public License along with the GNU MP Library. If not,
29 see https://www.gnu.org/licenses/. */
31 #include "gmp.h"
32 #include "gmp-impl.h"
35 /* Something like mpq_cmpabs_ui would be more useful for the neg/neg case,
36 and perhaps a version accepting a parameter to reverse the test, to make
37 it a tail call here. */
39 int
40 _mpq_cmp_si (mpq_srcptr q, long n, unsigned long d)
42 /* need canonical sign to get right result */
43 ASSERT (SIZ(DEN(q)) > 0);
45 if (n >= 0)
46 return _mpq_cmp_ui (q, n, d);
47 if (SIZ(NUM(q)) >= 0)
49 return 1; /* >=0 cmp <0 */
51 else
53 mpq_t qabs;
54 SIZ(NUM(qabs)) = -SIZ(NUM(q));
55 PTR(NUM(qabs)) = PTR(NUM(q));
56 SIZ(DEN(qabs)) = SIZ(DEN(q));
57 PTR(DEN(qabs)) = PTR(DEN(q));
59 return - _mpq_cmp_ui (qabs, NEG_CAST (unsigned long, n), d); /* <0 cmp <0 */