1 /*
2 Copyright (C) 2018 Daniel Schultz
3
4 This file is part of FLINT.
5
6 FLINT is free software: you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License (LGPL) as published
8 by the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version. See <http://www.gnu.org/licenses/>.
10 */
11
12 #include "fmpq_mpoly.h"
13
14
fmpq_mpoly_div(fmpq_mpoly_t Q,const fmpq_mpoly_t A,const fmpq_mpoly_t B,const fmpq_mpoly_ctx_t ctx)15 void fmpq_mpoly_div(fmpq_mpoly_t Q, const fmpq_mpoly_t A, const fmpq_mpoly_t B,
16 const fmpq_mpoly_ctx_t ctx)
17 {
18 fmpz_t scale;
19
20 if (fmpq_mpoly_is_zero(B, ctx))
21 {
22 flint_throw(FLINT_DIVZERO, "Divide by zero in fmpq_mpoly_div");
23 }
24
25 if (fmpq_mpoly_is_zero(A, ctx))
26 {
27 fmpq_mpoly_zero(Q, ctx);
28 return;
29 }
30
31 fmpz_init(scale);
32 fmpz_mpoly_quasidiv(scale, Q->zpoly, A->zpoly, B->zpoly, ctx->zctx);
33
34 fmpq_div(Q->content, A->content, B->content);
35 fmpq_div_fmpz(Q->content, Q->content, scale);
36 fmpz_clear(scale);
37
38 fmpq_mpoly_reduce(Q, ctx);
39 }
40