3 Copyright 2004 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
7 The GNU MP Library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
12 The GNU MP Library is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
28 check_one (mpf_ptr got, mpq_srcptr q)
34 PTR(n) = PTR(&q->_mp_num);
35 SIZ(n) = SIZ(&q->_mp_num);
36 EXP(n) = ABSIZ(&q->_mp_num);
38 PTR(d) = PTR(&q->_mp_den);
39 SIZ(d) = SIZ(&q->_mp_den);
40 EXP(d) = ABSIZ(&q->_mp_den);
42 if (! refmpf_validate_division ("mpf_set_q", got, n, d))
53 unsigned long min_prec = __GMPF_BITS_TO_PREC (1);
54 gmp_randstate_ptr rands = RANDS;
63 for (i = 0; i < 400; i++)
65 /* result precision */
66 prec = min_prec + gmp_urandomm_ui (rands, 20L);
67 refmpf_set_prec_limbs (got, prec);
70 prec = gmp_urandomm_ui (rands, 20L * GMP_NUMB_BITS);
71 mpz_rrandomb (mpq_numref(q), rands, prec);
73 /* possibly negative num */
74 if (gmp_urandomb_ui (rands, 1L))
75 mpz_neg (mpq_numref(q), mpq_numref(q));
79 prec = gmp_urandomm_ui (rands, 20L * GMP_NUMB_BITS);
80 mpz_rrandomb (mpq_denref(q), rands, prec);
81 } while (mpz_sgn (mpq_denref(q)) <= 0);
100 mpf_set_prec (got, 20L);
101 mpq_set_ui (q, 1L, 1L);
103 MPF_CHECK_FORMAT (got);
104 ASSERT_ALWAYS (mpf_cmp_ui (got, 1L) == 0);
106 /* 1/(2^n+1), a case where truncating the divisor would be wrong */
107 mpf_set_prec (got, 500L);
108 mpq_set_ui (q, 1L, 1L);
109 mpz_mul_2exp (mpq_denref(q), mpq_denref(q), 800L);
110 mpz_add_ui (mpq_denref(q), mpq_denref(q), 1L);