1 /*
2     Copyright (C) 2012 Fredrik Johansson
3     Copyright (C) 2015 Arb authors
4 
5     This file is part of Arb.
6 
7     Arb is free software: you can redistribute it and/or modify it under
8     the terms of the GNU Lesser General Public License (LGPL) as published
9     by the Free Software Foundation; either version 2.1 of the License, or
10     (at your option) any later version.  See <http://www.gnu.org/licenses/>.
11 */
12 
13 #include "arf.h"
14 
15 void
arf_fprint(FILE * file,const arf_t x)16 arf_fprint(FILE * file, const arf_t x)
17 {
18     if (arf_is_normal(x))
19     {
20         fmpz_t man, exp;
21 
22         fmpz_init(man);
23         fmpz_init(exp);
24 
25         arf_get_fmpz_2exp(man, exp, x);
26 
27         flint_fprintf(file, "(");
28         fmpz_fprint(file, man);
29         flint_fprintf(file, " * 2^");
30         fmpz_fprint(file, exp);
31         flint_fprintf(file, ")");
32 
33         fmpz_clear(man);
34         fmpz_clear(exp);
35     }
36     else
37     {
38         if (arf_is_zero(x)) flint_fprintf(file, "(0)");
39         else if (arf_is_pos_inf(x)) flint_fprintf(file, "(+inf)");
40         else if (arf_is_neg_inf(x)) flint_fprintf(file, "(-inf)");
41         else flint_fprintf(file, "(nan)");
42     }
43 }
44 
45 void
arf_fprintd(FILE * file,const arf_t x,slong d)46 arf_fprintd(FILE * file, const arf_t x, slong d)
47 {
48     if (arf_is_finite(x) && (ARF_EXP(x) <= MPFR_EMIN_MIN + 1 ||
49                              ARF_EXP(x) >= MPFR_EMAX_MAX - 1))
50     {
51         arf_fprint(file, x);
52     }
53     else
54     {
55         mpfr_t t;
56         mpfr_init2(t, d * 3.33 + 10);
57         mpfr_set_emin(MPFR_EMIN_MIN);
58         mpfr_set_emax(MPFR_EMAX_MAX);
59         arf_get_mpfr(t, x, MPFR_RNDN);
60         mpfr_fprintf(file, "%.*Rg", FLINT_MAX(d, 1), t);
61         mpfr_clear(t);
62     }
63 }
64 
65