Add "device uether" to various manual pages' synopses.
[dragonfly.git] / contrib / gmp / mpz / divexact.c
blob95ba31112f852be800c38b24c5833e93676fabc5
1 /* mpz_divexact -- finds quotient when known that quot * den == num && den != 0.
3 Contributed to the GNU project by Niels Möller.
5 Copyright 1991, 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2005,
6 2006, 2007, 2009 Free Software Foundation, Inc.
8 This file is part of the GNU MP Library.
10 The GNU MP Library is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or (at your
13 option) any later version.
15 The GNU MP Library is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 License for more details.
20 You should have received a copy of the GNU Lesser General Public License
21 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
24 #include "gmp.h"
25 #include "gmp-impl.h"
26 #include "longlong.h"
28 void
29 mpz_divexact (mpz_ptr quot, mpz_srcptr num, mpz_srcptr den)
31 mp_ptr qp;
32 mp_size_t qn;
33 mp_srcptr np, dp;
34 mp_size_t nn, dn;
35 TMP_DECL;
37 #if WANT_ASSERT
39 mpz_t rem;
40 mpz_init (rem);
41 mpz_tdiv_r (rem, num, den);
42 ASSERT (SIZ(rem) == 0);
43 mpz_clear (rem);
45 #endif
47 nn = ABSIZ (num);
48 dn = ABSIZ (den);
50 qn = nn - dn + 1;
51 MPZ_REALLOC (quot, qn);
53 if (nn < dn)
55 /* This special case avoids segfaults below when the function is
56 incorrectly called with |N| < |D|, N != 0. It also handles the
57 well-defined case N = 0. */
58 SIZ(quot) = 0;
59 return;
62 TMP_MARK;
64 qp = PTR(quot);
66 if (quot == num || quot == den)
67 qp = TMP_ALLOC_LIMBS (qn);
69 np = PTR(num);
70 dp = PTR(den);
72 mpn_divexact (qp, np, nn, dp, dn);
73 MPN_NORMALIZE (qp, qn);
75 SIZ(quot) = (SIZ(num) ^ SIZ(den)) >= 0 ? qn : -qn;
77 if (qp != PTR(quot))
78 MPN_COPY (PTR(quot), qp, qn);
80 TMP_FREE;