1 /* 2 Copyright (C) 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 int arb_contains_int(const arb_t x)15arb_contains_int(const arb_t x) 16 { 17 if (arf_is_int(arb_midref(x))) 18 { 19 return 1; 20 } 21 else if (!arb_is_finite(x)) 22 { 23 return arb_contains_zero(x); 24 } 25 else if (arb_is_exact(x)) 26 { 27 return 0; 28 } 29 else if (mag_cmp_2exp_si(arb_radref(x), -1) >= 0) /* radius >= 1/2 */ 30 { 31 return 1; 32 } 33 else 34 { 35 /* radius is < 1/2, so it's enough to test the two integers 36 bracketing the midpoint */ 37 arf_t t; 38 int res; 39 arf_init(t); 40 arf_floor(t, arb_midref(x)); 41 42 res = arb_contains_arf(x, t); 43 if (!res) 44 { 45 arf_ceil(t, arb_midref(x)); 46 res = arb_contains_arf(x, t); 47 } 48 49 arf_clear(t); 50 return res; 51 } 52 } 53 54