2016-04-26 17:20:05 +02:00
|
|
|
/*
|
2014-05-06 15:31:17 +02:00
|
|
|
Copyright (C) 2014 Fredrik Johansson
|
|
|
|
|
2016-04-26 17:20:05 +02:00
|
|
|
This file is part of Arb.
|
|
|
|
|
|
|
|
Arb 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 2.1 of the License, or
|
|
|
|
(at your option) any later version. See <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2014-05-06 15:31:17 +02:00
|
|
|
|
2014-05-08 14:48:36 +02:00
|
|
|
#include "arf.h"
|
2014-05-06 15:31:17 +02:00
|
|
|
|
|
|
|
void
|
2014-05-08 14:48:36 +02:00
|
|
|
arf_get_mag(mag_t y, const arf_t x)
|
2014-05-06 15:31:17 +02:00
|
|
|
{
|
|
|
|
if (arf_is_zero(x))
|
|
|
|
{
|
|
|
|
mag_zero(y);
|
|
|
|
}
|
|
|
|
else if (arf_is_special(x))
|
|
|
|
{
|
|
|
|
mag_inf(y);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-08 14:48:36 +02:00
|
|
|
mp_limb_t t, u;
|
|
|
|
|
|
|
|
ARF_GET_TOP_LIMB(t, x);
|
|
|
|
t = (t >> (FLINT_BITS - MAG_BITS)) + LIMB_ONE;
|
2016-04-10 23:54:20 +02:00
|
|
|
|
|
|
|
/* may have rounded up to next power of two */
|
2014-05-08 14:48:36 +02:00
|
|
|
u = t >> MAG_BITS;
|
2016-04-10 23:54:20 +02:00
|
|
|
/* todo: avoid the addition? check agreement with mag_fast_init_set_arf */
|
|
|
|
t = (t >> u) + (u & t);
|
|
|
|
|
2014-05-08 14:48:36 +02:00
|
|
|
_fmpz_add_fast(MAG_EXPREF(y), ARF_EXPREF(x), u);
|
|
|
|
MAG_MAN(y) = t;
|
2014-05-06 15:31:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-08 16:49:39 +02:00
|
|
|
void
|
|
|
|
arf_get_mag_lower(mag_t y, const arf_t x)
|
|
|
|
{
|
|
|
|
if (arf_is_zero(x))
|
|
|
|
{
|
|
|
|
mag_zero(y);
|
|
|
|
}
|
|
|
|
else if (arf_is_special(x))
|
|
|
|
{
|
2015-04-19 05:42:29 +02:00
|
|
|
if (arf_is_nan(x))
|
|
|
|
mag_zero(y);
|
|
|
|
else
|
|
|
|
mag_inf(y);
|
2014-05-08 16:49:39 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mp_limb_t t;
|
|
|
|
ARF_GET_TOP_LIMB(t, x);
|
|
|
|
MAG_MAN(y) = t >> (FLINT_BITS - MAG_BITS);
|
|
|
|
_fmpz_set_fast(MAG_EXPREF(y), ARF_EXPREF(x));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|