/* mpz_urandomm (rop, state, n) -- Generate a uniform pseudorandom integer in the range 0 to N-1, using STATE as the random state previously initialized by a call to gmp_randinit(). Copyright 2000, 2002 Free Software Foundation, Inc. This file is part of the GNU MP Library. The GNU MP Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser 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 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ #include "gmp.h" #include "gmp-impl.h" #include "longlong.h" /* for count_leading_zeros */ #define MAX_URANDOMM_ITER 80 void mpz_urandomm (mpz_ptr rop, gmp_randstate_t rstate, mpz_srcptr n) { mp_ptr rp, np, nlast; mp_size_t nbits, size; int count; int pow2; int cmp; size = ABSIZ (n); if (size == 0) DIVIDE_BY_ZERO; nlast = &PTR (n)[size - 1]; /* Detect whether n is a power of 2. */ pow2 = POW2_P (*nlast); if (pow2 != 0) for (np = PTR (n); np < nlast; np++) if (*np != 0) { pow2 = 0; /* Mark n as `not a power of two'. */ break; } count_leading_zeros (count, *nlast); nbits = size * GMP_NUMB_BITS - (count - GMP_NAIL_BITS) - pow2; if (nbits == 0) /* nbits == 0 means that n was == 1. */ { SIZ (rop) = 0; return; } /* Here the allocated size can be one too much if n is a power of (2^GMP_NUMB_BITS) but it's convenient for using mpn_cmp below. */ rp = MPZ_REALLOC (rop, size); /* Clear last limb to prevent the case in which size is one too much. */ rp[size - 1] = 0; count = MAX_URANDOMM_ITER; /* Set iteration count limit. */ do { _gmp_rand (rp, rstate, nbits); MPN_CMP (cmp, rp, PTR (n), size); } while (cmp >= 0 && --count != 0); if (count == 0) /* Too many iterations; return result mod n == result - n */ mpn_sub_n (rp, rp, PTR (n), size); MPN_NORMALIZE (rp, size); SIZ (rop) = size; } BASE) -- Function: int mpf_class::set_str (const string& STR, int BASE) -- Function: int sgn (mpf_class OP) -- Function: mpf_class sqrt (mpf_class OP) -- Function: mpf_class trunc (mpf_class OP) These functions provide a C++ class interface to the corresponding GMP C routines. `cmp' can be used with any of the classes or the standard C++ types, except `long long' and `long double'. The accuracy provided by `hypot' is not currently guaranteed. -- Function: unsigned long int mpf_class::get_prec () -- Function: void mpf_class::set_prec (unsigned long PREC) -- Function: void mpf_class::set_prec_raw (unsigned long PREC) Get or set the current precision of an `mpf_class'. The restrictions described for `mpf_set_prec_raw' (*note Initializing Floats::) apply to `mpf_class::set_prec_raw'. Note in particular that the `mpf_class' must be restored to it's allocated precision before being destroyed. This must be done by application code, there's no automatic mechanism for it.  File: gmp.info, Node: C++ Interface Random Numbers, Next: C++ Interface Limitations, Prev: C++ Interface Floats, Up: C++ Class Interface 12.5 C++ Interface Random Numbers ================================= -- Class: gmp_randclass The C++ class interface to the GMP random number functions uses `gmp_randclass' to hold an algorithm selection and current state, as per `gmp_randstate_t'. -- Function: gmp_randclass::gmp_randclass (void (*RANDINIT) (gmp_randstate_t, ...), ...) Construct a `gmp_randclass', using a call to the given RANDINIT function (*note Random State Initialization::). The arguments expected are the same as RANDINIT, but with `mpz_class' instead of `mpz_t'. For example, gmp_randclass r1 (gmp_randinit_default); gmp_randclass r2 (gmp_randinit_lc_2exp_size, 32); gmp_randclass r3 (gmp_randinit_lc_2exp, a, c, m2exp); gmp_randclass r4 (gmp_randinit_mt); `gmp_randinit_lc_2exp_size' will fail if the size requested is too big, an `std::length_error' exception is thrown in that case. -- Function: gmp_randclass::gmp_randclass (gmp_randalg_t ALG, ...) Construct a `gmp_randclass' using the same parameters as `gmp_randinit' (*note Random State Initialization::). This function is obsolete and the above RANDINIT style should be preferred. -- Function: void gmp_randclass::seed (unsigned long int S) -- Function: void gmp_randclass::seed (mpz_class S) Seed a random number generator. See *note Random Number Functions::, for how to choose a good seed. -- Function: mpz_class gmp_randclass::get_z_bits (unsigned long BITS) -- Function: mpz_class gmp_randclass::get_z_bits (mpz_class BITS) Generate a random integer with a specified number of bits. -- Function: mpz_class gmp_randclass::get_z_range (mpz_class N) Generate a random integer in the range 0 to N-1 inclusive. -- Function: mpf_class gmp_randclass::get_f () -- Function: mpf_class gmp_randclass::get_f (unsigned long PREC) Generate a random float F in the range 0 <= F < 1. F will be to PREC bits precision, or if PREC is not given then to the precision of the destination. For example, gmp_randclass r; ... mpf_class f (0, 512); // 512 bits precision f = r.get_f(); // random number, 512 bits  File: gmp.info, Node: C++ Interface Limitations, Prev: C++ Interface Random Numbers, Up: C++ Class Interface 12.6 C++ Interface Limitations ============================== `mpq_class' and Templated Reading A generic piece of template code probably won't know that `mpq_class' requires a `canonicalize' call if inputs read with `operator>>' might be non-canonical. This can lead to incorrect results. `operator>>' behaves as it does for reasons of efficiency. A canonicalize can be quite time consuming on large operands, and is best avoided if it's not necessary. But this potential difficult# udiv.lo - a libtool object file # Generated by ltmain.sh - GNU libtool 1.5.24 (1.1220.2.455 2007/06/24 02:13:29) # # Please DO NOT delete this file! # It is necessary for linking the library. # Name of the PIC object. pic_object='.libs/udiv.o' # Name of the non-PIC object. non_pic_object='udiv.o'