From 49406a145c30997c8c82d33696e2b3b1de930e0f Mon Sep 17 00:00:00 2001 From: thevenyp Date: Tue, 24 Mar 2009 15:10:52 +0000 Subject: Move mpfr_random2 to tests directory, remove it from API. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@6136 280ebfd0-de03-0410-8827-d642c229c3f4 --- Makefile.am | 2 +- NEWS | 2 +- mpfr.h | 2 - mpfr.texi | 15 ------ random2.c | 154 ----------------------------------------------------- tests/Makefile.am | 2 +- tests/mpf_compat.h | 2 - tests/mpfr-test.h | 1 + tests/random2.c | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/tadd.c | 2 +- tests/tadd_d.c | 2 +- tests/tadd_ui.c | 2 +- tests/td_div.c | 2 +- tests/td_sub.c | 2 +- tests/tdiv.c | 2 +- tests/tdiv_d.c | 2 +- tests/tdiv_ui.c | 2 +- tests/tgamma.c | 2 +- tests/tj0.c | 2 +- tests/tj1.c | 2 +- tests/tmul.c | 2 +- tests/tmul_d.c | 2 +- tests/tmul_ui.c | 2 +- tests/tpow.c | 4 +- tests/trandom.c | 153 +--------------------------------------------------- tests/tsi_op.c | 8 +-- tests/tsub.c | 2 +- tests/tsub_d.c | 2 +- tests/tsub_ui.c | 2 +- tests/ty0.c | 2 +- tests/ty1.c | 2 +- 31 files changed, 177 insertions(+), 353 deletions(-) delete mode 100644 random2.c create mode 100644 tests/random2.c diff --git a/Makefile.am b/Makefile.am index 07fc65008..5ef79512d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -8,7 +8,7 @@ include_HEADERS = mpfr.h mpf2mpfr.h lib_LTLIBRARIES = libmpfr.la -libmpfr_la_SOURCES = mpfr.h mpf2mpfr.h mpfr-gmp.h mpfr-impl.h mpfr-longlong.h mpfr-thread.h exceptions.c extract.c uceil_exp2.c uceil_log2.c ufloor_log2.c add.c add1.c add_ui.c agm.c clear.c cmp.c cmp_abs.c cmp_si.c cmp_ui.c comparisons.c div_2exp.c div_2si.c div_2ui.c div.c div_ui.c dump.c eq.c exp10.c exp2.c exp3.c exp.c frac.c get_d.c get_exp.c get_str.c init.c inp_str.c isinteger.c isinf.c isnan.c isnum.c const_log2.c log.c modf.c mul_2exp.c mul_2si.c mul_2ui.c mul.c mul_ui.c neg.c next.c out_str.c printf.c vasprintf.c const_pi.c pow.c pow_si.c pow_ui.c print_raw.c print_rnd_mode.c random2.c reldiff.c round_prec.c set.c setmax.c setmin.c set_d.c set_dfl_prec.c set_exp.c set_rnd.c set_f.c set_prc_raw.c set_prec.c set_q.c set_si.c set_str.c set_str_raw.c set_ui.c set_z.c sqrt.c sqrt_ui.c sub.c sub1.c sub_ui.c rint.c ui_div.c ui_sub.c urandomb.c get_z_exp.c swap.c factorial.c cosh.c sinh.c tanh.c sinh_cosh.c acosh.c asinh.c atanh.c atan.c cmp2.c exp_2.c asin.c const_euler.c cos.c sin.c tan.c fma.c fms.c hypot.c log1p.c expm1.c log2.c log10.c ui_pow.c ui_pow_ui.c minmax.c dim.c signbit.c copysign.c setsign.c gmp_op.c init2.c acos.c sin_cos.c set_nan.c set_inf.c powerof2.c gamma.c set_ld.c get_ld.c cbrt.c volatile.c fits_s.h fits_sshort.c fits_sint.c fits_slong.c fits_u.h fits_ushort.c fits_uint.c fits_ulong.c fits_uintmax.c fits_intmax.c get_si.c get_ui.c zeta.c cmp_d.c erf.c inits.c inits2.c clears.c sgn.c check.c sub1sp.c version.c mpn_exp.c mpfr-gmp.c mp_clz_tab.c sum.c add1sp.c free_cache.c si_op.c cmp_ld.c set_ui_2exp.c set_si_2exp.c set_uj.c set_sj.c get_sj.c get_uj.c get_z.c iszero.c cache.c sqr.c int_ceil_log2.c isqrt.c strtofr.c pow_z.c logging.c mulders.c get_f.c round_p.c erfc.c atan2.c subnormal.c const_catalan.c root.c gen_inverse.h sec.c csc.c cot.c eint.c sech.c csch.c coth.c round_near_x.c constant.c abort_prec_max.c stack_interface.c lngamma.c zeta_ui.c set_d64.c get_d64.c jn.c yn.c rem1.c get_patches.c add_d.c sub_d.c d_sub.c mul_d.c div_d.c d_div.c li2.c rec_sqrt.c min_prec.c +libmpfr_la_SOURCES = mpfr.h mpf2mpfr.h mpfr-gmp.h mpfr-impl.h mpfr-longlong.h mpfr-thread.h exceptions.c extract.c uceil_exp2.c uceil_log2.c ufloor_log2.c add.c add1.c add_ui.c agm.c clear.c cmp.c cmp_abs.c cmp_si.c cmp_ui.c comparisons.c div_2exp.c div_2si.c div_2ui.c div.c div_ui.c dump.c eq.c exp10.c exp2.c exp3.c exp.c frac.c get_d.c get_exp.c get_str.c init.c inp_str.c isinteger.c isinf.c isnan.c isnum.c const_log2.c log.c modf.c mul_2exp.c mul_2si.c mul_2ui.c mul.c mul_ui.c neg.c next.c out_str.c printf.c vasprintf.c const_pi.c pow.c pow_si.c pow_ui.c print_raw.c print_rnd_mode.c reldiff.c round_prec.c set.c setmax.c setmin.c set_d.c set_dfl_prec.c set_exp.c set_rnd.c set_f.c set_prc_raw.c set_prec.c set_q.c set_si.c set_str.c set_str_raw.c set_ui.c set_z.c sqrt.c sqrt_ui.c sub.c sub1.c sub_ui.c rint.c ui_div.c ui_sub.c urandomb.c get_z_exp.c swap.c factorial.c cosh.c sinh.c tanh.c sinh_cosh.c acosh.c asinh.c atanh.c atan.c cmp2.c exp_2.c asin.c const_euler.c cos.c sin.c tan.c fma.c fms.c hypot.c log1p.c expm1.c log2.c log10.c ui_pow.c ui_pow_ui.c minmax.c dim.c signbit.c copysign.c setsign.c gmp_op.c init2.c acos.c sin_cos.c set_nan.c set_inf.c powerof2.c gamma.c set_ld.c get_ld.c cbrt.c volatile.c fits_s.h fits_sshort.c fits_sint.c fits_slong.c fits_u.h fits_ushort.c fits_uint.c fits_ulong.c fits_uintmax.c fits_intmax.c get_si.c get_ui.c zeta.c cmp_d.c erf.c inits.c inits2.c clears.c sgn.c check.c sub1sp.c version.c mpn_exp.c mpfr-gmp.c mp_clz_tab.c sum.c add1sp.c free_cache.c si_op.c cmp_ld.c set_ui_2exp.c set_si_2exp.c set_uj.c set_sj.c get_sj.c get_uj.c get_z.c iszero.c cache.c sqr.c int_ceil_log2.c isqrt.c strtofr.c pow_z.c logging.c mulders.c get_f.c round_p.c erfc.c atan2.c subnormal.c const_catalan.c root.c gen_inverse.h sec.c csc.c cot.c eint.c sech.c csch.c coth.c round_near_x.c constant.c abort_prec_max.c stack_interface.c lngamma.c zeta_ui.c set_d64.c get_d64.c jn.c yn.c rem1.c get_patches.c add_d.c sub_d.c d_sub.c mul_d.c div_d.c d_div.c li2.c rec_sqrt.c min_prec.c libmpfr_la_LIBADD = @LIBOBJS@ diff --git a/NEWS b/NEWS index a2551d8bd..0951fecba 100644 --- a/NEWS +++ b/NEWS @@ -25,7 +25,7 @@ Changes from versions 2.4.* to version 3.0: version 3 or later (LGPL v3+). - Rounding modes GMP_RNDX are now MPFR_RNDX (GMP_RNDX kept for compatibility). - A new rounding mode (MPFR_RNDA) is available to round away from zero. -- Function mpfr_random has been removed. +- Functions mpfr_random and mpfr_random2 have been removed. Changes from versions 2.3.* to version 2.4.0: - MPFR is now a GNU package. diff --git a/mpfr.h b/mpfr.h index 54782036a..6d00c2bb7 100644 --- a/mpfr.h +++ b/mpfr.h @@ -348,8 +348,6 @@ __MPFR_DECLSPEC void mpfr_get_z _MPFR_PROTO ((mpz_ptr z, mpfr_srcptr f, __MPFR_DECLSPEC void mpfr_free_str _MPFR_PROTO ((char *)); - -__MPFR_DECLSPEC void mpfr_random2 _MPFR_PROTO ((mpfr_ptr,mp_size_t,mp_exp_t)); __MPFR_DECLSPEC int mpfr_urandomb _MPFR_PROTO ((mpfr_ptr, gmp_randstate_t)); __MPFR_DECLSPEC void mpfr_nextabove _MPFR_PROTO ((mpfr_ptr)); diff --git a/mpfr.texi b/mpfr.texi index 5e1d2e820..13a2c072e 100644 --- a/mpfr.texi +++ b/mpfr.texi @@ -2403,21 +2403,6 @@ second argument is a @code{gmp_randstate_t} structure which should be created using the GMP @code{gmp_randinit} function, see the GMP manual. @end deftypefun -@deftypefun void mpfr_random2 (mpfr_t @var{rop}, mp_size_t @var{size}, mp_exp_t @var{exp}) -Generate a random float of at most @var{size} limbs, with long strings of -zeros and ones in the binary representation. The exponent of the number is in -the interval @minus{}@var{exp} to @var{exp}. -This function is useful for -testing functions and algorithms, since this kind of random numbers have -proven to be more likely to trigger corner-case bugs. -Negative random numbers are generated when @var{size} is negative. -Put +0 in @var{rop} when size if zero. The internal state of the default -pseudorandom number generator is modified by a call to this function (the -same one as GMP if MPFR was built using @samp{--with-gmp-build}). - -This function is deprecated and will be suppressed in the next release. -@end deftypefun - @deftypefun mp_exp_t mpfr_get_exp (mpfr_t @var{x}) Get the exponent of @var{x}, assuming that @var{x} is a non-zero ordinary number and the significand is chosen in [1/2,1). The behavior for NaN, diff --git a/random2.c b/random2.c deleted file mode 100644 index 64a4deb07..000000000 --- a/random2.c +++ /dev/null @@ -1,154 +0,0 @@ -/* mpfr_random2 -- Generate a positive random mpfr_t of specified size, with - long runs of consecutive ones and zeros in the binary representation. - Intended for testing. - -Copyright 1999, 2001, 2002, 2003, 2004, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. -Contributed by the Arenaire and Cacao projects, INRIA. - -This file is part of the GNU MPFR Library. - -The GNU MPFR 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 MPFR 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 MPFR Library; see the file COPYING.LIB. If not, see -http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., -51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#define MPFR_NEED_LONGLONG_H -#include "mpfr-impl.h" - -#define LOGBITS_PER_BLOCK 4 -#if GMP_NUMB_BITS < 32 -#define BITS_PER_RANDCALL GMP_NUMB_BITS -#else -#define BITS_PER_RANDCALL 32 -#endif - -static void -mpfr_random2_raw (mpfr_ptr x, mp_size_t size, mp_exp_t exp, - gmp_randstate_t rstate) -{ - mp_size_t xn, k, ri; - unsigned long sh; - mp_ptr xp; - mp_limb_t elimb, ran, acc; - int ran_nbits, bit_pos, nb; - - MPFR_CLEAR_FLAGS (x); - - if (MPFR_UNLIKELY(size == 0)) - { - MPFR_SET_ZERO (x); - MPFR_SET_POS (x); - return ; - } - else if (size > 0) - { - MPFR_SET_POS (x); - } - else - { - MPFR_SET_NEG (x); - size = -size; - } - - xn = MPFR_LIMB_SIZE (x); - xp = MPFR_MANT (x); - if (size > xn) - size = xn; - k = xn - size; - - /* Code extracted from GMP, function mpn_random2, to avoid the use - of GMP's internal random state in MPFR */ - - _gmp_rand (&elimb, rstate, BITS_PER_RANDCALL); - ran = elimb; - - /* Start off at a random bit position in the most significant limb. */ - bit_pos = GMP_NUMB_BITS - 1; - ran >>= 6; /* Ideally log2(GMP_NUMB_BITS) */ - ran_nbits = BITS_PER_RANDCALL - 6; /* Ideally - log2(GMP_NUMB_BITS) */ - - /* Bit 0 of ran chooses string of ones/string of zeroes. - Make most significant limb be non-zero by setting bit 0 of RAN. */ - ran |= 1; - ri = xn - 1; - - acc = 0; - while (ri >= k) - { - if (ran_nbits < LOGBITS_PER_BLOCK + 1) - { - _gmp_rand (&elimb, rstate, BITS_PER_RANDCALL); - ran = elimb; - ran_nbits = BITS_PER_RANDCALL; - } - - nb = (ran >> 1) % (1 << LOGBITS_PER_BLOCK) + 1; - if ((ran & 1) != 0) - { - /* Generate a string of nb ones. */ - if (nb > bit_pos) - { - xp[ri--] = acc | (((mp_limb_t) 2 << bit_pos) - 1); - bit_pos += GMP_NUMB_BITS; - bit_pos -= nb; - acc = ((~(mp_limb_t) 1) << bit_pos) & GMP_NUMB_MASK; - } - else - { - bit_pos -= nb; - acc |= (((mp_limb_t) 2 << nb) - 2) << bit_pos; - } - } - else - { - /* Generate a string of nb zeroes. */ - if (nb > bit_pos) - { - xp[ri--] = acc; - acc = 0; - bit_pos += GMP_NUMB_BITS; - } - bit_pos -= nb; - } - ran_nbits -= LOGBITS_PER_BLOCK + 1; - ran >>= LOGBITS_PER_BLOCK + 1; - } - - /* Set mandatory most significant bit. */ - /* xp[xn - 1] |= MPFR_LIMB_HIGHBIT; */ - - if (k != 0) - { - /* Clear last limbs */ - MPN_ZERO (xp, k); - } - else - { - /* Mask off non significant bits in the low limb. */ - MPFR_UNSIGNED_MINUS_MODULO (sh, MPFR_PREC (x)); - xp[0] &= ~MPFR_LIMB_MASK (sh); - } - - /* Generate random exponent. */ - _gmp_rand (&elimb, RANDS, BITS_PER_MP_LIMB); - exp = ABS (exp); - MPFR_SET_EXP (x, elimb % (2 * exp + 1) - exp); - - return ; -} - -void -mpfr_random2 (mpfr_ptr x, mp_size_t size, mp_exp_t exp) -{ - mpfr_random2_raw (x, size, exp, RANDS); -} diff --git a/tests/Makefile.am b/tests/Makefile.am index 2619f478f..ab11d8e76 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -27,7 +27,7 @@ INCLUDES = -I$(top_srcdir) -I$(top_builddir) LOADLIBES=$(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) $(top_builddir)/tests/.libs/libfrtests.a $(top_builddir)/.libs/libmpfr.a $(LIBS) $(MPFR_LIBM) check_LTLIBRARIES = libfrtests.la -libfrtests_la_SOURCES = mpfr-test.h memory.c rnd_mode.c tests.c cmp_str.c +libfrtests_la_SOURCES = mpfr-test.h memory.c rnd_mode.c tests.c cmp_str.c random2.c $(top_builddir)/libmpfr.la: cd $(top_builddir); make libmpfr.la diff --git a/tests/mpf_compat.h b/tests/mpf_compat.h index 0c05b086c..a390ca37c 100644 --- a/tests/mpf_compat.h +++ b/tests/mpf_compat.h @@ -211,8 +211,6 @@ main () mpf_urandomb (x, state, 10); gmp_randclear (state); - mpf_random2 (x, 17, 17); - /* Conversion to mpz */ mpz_init (z); mpf_set_ui (x, 17); diff --git a/tests/mpfr-test.h b/tests/mpfr-test.h index e01804368..10a9954d9 100644 --- a/tests/mpfr-test.h +++ b/tests/mpfr-test.h @@ -72,6 +72,7 @@ int mpfr_set_machine_rnd_mode _MPFR_PROTO ((mp_rnd_t)); void mpfr_test_init _MPFR_PROTO ((void)); mp_limb_t randlimb _MPFR_PROTO ((void)); void randseed _MPFR_PROTO ((unsigned int)); +void mpfr_random2 _MPFR_PROTO ((mpfr_ptr, mp_size_t, mp_exp_t, gmp_randstate_t)); int ulp _MPFR_PROTO ((double, double)); double dbl _MPFR_PROTO ((double, int)); double Ulp _MPFR_PROTO ((double)); diff --git a/tests/random2.c b/tests/random2.c new file mode 100644 index 000000000..66739e862 --- /dev/null +++ b/tests/random2.c @@ -0,0 +1,147 @@ +/* mpfr_random2 -- Generate a positive random mpfr_t of specified size, with + long runs of consecutive ones and zeros in the binary representation. + +Copyright 1999, 2001, 2002, 2003, 2004, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. +Contributed by the Arenaire and Cacao projects, INRIA. + +This file is part of the GNU MPFR Library. + +The GNU MPFR 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 MPFR 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 MPFR Library; see the file COPYING.LIB. If not, see +http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#define MPFR_NEED_LONGLONG_H +#include "mpfr-impl.h" + +#define LOGBITS_PER_BLOCK 4 +#if GMP_NUMB_BITS < 32 +#define BITS_PER_RANDCALL GMP_NUMB_BITS +#else +#define BITS_PER_RANDCALL 32 +#endif + +void +mpfr_random2 (mpfr_ptr x, mp_size_t size, mp_exp_t exp, + gmp_randstate_t rstate) +{ + mp_size_t xn, k, ri; + unsigned long sh; + mp_ptr xp; + mp_limb_t elimb, ran, acc; + int ran_nbits, bit_pos, nb; + + MPFR_CLEAR_FLAGS (x); + + if (MPFR_UNLIKELY(size == 0)) + { + MPFR_SET_ZERO (x); + MPFR_SET_POS (x); + return ; + } + else if (size > 0) + { + MPFR_SET_POS (x); + } + else + { + MPFR_SET_NEG (x); + size = -size; + } + + xn = MPFR_LIMB_SIZE (x); + xp = MPFR_MANT (x); + if (size > xn) + size = xn; + k = xn - size; + + /* Code extracted from GMP, function mpn_random2, to avoid the use + of GMP's internal random state in MPFR */ + + _gmp_rand (&elimb, rstate, BITS_PER_RANDCALL); + ran = elimb; + + /* Start off at a random bit position in the most significant limb. */ + bit_pos = GMP_NUMB_BITS - 1; + ran >>= 6; /* Ideally log2(GMP_NUMB_BITS) */ + ran_nbits = BITS_PER_RANDCALL - 6; /* Ideally - log2(GMP_NUMB_BITS) */ + + /* Bit 0 of ran chooses string of ones/string of zeroes. + Make most significant limb be non-zero by setting bit 0 of RAN. */ + ran |= 1; + ri = xn - 1; + + acc = 0; + while (ri >= k) + { + if (ran_nbits < LOGBITS_PER_BLOCK + 1) + { + _gmp_rand (&elimb, rstate, BITS_PER_RANDCALL); + ran = elimb; + ran_nbits = BITS_PER_RANDCALL; + } + + nb = (ran >> 1) % (1 << LOGBITS_PER_BLOCK) + 1; + if ((ran & 1) != 0) + { + /* Generate a string of nb ones. */ + if (nb > bit_pos) + { + xp[ri--] = acc | (((mp_limb_t) 2 << bit_pos) - 1); + bit_pos += GMP_NUMB_BITS; + bit_pos -= nb; + acc = ((~(mp_limb_t) 1) << bit_pos) & GMP_NUMB_MASK; + } + else + { + bit_pos -= nb; + acc |= (((mp_limb_t) 2 << nb) - 2) << bit_pos; + } + } + else + { + /* Generate a string of nb zeroes. */ + if (nb > bit_pos) + { + xp[ri--] = acc; + acc = 0; + bit_pos += GMP_NUMB_BITS; + } + bit_pos -= nb; + } + ran_nbits -= LOGBITS_PER_BLOCK + 1; + ran >>= LOGBITS_PER_BLOCK + 1; + } + + /* Set mandatory most significant bit. */ + /* xp[xn - 1] |= MPFR_LIMB_HIGHBIT; */ + + if (k != 0) + { + /* Clear last limbs */ + MPN_ZERO (xp, k); + } + else + { + /* Mask off non significant bits in the low limb. */ + MPFR_UNSIGNED_MINUS_MODULO (sh, MPFR_PREC (x)); + xp[0] &= ~MPFR_LIMB_MASK (sh); + } + + /* Generate random exponent. */ + _gmp_rand (&elimb, RANDS, BITS_PER_MP_LIMB); + exp = ABS (exp); + MPFR_SET_EXP (x, elimb % (2 * exp + 1) - exp); + + return ; +} diff --git a/tests/tadd.c b/tests/tadd.c index 2067e175a..306f20aa4 100644 --- a/tests/tadd.c +++ b/tests/tadd.c @@ -1107,7 +1107,7 @@ tests (void) #define TEST_FUNCTION test_add #define TWO_ARGS -#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), randlimb () % 100) +#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), randlimb () % 100, RANDS) #include "tgeneric.c" int diff --git a/tests/tadd_d.c b/tests/tadd_d.c index 26e4dc61e..6f5b51894 100644 --- a/tests/tadd_d.c +++ b/tests/tadd_d.c @@ -130,7 +130,7 @@ check_nans (void) #define TEST_FUNCTION mpfr_add_d #define DOUBLE_ARG2 -#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1) +#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1, RANDS) #include "tgeneric.c" int diff --git a/tests/tadd_ui.c b/tests/tadd_ui.c index 28fafa906..8c2428c45 100644 --- a/tests/tadd_ui.c +++ b/tests/tadd_ui.c @@ -90,7 +90,7 @@ check_nans (void) #define TEST_FUNCTION mpfr_add_ui #define INTEGER_TYPE unsigned long -#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1) +#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1, RANDS) #include "tgeneric_ui.c" int diff --git a/tests/td_div.c b/tests/td_div.c index f4c605992..3e671418e 100644 --- a/tests/td_div.c +++ b/tests/td_div.c @@ -78,7 +78,7 @@ check_nans (void) #define TEST_FUNCTION mpfr_d_sub #define DOUBLE_ARG1 -#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1) +#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1, RANDS) #include "tgeneric.c" int diff --git a/tests/td_sub.c b/tests/td_sub.c index ab0abd4a3..c9dc9f9c3 100644 --- a/tests/td_sub.c +++ b/tests/td_sub.c @@ -69,7 +69,7 @@ check_nans (void) #define TEST_FUNCTION mpfr_d_sub #define DOUBLE_ARG1 -#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1) +#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1, RANDS) #include "tgeneric.c" int diff --git a/tests/tdiv.c b/tests/tdiv.c index 043b214d2..5d201345d 100644 --- a/tests/tdiv.c +++ b/tests/tdiv.c @@ -898,7 +898,7 @@ test_20070628 (void) #define TEST_FUNCTION test_div #define TWO_ARGS -#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), randlimb () % 100) +#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), randlimb () % 100, RANDS) #include "tgeneric.c" int diff --git a/tests/tdiv_d.c b/tests/tdiv_d.c index c913172f2..125fbe23e 100644 --- a/tests/tdiv_d.c +++ b/tests/tdiv_d.c @@ -77,7 +77,7 @@ check_nans (void) #define TEST_FUNCTION mpfr_sub_d #define DOUBLE_ARG2 -#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1) +#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1, RANDS) #include "tgeneric.c" int diff --git a/tests/tdiv_ui.c b/tests/tdiv_ui.c index 6b52e7f9b..d86324901 100644 --- a/tests/tdiv_ui.c +++ b/tests/tdiv_ui.c @@ -198,7 +198,7 @@ check_inexact (void) #define TEST_FUNCTION mpfr_div_ui #define INTEGER_TYPE unsigned long -#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1) +#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1, RANDS) #include "tgeneric_ui.c" int diff --git a/tests/tgamma.c b/tests/tgamma.c index 54ee2e675..b2730a18f 100644 --- a/tests/tgamma.c +++ b/tests/tgamma.c @@ -26,7 +26,7 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., #include "mpfr-test.h" #define TEST_FUNCTION mpfr_gamma -#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1) +#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1, RANDS) #include "tgeneric.c" static void diff --git a/tests/tj0.c b/tests/tj0.c index 28d6bd6d7..01ccf85ce 100644 --- a/tests/tj0.c +++ b/tests/tj0.c @@ -26,7 +26,7 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., #include "mpfr-test.h" #define TEST_FUNCTION mpfr_j0 -#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 8) +#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 8, RANDS) #define REDUCE_EMAX 262143 /* otherwise arg. reduction is too expensive */ #include "tgeneric.c" diff --git a/tests/tj1.c b/tests/tj1.c index 4fe0b4bf9..6e3726ed4 100644 --- a/tests/tj1.c +++ b/tests/tj1.c @@ -26,7 +26,7 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., #include "mpfr-test.h" #define TEST_FUNCTION mpfr_j1 -#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 8) +#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 8, RANDS) #define REDUCE_EMAX 262143 /* otherwise arg. reduction is too expensive */ #include "tgeneric.c" diff --git a/tests/tmul.c b/tests/tmul.c index 4e3c39c46..2f2e89acd 100644 --- a/tests/tmul.c +++ b/tests/tmul.c @@ -617,7 +617,7 @@ check_regression (void) #define TEST_FUNCTION test_mul #define TWO_ARGS -#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), randlimb () % 100) +#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), randlimb () % 100, RANDS) #include "tgeneric.c" /* multiplies x by 53-bit approximation of Pi */ diff --git a/tests/tmul_d.c b/tests/tmul_d.c index 05eb4e0f2..1b12a1b87 100644 --- a/tests/tmul_d.c +++ b/tests/tmul_d.c @@ -76,7 +76,7 @@ check_nans (void) #define TEST_FUNCTION mpfr_mul_d #define DOUBLE_ARG2 -#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1) +#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1, RANDS) #include "tgeneric.c" int diff --git a/tests/tmul_ui.c b/tests/tmul_ui.c index f1a32b4f7..24a5fa194 100644 --- a/tests/tmul_ui.c +++ b/tests/tmul_ui.c @@ -77,7 +77,7 @@ check_inexact (mp_prec_t p) #define TEST_FUNCTION mpfr_mul_ui #define INTEGER_TYPE unsigned long -#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1) +#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1, RANDS) #include "tgeneric_ui.c" int diff --git a/tests/tpow.c b/tests/tpow.c index 4011e72ca..2591d1a4a 100644 --- a/tests/tpow.c +++ b/tests/tpow.c @@ -62,12 +62,12 @@ test_pow (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) #define TEST_FUNCTION mpfr_pow_ui #define INTEGER_TYPE unsigned long -#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1) +#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1, RANDS) #include "tgeneric_ui.c" #define TEST_FUNCTION mpfr_pow_si #define INTEGER_TYPE long -#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1) +#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1, RANDS) #define test_generic_ui test_generic_si #include "tgeneric_ui.c" diff --git a/tests/trandom.c b/tests/trandom.c index 14dafc31e..030737ede 100644 --- a/tests/trandom.c +++ b/tests/trandom.c @@ -1,4 +1,4 @@ -/* Test file for the various mpfr_random fonctions. +/* Test file for mpfr_urandomb Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. Contributed by the Arenaire and Cacao projects, INRIA. @@ -25,153 +25,6 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., #include "mpfr-test.h" -static void -test_random (long nbtests, mp_prec_t prec, int verbose) -{ - mpfr_t x; - int *tab, size_tab, k; - double d, av = 0, var = 0, chi2 = 0, th; - - size_tab = (nbtests >= 1000 ? nbtests / 50 : 20); - tab = (int *) calloc (size_tab, sizeof(int)); - if (tab == NULL) - { - fprintf (stderr, "trandom: can't allocate memory in test_random\n"); - exit (1); - } - - mpfr_init2(x, prec); - - for (k = 0; k < nbtests; k++) - { - mpfr_urandomb (x, RANDS); - d = mpfr_get_d1 (x); av += d; var += d*d; - tab[(int)(size_tab * d)]++; - } - - mpfr_clear(x); - if (!verbose) - { - free(tab); - return; - } - - av /= nbtests; - var = (var / nbtests) - av*av; - - th = (double) nbtests / size_tab; - - printf("Average = %.5f\nVariance = %.5f\n", av, var); - printf("Repartition for random. Each integer should be close to %d.\n", - (int)th); - - for (k = 0; k < size_tab; k++) - { - chi2 += (tab[k] - th) * (tab[k] - th) / th; - printf("%d ", tab[k]); - if (((k+1) & 7) == 0) - printf("\n"); - } - - printf("\nChi2 statistics value (with %d degrees of freedom) : %.5f\n\n", - size_tab - 1, chi2); - - printf("\n"); - - free(tab); - return; -} - -static void -test_random2 (long nbtests, mp_prec_t prec, int verbose) -{ - mpfr_t x; - int *tab, size_tab, k, sh, xn; - double d, av = 0, var = 0, chi2 = 0, th; - - size_tab = (nbtests >= 1000 ? nbtests / 50 : 20); - tab = (int *) calloc (size_tab, sizeof(int)); - if (tab == NULL) - { - fprintf (stderr, "trandom: can't allocate memory in test_random2\n"); - exit (1); - } - - mpfr_init2 (x, prec); - xn = 1 + (prec - 1) / mp_bits_per_limb; - sh = xn * mp_bits_per_limb - prec; - - for (k = 0; k < nbtests; k++) - { - mpfr_random2 (x, xn, 0); - /* check that lower bits are zero */ - if (MPFR_MANT(x)[0] & MPFR_LIMB_MASK(sh)) - { - printf ("Error: mpfr_random2() returns invalid numbers:\n"); - mpfr_print_binary (x); puts (""); - exit (1); - } - - /* check that the number is normalized */ - if (! (MPFR_MANT(x)[MPFR_LIMB_SIZE(x) - 1] >> (BITS_PER_MP_LIMB - 1))) - { - printf ("Error: mpfr_random2() returns unnormalized numbers:\n"); - mpfr_print_binary (x); puts (""); - exit (1); - } - - /* check that exponent is in correct range */ - if (mpfr_get_exp (x) != 0) - { - printf ("Error: mpfr_random2 (.., .., 0) does not return" - " a 0 exponent:\n"); - mpfr_print_binary (x); puts (""); - exit (1); - } - d = mpfr_get_d1 (x); av += d; var += d*d; - if (d < 1) - tab[(int)(size_tab * d)]++; - } - - /* test size=0 */ - mpfr_random2 (x, 0, 0); - MPFR_ASSERTN (mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_POS (x)); - mpfr_set_si (x, -1, MPFR_RNDN); /* x is negative */ - mpfr_random2 (x, 0, 0); - MPFR_ASSERTN (mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_POS (x)); - - /* test size < 0 */ - mpfr_random2 (x, -1, 0); - MPFR_ASSERTN (MPFR_IS_NEG (x) && MPFR_EXP (x) == 0); - - mpfr_clear (x); - if (!verbose) - { - free(tab); - return; - } - - av /= nbtests; - var = (var / nbtests) - av*av; - - th = (double)nbtests / size_tab; - printf("Average = %.5f\nVariance = %.5f\n", av, var); - printf("Repartition for random2 (taking only values < 1 into account.\n"); - - for (k = 0; k < size_tab; k++) - { - chi2 += (tab[k] - th) * (tab[k] - th) / th; - printf("%d ", tab[k]); - if (((k+1) & 7) == 0) - printf("\n"); - } - - printf("\nChi2 statistics value (with %d degrees of freedom) : %.5f\n\n", - size_tab - 1, chi2); - - free(tab); - return; -} static void test_urandomb (long nbtests, mp_prec_t prec, int verbose) @@ -275,14 +128,10 @@ main (int argc, char *argv[]) else prec = atol(argv[2]); - test_random (nbtests, prec, verbose); - test_random2 (nbtests, prec, verbose); test_urandomb (nbtests, prec, verbose); if (argc == 1) /* check also small precision */ { - test_random (nbtests, 2, 0); - test_random2 (nbtests, 2, 0); test_urandomb (nbtests, 2, 0); } diff --git a/tests/tsi_op.c b/tests/tsi_op.c index f709b0696..43d8273e2 100644 --- a/tests/tsi_op.c +++ b/tests/tsi_op.c @@ -68,28 +68,28 @@ check_invert (void) #define TEST_FUNCTION mpfr_add_si #define TEST_FUNCTION_NAME "mpfr_add_si" #define INTEGER_TYPE long -#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1) +#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1, RANDS) #define test_generic_ui test_generic_add_si #include "tgeneric_ui.c" #define TEST_FUNCTION mpfr_sub_si #define TEST_FUNCTION_NAME "mpfr_sub_si" #define INTEGER_TYPE long -#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1) +#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1, RANDS) #define test_generic_ui test_generic_sub_si #include "tgeneric_ui.c" #define TEST_FUNCTION mpfr_mul_si #define TEST_FUNCTION_NAME "mpfr_mul_si" #define INTEGER_TYPE long -#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1) +#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1, RANDS) #define test_generic_ui test_generic_mul_si #include "tgeneric_ui.c" #define TEST_FUNCTION mpfr_div_si #define TEST_FUNCTION_NAME "mpfr_div_si" #define INTEGER_TYPE long -#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1) +#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1, RANDS) #define test_generic_ui test_generic_div_si #include "tgeneric_ui.c" diff --git a/tests/tsub.c b/tests/tsub.c index e69feceb6..190a0f6b6 100644 --- a/tests/tsub.c +++ b/tests/tsub.c @@ -480,7 +480,7 @@ check_inexact (void) #define TEST_FUNCTION test_sub #define TWO_ARGS -#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), randlimb () % 100) +#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), randlimb () % 100, RANDS) #include "tgeneric.c" int diff --git a/tests/tsub_d.c b/tests/tsub_d.c index 1366d2ca2..543fb53f7 100644 --- a/tests/tsub_d.c +++ b/tests/tsub_d.c @@ -69,7 +69,7 @@ check_nans (void) #define TEST_FUNCTION mpfr_sub_d #define DOUBLE_ARG2 -#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1) +#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1, RANDS) #include "tgeneric.c" int diff --git a/tests/tsub_ui.c b/tests/tsub_ui.c index 0bd2ee923..6bcdc1978 100644 --- a/tests/tsub_ui.c +++ b/tests/tsub_ui.c @@ -117,7 +117,7 @@ check_nans (void) #define TEST_FUNCTION mpfr_sub_ui #define INTEGER_TYPE unsigned long -#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1) +#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1, RANDS) #include "tgeneric_ui.c" int diff --git a/tests/ty0.c b/tests/ty0.c index f788e0c76..d38712c2a 100644 --- a/tests/ty0.c +++ b/tests/ty0.c @@ -26,7 +26,7 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., #include "mpfr-test.h" #define TEST_FUNCTION mpfr_y0 -#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 8) +#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 8, RANDS) #include "tgeneric.c" int diff --git a/tests/ty1.c b/tests/ty1.c index f66acbf53..c9d3814e2 100644 --- a/tests/ty1.c +++ b/tests/ty1.c @@ -26,7 +26,7 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., #include "mpfr-test.h" #define TEST_FUNCTION mpfr_y1 -#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 8) +#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 8, RANDS) #include "tgeneric.c" int -- cgit v1.2.1