1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
Copyright (C) 2011 Sebastian Pancratz
This file is part of FLINT.
FLINT is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 3 of the License, or
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/
#include "fmpq.h"
void _fmpq_pow_si(fmpz_t rnum, fmpz_t rden,
const fmpz_t opnum, const fmpz_t opden, slong e)
{
if (e >= 0)
{
fmpz_pow_ui(rnum, opnum, e);
fmpz_pow_ui(rden, opden, e);
}
else
{
if (rnum == opnum)
{
fmpz t;
fmpz_pow_ui(rnum, opnum, -e);
fmpz_pow_ui(rden, opden, -e);
t = *rnum;
*rnum = *rden;
*rden = t;
}
else
{
fmpz_pow_ui(rden, opnum, -e);
fmpz_pow_ui(rnum, opden, -e);
}
if (fmpz_sgn(rden) < 0)
{
fmpz_neg(rnum, rnum);
fmpz_neg(rden, rden);
}
}
}
void fmpq_pow_si(fmpq_t rop, const fmpq_t op, slong e)
{
if (e < 0 && fmpz_is_zero(fmpq_numref(op)))
{
flint_throw(FLINT_DIVZERO, "Exception (fmpq_pow_si). Division by zero.\n");
}
_fmpq_pow_si(fmpq_numref(rop), fmpq_denref(rop),
fmpq_numref(op), fmpq_denref(op), e);
}