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 (const char *desc, mpf_ptr got, unsigned long u, mpf_srcptr v)
34 ulimbs[0] = u & GMP_NUMB_MASK;
36 #if BITS_PER_ULONG > GMP_NUMB_BITS
45 if (! refmpf_validate_division ("mpf_ui_div", got, uf, v))
48 printf (" u 0x%lX (%lu)\n", u, u);
50 printf (" %s\n", desc);
58 unsigned long min_prec = __GMPF_BITS_TO_PREC (1);
59 gmp_randstate_ptr rands = RANDS;
60 unsigned long prec, u;
67 for (i = 0; i < 200; i++)
70 prec = min_prec + gmp_urandomm_ui (rands, 15L);
71 refmpf_set_prec_limbs (got, prec);
74 prec = gmp_urandomm_ui (rands, BITS_PER_ULONG+1);
75 u = gmp_urandomb_ui (rands, prec);
78 prec = min_prec + gmp_urandomm_ui (rands, 15L);
79 refmpf_set_prec_limbs (v, prec);
83 mpf_random2 (v, PREC(v), (mp_exp_t) 20);
84 } while (SIZ(v) == 0);
86 /* v possibly negative */
87 if (gmp_urandomb_ui (rands, 1L))
93 mpf_ui_div (got, u, v);
94 check_one ("separate", got, u, v);
99 prec = refmpf_set_overlap (got, v);
100 mpf_ui_div (got, u, got);
101 check_one ("overlap src==dst", got, u, v);
103 mpf_set_prec_raw (got, prec);
120 mpf_set_prec (got, 20L);
122 mpf_ui_div (got, 100L, v);
123 MPF_CHECK_FORMAT (got);
124 ASSERT_ALWAYS (mpf_cmp_ui (got, 25L) == 0);
127 /* 1/(2^n+1), a case where truncating the divisor would be wrong */
128 unsigned long u = 1L;
129 mpf_set_prec (got, 500L);
130 mpf_set_prec (v, 900L);
132 mpf_mul_2exp (v, v, 800L);
133 mpf_add_ui (v, v, 1L);
134 mpf_ui_div (got, u, v);
135 check_one ("1/2^n+1, separate", got, u, v);