1 /*
2     Copyright (C) 2012 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 int
arb_overlaps(const arb_t x,const arb_t y)15 arb_overlaps(const arb_t x, const arb_t y)
16 {
17     arf_t t;
18     arf_struct u[4];
19     int result;
20 
21     if (mag_is_inf(arb_radref(x)) || mag_is_inf(arb_radref(y)))
22         return 1;
23 
24     if (arf_equal(arb_midref(x), arb_midref(y)))
25         return 1;
26 
27     arf_init(t);
28 
29     /* |xm - ym| <= xr + yr */
30 
31     if (arf_cmp(arb_midref(x), arb_midref(y)) >= 0)
32     {
33         arf_init_set_shallow(u + 0, arb_midref(x));
34         arf_init_neg_shallow(u + 1, arb_midref(y));
35     }
36     else
37     {
38         arf_init_neg_shallow(u + 0, arb_midref(x));
39         arf_init_set_shallow(u + 1, arb_midref(y));
40     }
41 
42     arf_init_neg_mag_shallow(u + 2, arb_radref(x));
43     arf_init_neg_mag_shallow(u + 3, arb_radref(y));
44 
45     arf_sum(t, u, 4, MAG_BITS, ARF_RND_DOWN);
46     result = arf_sgn(t) <= 0;
47 
48     arf_clear(t);
49 
50     return result;
51 }
52 
53