forked from flintlib/flint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgcd_ui.c
35 lines (31 loc) · 875 Bytes
/
gcd_ui.c
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
/*
Copyright (C) 2021 Albin Ahlbäck
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 2.1 of the License, or
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/
#include <gmp.h>
#include "fmpz.h"
void
fmpz_gcd_ui(fmpz_t res, const fmpz_t a, ulong b)
{
if (b == 0)
fmpz_abs(res, a);
else if (!COEFF_IS_MPZ(*a))
{
if (*a != 0)
{
_fmpz_demote(res);
*res = mpn_gcd_1(&b, 1, FLINT_ABS(*a));
}
else
fmpz_set_ui(res, b);
}
else
{
__mpz_struct * ma = COEFF_TO_PTR(*a);
fmpz_set_ui(res, mpn_gcd_1(ma->_mp_d, FLINT_ABS(ma->_mp_size), b));
}
}