=================================================================== RCS file: /home/cvs/OpenXM_contrib/gmp/demos/Attic/factorize.c,v retrieving revision 1.1.1.2 retrieving revision 1.1.1.3 diff -u -p -r1.1.1.2 -r1.1.1.3 --- OpenXM_contrib/gmp/demos/Attic/factorize.c 2000/09/09 14:13:19 1.1.1.2 +++ OpenXM_contrib/gmp/demos/Attic/factorize.c 2003/08/25 16:06:03 1.1.1.3 @@ -1,21 +1,19 @@ /* Factoring with Pollard's rho method. - Copyright (C) 1995, 1997, 1998, 1999, 2000 Free Software Foundation, Inc. +Copyright 1995, 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, +Inc. - This program 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, or (at your option) any - later version. +This program 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, or (at your option) any later version. - This program 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. +This program 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 this program; see the file COPYING. If not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. */ +You should have received a copy of the GNU General Public License along with +this program; see the file COPYING. If not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include @@ -27,22 +25,6 @@ int flag_verbose = 0; static unsigned add[] = {4, 2, 4, 2, 4, 6, 2, 6}; -#if defined (__hpux) || defined (__alpha) || defined (__svr4__) || defined (__SVR4) -/* HPUX lacks random(). DEC OSF/1 1.2 random() returns a double. */ -long mrand48 (); -static long -random () -{ - return mrand48 (); -} -#else -/* Glibc stdlib.h has "int32_t random();" which, on i386 at least, conflicts - with a redeclaration as "long". */ -#ifndef __GLIBC__ -long random (); -#endif -#endif - void factor_using_division (mpz_t t, unsigned int limit) { @@ -240,7 +222,11 @@ S4: if (!mpz_probab_prime_p (g, 3)) { do - a_int = random (); + { + mp_limb_t a_limb; + mpn_random (&a_limb, (mp_size_t) 1); + a_int = (int) a_limb; + } while (a_int == -2 || a_int == 0); if (flag_verbose) @@ -285,6 +271,9 @@ factor (mpz_t t, unsigned long p) { unsigned int division_limit; + if (mpz_sgn (t) == 0) + return; + /* Set the trial division limit according the size of t. */ division_limit = mpz_sizeinbase (t, 2); if (division_limit > 1000) @@ -324,40 +313,50 @@ main (int argc, char *argv[]) argc--; } - p = 0; - for (i = 1; i < argc; i++) + mpz_init (t); + if (argc > 1) { - if (!strncmp (argv[i], "-Mp", 3)) + p = 0; + for (i = 1; i < argc; i++) { - p = atoi (argv[i] + 3); - mpz_init_set_ui (t, 1); - mpz_mul_2exp (t, t, p); - mpz_sub_ui (t, t, 1); + if (!strncmp (argv[i], "-Mp", 3)) + { + p = atoi (argv[i] + 3); + mpz_set_ui (t, 1); + mpz_mul_2exp (t, t, p); + mpz_sub_ui (t, t, 1); + } + else if (!strncmp (argv[i], "-2kp", 4)) + { + p = atoi (argv[i] + 4); + continue; + } + else + { + mpz_set_str (t, argv[i], 0); + } + + if (mpz_cmp_ui (t, 0) == 0) + puts ("-"); + else + { + factor (t, p); + puts (""); + } } - else if (!strncmp (argv[i], "-2kp", 4)) + } + else + { + for (;;) { - p = atoi (argv[i] + 4); - continue; - } - else - { - mpz_init_set_str (t, argv[i], 0); - } - - if (mpz_cmp_ui (t, 0) == 0) - puts ("-"); - else - { - factor (t, p); + mpz_inp_str (t, stdin, 0); + if (feof (stdin)) + break; + mpz_out_str (stdout, 10, t); printf (" = "); + factor (t, 0); puts (""); } } - exit (0); -} -void -dmp (mpz_t x) -{ - mpz_out_str (stdout, 10, x); - puts (""); + exit (0); }