mirror of
https://github.com/vale981/arb
synced 2025-03-06 09:51:39 -05:00
103 lines
3.2 KiB
C
103 lines
3.2 KiB
C
/*=============================================================================
|
|
|
|
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) 2015 Fredrik Johansson
|
|
|
|
******************************************************************************/
|
|
|
|
#include "acb.h"
|
|
|
|
int main()
|
|
{
|
|
slong iter;
|
|
flint_rand_t state;
|
|
|
|
flint_printf("quadratic_roots_fmpz....");
|
|
fflush(stdout);
|
|
|
|
flint_randinit(state);
|
|
|
|
for (iter = 0; iter < 10000; iter++)
|
|
{
|
|
acb_t r1, r2, x, y;
|
|
fmpz_t a, b, c;
|
|
slong prec;
|
|
|
|
fmpz_init(a);
|
|
fmpz_init(b);
|
|
fmpz_init(c);
|
|
|
|
acb_init(r1);
|
|
acb_init(r2);
|
|
acb_init(x);
|
|
acb_init(y);
|
|
|
|
prec = 2 + n_randint(state, 1000);
|
|
|
|
fmpz_randtest_not_zero(a, state, 1 + n_randint(state, 1000));
|
|
fmpz_randtest(b, state, 1 + n_randint(state, 1000));
|
|
fmpz_randtest(c, state, 1 + n_randint(state, 1000));
|
|
|
|
acb_randtest(r1, state, 1 + n_randint(state, 1000), 1 + n_randint(state, 100));
|
|
acb_randtest(r2, state, 1 + n_randint(state, 1000), 1 + n_randint(state, 100));
|
|
|
|
acb_quadratic_roots_fmpz(r1, r2, a, b, c, prec);
|
|
|
|
acb_mul(x, r1, r1, prec);
|
|
acb_mul_fmpz(x, x, a, prec);
|
|
acb_addmul_fmpz(x, r1, b, prec);
|
|
acb_add_fmpz(x, x, c, prec);
|
|
|
|
acb_mul(y, r2, r2, prec);
|
|
acb_mul_fmpz(y, y, a, prec);
|
|
acb_addmul_fmpz(y, r2, b, prec);
|
|
acb_add_fmpz(y, y, c, prec);
|
|
|
|
if (!acb_contains_zero(x) || !acb_contains_zero(y) ||
|
|
acb_rel_accuracy_bits(r1) < prec - 4 ||
|
|
acb_rel_accuracy_bits(r2) < prec - 4)
|
|
{
|
|
flint_printf("FAIL: containment / accuracy\n\n");
|
|
flint_printf("prec = %wd\n", prec);
|
|
flint_printf("a = "); fmpz_print(a); flint_printf("\n\n");
|
|
flint_printf("b = "); fmpz_print(b); flint_printf("\n\n");
|
|
flint_printf("c = "); fmpz_print(c); flint_printf("\n\n");
|
|
flint_printf("r1 = "); acb_printd(r1, 30); flint_printf("\n\n");
|
|
flint_printf("r2 = "); acb_printd(r2, 30); flint_printf("\n\n");
|
|
abort();
|
|
}
|
|
|
|
fmpz_clear(a);
|
|
fmpz_clear(b);
|
|
fmpz_clear(c);
|
|
|
|
acb_clear(r1);
|
|
acb_clear(r2);
|
|
acb_clear(x);
|
|
acb_clear(y);
|
|
}
|
|
|
|
flint_randclear(state);
|
|
flint_cleanup();
|
|
flint_printf("PASS\n");
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|