#include "test_helpers.h"
#include "fmpq.h"
void mpq_addmul(mpq_t x, mpq_t y, mpq_t z)
{
mpq_t t;
mpq_init(t);
mpq_mul(t, y, z);
mpq_add(x, x, t);
mpq_clear(t);
}
TEST_FUNCTION_START(fmpq_addmul, state)
{
int i, result;
for (i = 0; i < 10000 * flint_test_multiplier(); i++)
{
fmpq_t a, b, c;
mpq_t d, e, f, g;
int aliasing;
fmpq_init(a);
fmpq_init(b);
fmpq_init(c);
mpq_init(d);
mpq_init(e);
mpq_init(f);
mpq_init(g);
fmpq_randtest(a, state, 200);
fmpq_randtest(b, state, 200);
fmpq_randtest(c, state, 200);
if (n_randint(state, 10) == 0)
fmpq_submul(c, a, b);
fmpq_get_mpq(d, a);
fmpq_get_mpq(e, b);
fmpq_get_mpq(f, c);
aliasing = n_randint(state, 4);
if (aliasing == 0)
{
fmpq_addmul(c, a, b);
}
else if (aliasing == 1)
{
fmpq_set(a, b);
mpq_set(d, e);
fmpq_addmul(c, a, a);
}
else if (aliasing == 2)
{
fmpq_set(c, a);
mpq_set(f, d);
fmpq_addmul(c, c, b);
}
else
{
fmpq_set(c, b);
mpq_set(f, e);
fmpq_addmul(c, a, c);
}
mpq_addmul(f, d, e);
fmpq_get_mpq(g, c);
result = (mpq_cmp(f, g) == 0) && fmpq_is_canonical(c);
if (!result)
{
flint_printf("FAIL:\n");
gmp_printf("d = %Qd, e = %Qd, f = %Qd, g = %Qd\n", d, e, f, g);
fflush(stdout);
flint_abort();
}
fmpq_clear(a);
fmpq_clear(b);
fmpq_clear(c);
mpq_clear(d);
mpq_clear(e);
mpq_clear(f);
mpq_clear(g);
}
TEST_FUNCTION_END(state);
}