add get/set_fmpz_2exp methods

This commit is contained in:
Fredrik Johansson 2012-09-10 16:33:59 +02:00
parent 621c0fc031
commit 5c861c5329
4 changed files with 165 additions and 0 deletions

4
fmpr.h
View file

@ -558,6 +558,10 @@ void fmpr_get_fmpq(fmpq_t y, const fmpr_t x);
long fmpr_set_fmpq(fmpr_t x, const fmpq_t y, long prec, fmpr_rnd_t rnd);
void fmpr_set_fmpz_2exp(fmpr_t x, const fmpz_t man, const fmpz_t exp);
void fmpr_get_fmpz_2exp(fmpz_t man, fmpz_t exp, const fmpr_t x);
#define CALL_MPFR_FUNC(r, func, y, x, prec, rnd) \
do { \
mpfr_t t, u; \

41
fmpr/get_fmpz_2exp.c Normal file
View file

@ -0,0 +1,41 @@
/*=============================================================================
This file is part of ARB.
ARB is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ARB is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ARB; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2012 Fredrik Johansson
******************************************************************************/
#include "fmpr.h"
void
fmpr_get_fmpz_2exp(fmpz_t man, fmpz_t exp, const fmpr_t x)
{
if (fmpr_is_zero(x))
{
fmpz_zero(man);
fmpz_zero(exp);
}
else
{
fmpz_set(man, fmpr_manref(x));
fmpz_set(exp, fmpr_expref(x));
}
}

40
fmpr/set_fmpz_2exp.c Normal file
View file

@ -0,0 +1,40 @@
/*=============================================================================
This file is part of ARB.
ARB is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ARB is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ARB; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2012 Fredrik Johansson
******************************************************************************/
#include "fmpr.h"
void
fmpr_set_fmpz_2exp(fmpr_t x, const fmpz_t man, const fmpz_t exp)
{
if (fmpz_is_zero(man))
{
fmpr_zero(x);
}
else
{
fmpr_set_fmpz(x, man);
fmpz_add(fmpr_expref(x), fmpr_expref(x), exp);
}
}

View file

@ -0,0 +1,80 @@
/*=============================================================================
This file is part of ARB.
ARB is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ARB is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ARB; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2012 Fredrik Johansson
******************************************************************************/
#include "fmpr.h"
int main()
{
long iter;
flint_rand_t state;
printf("set_fmpz_2exp....");
fflush(stdout);
flint_randinit(state);
/* test exact roundtrip R -> Q -> R */
for (iter = 0; iter < 100000; iter++)
{
long bits;
fmpr_t x, z;
fmpz_t y, e;
bits = 2 + n_randint(state, 200);
fmpr_init(x);
fmpr_init(z);
fmpz_init(y);
fmpz_init(e);
fmpr_randtest(x, state, bits, 10);
fmpr_randtest(z, state, bits, 10);
fmpr_get_fmpz_2exp(y, e, x);
fmpr_set_fmpz_2exp(z, y, e);
if (!fmpr_equal(x, z))
{
printf("FAIL\n\n");
printf("bits: %ld\n", bits);
printf("x = "); fmpr_print(x); printf("\n\n");
printf("y = "); fmpz_print(y); printf("\n\n");
printf("e = "); fmpz_print(e); printf("\n\n");
printf("z = "); fmpr_print(z); printf("\n\n");
abort();
}
fmpr_clear(x);
fmpr_clear(z);
fmpz_clear(y);
fmpz_clear(e);
}
flint_randclear(state);
_fmpz_cleanup();
printf("PASS\n");
return EXIT_SUCCESS;
}