arb/fmpr/test/t-normalise.c

112 lines
3.5 KiB
C
Raw Normal View History

2013-01-09 16:35:49 +01: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 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()
{
2015-11-05 18:03:08 +00:00
slong iter;
2013-01-09 16:35:49 +01:00
flint_rand_t state;
flint_printf("normalise....");
2013-01-09 16:35:49 +01:00
fflush(stdout);
flint_randinit(state);
for (iter = 0; iter < 1000000 * arb_test_multiplier(); iter++)
2013-01-09 16:35:49 +01:00
{
fmpr_t x, xcopy, y, err_bound, err;
2015-11-05 18:03:08 +00:00
slong prec, ret1, ret2, bits, ebits;
2013-01-09 16:35:49 +01:00
fmpr_rnd_t rnd;
fmpr_init(x);
fmpr_init(xcopy);
2013-01-09 16:35:49 +01:00
fmpr_init(y);
fmpr_init(err_bound);
fmpr_init(err);
2013-01-09 16:35:49 +01:00
bits = 2 + n_randint(state, 2000);
ebits = 2 + n_randint(state, 200);
fmpz_randtest_not_zero(fmpr_manref(x), state, bits);
fmpz_randtest(fmpr_expref(x), state, ebits);
2013-01-09 16:35:49 +01:00
fmpz_set(fmpr_manref(y), fmpr_manref(x));
fmpz_set(fmpr_expref(y), fmpr_expref(x));
fmpr_set(xcopy, x);
2013-01-09 16:35:49 +01:00
switch (n_randint(state, 4))
{
case 0: rnd = FMPR_RND_DOWN; break;
case 1: rnd = FMPR_RND_UP; break;
case 2: rnd = FMPR_RND_FLOOR; break;
default: rnd = FMPR_RND_CEIL; break;
}
prec = 2 + n_randint(state, 2000);
ret1 = _fmpr_normalise(fmpr_manref(x), fmpr_expref(x), prec, rnd);
ret2 = _fmpr_normalise_naive(fmpr_manref(y), fmpr_expref(y), prec, rnd);
if (!fmpr_equal(x, y) || ret1 != ret2)
{
flint_printf("FAIL!\n");
flint_printf("x = "); fmpr_print(x); flint_printf("\n\n");
flint_printf("y = "); fmpr_print(y); flint_printf("\n\n");
flint_printf("ret1 = %wd, ret2 = %wd\n", ret1, ret2);
2013-01-09 16:35:49 +01:00
abort();
}
fmpr_sub(err, x, xcopy, FMPR_PREC_EXACT, FMPR_RND_DOWN);
fmpr_abs(err, err);
fmpr_set_error_result(err_bound, x, ret1);
if (fmpr_cmp(err, err_bound) > 0)
{
flint_printf("FAIL (error bound)!\n");
flint_printf("x (original) = "); fmpr_print(xcopy); flint_printf("\n\n");
flint_printf("x = "); fmpr_print(x); flint_printf("\n\n");
flint_printf("error: "); fmpr_print(err); flint_printf("\n\n");
flint_printf("error bound: "); fmpr_print(err_bound); flint_printf("\n\n");
flint_printf("ret = %wd\n", ret1);
abort();
}
2013-01-09 16:35:49 +01:00
fmpr_clear(x);
fmpr_clear(xcopy);
2013-01-09 16:35:49 +01:00
fmpr_clear(y);
fmpr_clear(err_bound);
fmpr_clear(err);
2013-01-09 16:35:49 +01:00
}
flint_randclear(state);
2013-07-30 13:53:10 +02:00
flint_cleanup();
flint_printf("PASS\n");
2013-01-09 16:35:49 +01:00
return EXIT_SUCCESS;
}