1 /*
2     Copyright (C) 2014 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 "flint/double_extras.h"
13 #include "mag.h"
14 
15 void
mag_set_d_2exp_fmpz(mag_t z,double c,const fmpz_t exp)16 mag_set_d_2exp_fmpz(mag_t z, double c, const fmpz_t exp)
17 {
18     if (c < 0.0)
19         c = -c;
20 
21     if (c == 0.0)
22     {
23         mag_zero(z);
24     }
25     else if ((c != c) || c == D_INF)
26     {
27         mag_inf(z);
28     }
29     else
30     {
31         slong cexp = *exp;
32 
33         if (cexp >= MAG_MIN_LAGOM_EXP && cexp <= MAG_MAX_LAGOM_EXP)
34         {
35             _fmpz_demote(MAG_EXPREF(z));
36             MAG_SET_D_2EXP(MAG_MAN(z), MAG_EXP(z), c, cexp);
37         }
38         else
39         {
40             MAG_SET_D_2EXP(MAG_MAN(z), cexp, c, 0);
41             fmpz_add_si(MAG_EXPREF(z), exp, cexp);
42         }
43     }
44 }
45 
46 void
mag_set_d_2exp_fmpz_lower(mag_t z,double c,const fmpz_t exp)47 mag_set_d_2exp_fmpz_lower(mag_t z, double c, const fmpz_t exp)
48 {
49     if (c < 0.0)
50         c = -c;
51 
52     if (c == 0.0 || (c != c))
53     {
54         mag_zero(z);
55     }
56     else if (c == D_INF)
57     {
58         mag_inf(z);
59     }
60     else
61     {
62         slong cexp = *exp;
63 
64         if (cexp >= MAG_MIN_LAGOM_EXP && cexp <= MAG_MAX_LAGOM_EXP)
65         {
66             _fmpz_demote(MAG_EXPREF(z));
67             MAG_SET_D_2EXP_LOWER(MAG_MAN(z), MAG_EXP(z), c, cexp);
68         }
69         else
70         {
71             MAG_SET_D_2EXP_LOWER(MAG_MAN(z), cexp, c, 0);
72             fmpz_add_si(MAG_EXPREF(z), exp, cexp);
73         }
74     }
75 }
76 
77