1 /*
2     Copyright (C) 2012-2015 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_add_error_arf(arb_t x,const arf_t err)15 arb_add_error_arf(arb_t x, const arf_t err)
16 {
17     mag_t t;
18 
19     if (arf_is_zero(err))
20         return;
21 
22     if (mag_is_zero(arb_radref(x)))
23     {
24         arf_get_mag(arb_radref(x), err);
25         return;
26     }
27 
28     mag_init(t);
29     arf_get_mag(t, err);
30     mag_add(arb_radref(x), arb_radref(x), t);
31     mag_clear(t);
32 }
33 
34 void
arb_add_error_2exp_si(arb_t x,slong err)35 arb_add_error_2exp_si(arb_t x, slong err)
36 {
37     fmpz_t t;
38 
39     if (mag_is_zero(arb_radref(x)))
40     {
41         mag_one(arb_radref(x));
42         mag_mul_2exp_si(arb_radref(x), arb_radref(x), err);
43         return;
44     }
45 
46     fmpz_init(t);
47     fmpz_set_si(t, err);
48     mag_add_2exp_fmpz(arb_radref(x), arb_radref(x), t);
49     fmpz_clear(t);
50 }
51 
52 void
arb_add_error_2exp_fmpz(arb_t x,const fmpz_t err)53 arb_add_error_2exp_fmpz(arb_t x, const fmpz_t err)
54 {
55     if (mag_is_zero(arb_radref(x)))
56     {
57         mag_one(arb_radref(x));
58         mag_mul_2exp_fmpz(arb_radref(x), arb_radref(x), err);
59         return;
60     }
61 
62     mag_add_2exp_fmpz(arb_radref(x), arb_radref(x), err);
63 }
64 
65 void
arb_add_error(arb_t x,const arb_t err)66 arb_add_error(arb_t x, const arb_t err)
67 {
68     mag_t u;
69 
70     if (arb_is_zero(err))
71         return;
72 
73     if (mag_is_zero(arb_radref(x)))
74     {
75         arb_get_mag(arb_radref(x), err);
76         return;
77     }
78 
79     mag_init(u);
80     arb_get_mag(u, err);
81     mag_add(arb_radref(x), arb_radref(x), u);
82     mag_clear(u);
83 }
84 
85