Copyright 2011, 2016, 2018 Free Software Foundation, Inc.
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/. */
#include <stdio.h> #include <stdlib.h>
#include <time.h>
#ifdef __unix__ # include <unistd.h> # include <sys/time.h> #endif
#include"gmp.h"
#include"hex-random.h"
/* FIXME: gmp-impl.h included only for mpz_lucas_mod */ /* #include "gmp-impl.h" */ #ifdefined (__cplusplus) extern"C" { #endif
signs = gmp_urandomb_ui (state, 3); if (signs & 1)
mpz_neg (a, a); if (signs & 2)
mpz_neg (b, b);
switch (op)
{ default:
abort (); case OP_ADD:
mpz_add (r, a, b); break; case OP_SUB:
mpz_sub (r, a, b); break; case OP_MUL:
mpz_mul (r, a, b); break; case OP_GCD: if (signs & 4)
{ /* Produce a large gcd */ unsignedlong gbits = gmp_urandomb_ui (state, 32) % maxbits;
mpz_rrandomb (r, state, gbits);
mpz_mul (a, a, r);
mpz_mul (b, b, r);
}
mpz_gcd (r, a, b); break; case OP_LCM: if (signs & 4)
{ /* Produce a large gcd */ unsignedlong gbits = gmp_urandomb_ui (state, 32) % maxbits;
mpz_rrandomb (r, state, gbits);
mpz_mul (a, a, r);
mpz_mul (b, b, r);
}
mpz_lcm (r, a, b); break; case OP_AND:
mpz_and (r, a, b); break; case OP_IOR:
mpz_ior (r, a, b); break; case OP_XOR:
mpz_xor (r, a, b); break;
}
case OP_SETBIT:
mpz_set (r, a);
mpz_setbit (r, bbits); break; case OP_CLRBIT:
mpz_set (r, a);
mpz_clrbit (r, bbits); break; case OP_COMBIT:
mpz_set (r, a);
mpz_combit (r, bbits); break; case OP_CDIV_Q_2:
mpz_cdiv_q_2exp (r, a, bbits); break; case OP_CDIV_R_2:
mpz_cdiv_r_2exp (r, a, bbits); break; case OP_FDIV_Q_2:
mpz_fdiv_q_2exp (r, a, bbits); break; case OP_FDIV_R_2:
mpz_fdiv_r_2exp (r, a, bbits); break; case OP_TDIV_Q_2:
mpz_tdiv_q_2exp (r, a, bbits); break; case OP_TDIV_R_2:
mpz_tdiv_r_2exp (r, a, bbits); break;
}
mpz_rrandomb (m, state, mbits);
*b0 = gmp_urandomb_ui (state, 32) % (mbits - 3) + 2; /* The GMP implementation uses the exponent (m >> b0) + 1. */ /* mini-gmp implementation uses the exponent (m >> b0) | 1. */ /* They are the same (and are used) only when (m >> b0) is even */
mpz_clrbit (m, *b0); /* mini-gmp implementation only works if the modulus is odd. */
mpz_setbit (m, 0);
} while (mpz_gcd_ui (NULL, m, *Q) != 1);
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.