summaryrefslogtreecommitdiff
path: root/mpf/random2.c
diff options
context:
space:
mode:
authortege <tege@gmplib.org>2003-06-11 22:20:43 +0200
committertege <tege@gmplib.org>2003-06-11 22:20:43 +0200
commit847ce98d25765e2ab10d437e743fff663e88aab6 (patch)
tree22030d6dc5136a76b00e31b9df2e93435d1024f0 /mpf/random2.c
parent7de821ab94f2be375892799d969f9efd2535643a (diff)
downloadgmp-847ce98d25765e2ab10d437e743fff663e88aab6.tar.gz
Rewrite. Ignore sign of exp parameter.
Diffstat (limited to 'mpf/random2.c')
-rw-r--r--mpf/random2.c41
1 files changed, 24 insertions, 17 deletions
diff --git a/mpf/random2.c b/mpf/random2.c
index ade358ccb..68a15acfd 100644
--- a/mpf/random2.c
+++ b/mpf/random2.c
@@ -2,7 +2,7 @@
long runs of consecutive ones and zeros in the binary representation.
Intended for testing of other MP routines.
-Copyright 1995, 1996, 2001, 2002 Free Software Foundation, Inc.
+Copyright 1995, 1996, 2001, 2002, 2003 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -26,26 +26,33 @@ MA 02111-1307, USA. */
void
-mpf_random2 (mpf_ptr x, mp_size_t size, mp_exp_t exp)
+mpf_random2 (mpf_ptr x, mp_size_t xs, mp_exp_t exp)
{
- mp_size_t asize;
- mp_size_t prec = x->_mp_prec;
+ mp_size_t xn;
+ mp_size_t prec;
mp_limb_t elimb;
- asize = ABS (size);
- if (asize != 0)
- {
- if (asize > prec + 1)
- asize = prec + 1;
-
- mpn_random2 (x->_mp_d, asize);
- }
+ xn = ABS (xs);
+ prec = PREC(x);
- if (exp != 0)
+ if (xn == 0)
{
- _gmp_rand (&elimb, RANDS, GMP_NUMB_BITS);
- exp = elimb % (2 * exp) - exp;
+ EXP(x) = 0;
+ SIZ(x) = 0;
+ return;
}
- x->_mp_exp = asize == 0 ? 0 : exp;
- x->_mp_size = size < 0 ? -asize : asize;
+
+ if (xn > prec + 1)
+ xn = prec + 1;
+
+ /* General random mantissa. */
+ mpn_random2 (PTR(x), xn);
+
+ /* Generate random exponent. */
+ _gmp_rand (&elimb, RANDS, GMP_NUMB_BITS);
+ exp = ABS (exp);
+ exp = elimb % (2 * exp + 1) - exp;
+
+ EXP(x) = exp;
+ SIZ(x) = xs < 0 ? -xn : xn;
}