mirror of
https://github.com/vale981/arb
synced 2025-03-06 09:51:39 -05:00
90 lines
2.6 KiB
C
90 lines
2.6 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) 2013 Fredrik Johansson
|
|
|
|
******************************************************************************/
|
|
|
|
#include "fmprb.h"
|
|
|
|
int main()
|
|
{
|
|
long iter;
|
|
flint_rand_t state;
|
|
|
|
printf("cos_pi_fmpq_algebraic....");
|
|
fflush(stdout);
|
|
|
|
flint_randinit(state);
|
|
|
|
for (iter = 0; iter < 10000; iter++)
|
|
{
|
|
fmprb_t c1, c2;
|
|
ulong p, q, g;
|
|
long prec;
|
|
|
|
prec = 2 + n_randint(state, 5000);
|
|
q = 1 + n_randint(state, 500);
|
|
p = n_randint(state, q / 2 + 1);
|
|
|
|
g = n_gcd(q, p);
|
|
q /= g;
|
|
p /= g;
|
|
|
|
fmprb_init(c1);
|
|
fmprb_init(c2);
|
|
|
|
_fmprb_cos_pi_fmpq_algebraic(c1, p, q, prec);
|
|
|
|
fmprb_const_pi(c2, prec);
|
|
fmprb_mul_ui(c2, c2, p, prec);
|
|
fmprb_div_ui(c2, c2, q, prec);
|
|
fmprb_cos(c2, c2, prec);
|
|
|
|
if (!fmprb_overlaps(c1, c2))
|
|
{
|
|
printf("FAIL: overlap\n\n");
|
|
printf("p/q = %lu/%lu", p, q); printf("\n\n");
|
|
printf("c1 = "); fmprb_printd(c1, 15); printf("\n\n");
|
|
printf("c2 = "); fmprb_printd(c2, 15); printf("\n\n");
|
|
abort();
|
|
}
|
|
|
|
if (fmprb_rel_accuracy_bits(c1) < prec - 2)
|
|
{
|
|
printf("FAIL: accuracy\n\n");
|
|
printf("p/q = %lu/%lu", p, q); printf("\n\n");
|
|
printf("prec=%ld eff=%ld\n", prec, fmprb_rel_accuracy_bits(c1));
|
|
printf("c1 = "); fmprb_printd(c1, 15); printf("\n\n");
|
|
printf("c2 = "); fmprb_printd(c2, 15); printf("\n\n");
|
|
abort();
|
|
}
|
|
|
|
fmprb_clear(c1);
|
|
fmprb_clear(c2);
|
|
}
|
|
|
|
flint_randclear(state);
|
|
flint_cleanup();
|
|
printf("PASS\n");
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|