This file is part of the GNU MP Library test suite.
The GNU MP Library test suite 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 3 of the License, or (at your option) any later version.
The GNU MP Library test suite 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
the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */
/* Test operands from a table of seed data. This variant creates the operands using plain ol' mpz_rrandomb. This is a hack for better coverage of the gcd code, which depends on that the random number generators give the exact
numbers we expect. */ void
check_kolmo1 (void)
{ staticconststruct { unsignedint seed; int nb; constchar *want;
} data[] = {
{ 59618, 38208, "5"},
{ 76521, 49024, "3"},
{ 85869, 54976, "1"},
{ 99449, 63680, "1"},
{112453, 72000, "1"}
};
gmp_randstate_t rs;
mpz_t bs, a, b, want; int i, unb, vnb, nb;
gmp_randinit_default (rs);
mpz_inits (bs, a, b, want, NULL);
for (i = 0; i < numberof (data); i++)
{
nb = data[i].nb;
mpz_clears (bs, a, b, want, NULL);
gmp_randclear (rs);
}
/* Test operands from a table of seed data. This variant creates the operands using a division chain. This is a hack for better coverage of the gcd code, which depends on that the random number generators give the exact
numbers we expect. */ void
check_kolmo2 (void)
{ staticconststruct { unsignedint seed; int nb, chain_len;
} data[] = {
{ 917, 15, 5 },
{ 1032, 18, 6 },
{ 1167, 18, 6 },
{ 1174, 18, 6 },
{ 1192, 18, 6 },
};
gmp_randstate_t rs;
mpz_t bs, a, b, want; int i;
gmp_randinit_default (rs);
mpz_inits (bs, a, b, want, NULL);
for (i = 0; i < numberof (data); i++)
{
gmp_randseed_ui (rs, data[i].seed);
make_chain_operands (want, a, b, rs, data[i].nb, data[i].nb, data[i].chain_len);
one_test (a, b, want, -1);
}
mpz_clears (bs, a, b, want, NULL);
gmp_randclear (rs);
}
int
main (int argc, char **argv)
{
mpz_t op1, op2, ref; int i, chain_len;
gmp_randstate_ptr rands;
mpz_t bs; unsignedlong bsi, size_range; longint reps = 200;
for (i = 0; i < reps; i++)
{ /* Generate plain operands with unknown gcd. These types of operands have proven to trigger certain bugs in development versions of the gcd code. The "hgcd->row[3].rsize > M" ASSERT is not triggered by the division chain code below, but that is most likely just a result
of that other ASSERTs are triggered before it. */
/* Called when g is supposed to be gcd(a,b), and g = s a + t b, for some t.
Uses temp1, temp2 and temp3. */ staticint
gcdext_valid_p (const mpz_t a, const mpz_t b, const mpz_t g, const mpz_t s)
{ /* It's not clear that gcd(0,0) is well defined, but we allow it and require that
gcd(0,0) = 0. */ if (mpz_sgn (g) < 0) return 0;
if (mpz_sgn (a) == 0)
{ /* Must have g == abs (b). Any value for s is in some sense "correct",
but it makes sense to require that s == 0. */ return mpz_cmpabs (g, b) == 0 && mpz_sgn (s) == 0;
} elseif (mpz_sgn (b) == 0)
{ /* Must have g == abs (a), s == sign (a) */ return mpz_cmpabs (g, a) == 0 && mpz_cmp_si (s, mpz_sgn (a)) == 0;
}
if (mpz_sgn (g) <= 0) return 0;
mpz_tdiv_qr (temp1, temp3, a, g); if (mpz_sgn (temp3) != 0) return 0;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.