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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
Copyright (C) 2016 Fredrik Johansson
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 3 of the License, or
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/
#include <mpfr.h>
#include "arb.h"
int mpfr_round_p(nn_srcptr, slong, mpfr_exp_t, mpfr_prec_t);
int
arb_can_round_arf(const arb_t x, slong prec, arf_rnd_t rnd)
{
return arb_can_round_mpfr(x, prec, arf_rnd_to_mpfr(rnd));
}
int
arb_can_round_mpfr(const arb_t x, slong prec, mpfr_rnd_t rnd)
{
if (!arb_is_finite(x))
{
return 0;
}
else if (mag_is_zero(arb_radref(x)))
{
return 1;
}
else if (arf_is_zero(arb_midref(x)))
{
return 0;
}
else
{
slong e, bits;
slong n;
nn_srcptr d;
e = _fmpz_sub_small(ARF_EXPREF(arb_midref(x)), MAG_EXPREF(arb_radref(x)));
if (e < prec)
return 0;
/* The relative exponent could be tiny (in which case _fmpz_sub_small
has clamped it). Looking just past the end will be enough. */
bits = arb_bits(x);
e = FLINT_MIN(e, FLINT_MAX(bits, prec) + 10);
ARF_GET_MPN_READONLY(d, n, arb_midref(x));
return mpfr_round_p(d, n, e, prec + (rnd == MPFR_RNDN));
}
}