1 /*
2 Copyright (C) 2012-2014 Fredrik Johansson
3
4 This file is part of Arb.
5
6 Arb 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 "arb.h"
13
14 void
arb_sub(arb_t z,const arb_t x,const arb_t y,slong prec)15 arb_sub(arb_t z, const arb_t x, const arb_t y, slong prec)
16 {
17 int inexact;
18
19 inexact = arf_sub(arb_midref(z), arb_midref(x), arb_midref(y), prec, ARB_RND);
20
21 mag_add(arb_radref(z), arb_radref(x), arb_radref(y));
22 if (inexact)
23 arf_mag_add_ulp(arb_radref(z), arb_radref(z), arb_midref(z), prec);
24 }
25
26 void
arb_sub_arf(arb_t z,const arb_t x,const arf_t y,slong prec)27 arb_sub_arf(arb_t z, const arb_t x, const arf_t y, slong prec)
28 {
29 int inexact;
30 inexact = arf_sub(arb_midref(z), arb_midref(x), y, prec, ARB_RND);
31 if (inexact)
32 arf_mag_add_ulp(arb_radref(z), arb_radref(x), arb_midref(z), prec);
33 else
34 mag_set(arb_radref(z), arb_radref(x));
35 }
36
37 void
arb_sub_ui(arb_t z,const arb_t x,ulong y,slong prec)38 arb_sub_ui(arb_t z, const arb_t x, ulong y, slong prec)
39 {
40 int inexact;
41 inexact = arf_sub_ui(arb_midref(z), arb_midref(x), y, prec, ARB_RND);
42 if (inexact)
43 arf_mag_add_ulp(arb_radref(z), arb_radref(x), arb_midref(z), prec);
44 else
45 mag_set(arb_radref(z), arb_radref(x));
46 }
47
48 void
arb_sub_si(arb_t z,const arb_t x,slong y,slong prec)49 arb_sub_si(arb_t z, const arb_t x, slong y, slong prec)
50 {
51 int inexact;
52 inexact = arf_sub_si(arb_midref(z), arb_midref(x), y, prec, ARB_RND);
53 if (inexact)
54 arf_mag_add_ulp(arb_radref(z), arb_radref(x), arb_midref(z), prec);
55 else
56 mag_set(arb_radref(z), arb_radref(x));
57 }
58
59 void
arb_sub_fmpz(arb_t z,const arb_t x,const fmpz_t y,slong prec)60 arb_sub_fmpz(arb_t z, const arb_t x, const fmpz_t y, slong prec)
61 {
62 int inexact;
63 inexact = arf_sub_fmpz(arb_midref(z), arb_midref(x), y, prec, ARB_RND);
64 if (inexact)
65 arf_mag_add_ulp(arb_radref(z), arb_radref(x), arb_midref(z), prec);
66 else
67 mag_set(arb_radref(z), arb_radref(x));
68 }
69
70