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, mpf_srcptr u, mpf_srcptr v)
30 if (! refmpf_validate_division ("mpf_div", got, u, v))
35 printf (" %s\n", desc);
43 unsigned long min_prec = __GMPF_BITS_TO_PREC (1);
44 gmp_randstate_ptr rands = RANDS;
54 for (i = 0; i < 100; i++)
57 prec = min_prec + gmp_urandomm_ui (rands, 15L);
58 refmpf_set_prec_limbs (got, prec);
61 prec = min_prec + gmp_urandomm_ui (rands, 15L);
62 refmpf_set_prec_limbs (u, prec);
64 mpf_random2 (u, PREC(u), (mp_exp_t) 20);
65 } while (SIZ(u) == 0);
66 if (gmp_urandomb_ui (rands, 1L))
70 prec = min_prec + gmp_urandomm_ui (rands, 15L);
71 refmpf_set_prec_limbs (v, prec);
73 mpf_random2 (v, PREC(v), (mp_exp_t) 20);
74 } while (SIZ(v) == 0);
75 if (gmp_urandomb_ui (rands, 1L))
81 check_one ("separate", got, u, v);
84 prec = refmpf_set_overlap (got, u);
85 mpf_div (got, got, v);
86 check_one ("dst == u", got, u, v);
87 mpf_set_prec_raw (got, prec);
90 prec = refmpf_set_overlap (got, v);
91 mpf_div (got, u, got);
92 check_one ("dst == v", got, u, v);
93 mpf_set_prec_raw (got, prec);
103 /* Exercise calls mpf(x,x,x) */
105 check_reuse_three (void)
107 unsigned long min_prec = __GMPF_BITS_TO_PREC (1);
108 gmp_randstate_ptr rands = RANDS;
109 unsigned long result_prec, input_prec, set_prec;
115 for (i = 0; i < 8; i++)
117 result_prec = min_prec + gmp_urandomm_ui (rands, 15L);
118 input_prec = min_prec + gmp_urandomm_ui (rands, 15L);
120 set_prec = MAX (result_prec, input_prec);
121 refmpf_set_prec_limbs (got, set_prec);
123 /* input, non-zero, possibly negative */
124 PREC(got) = input_prec;
126 mpf_random2 (got, input_prec, (mp_exp_t) 20);
127 } while (SIZ(got) == 0);
128 if (gmp_urandomb_ui (rands, 1L))
131 PREC(got) = result_prec;
133 mpf_div (got, got, got);
135 /* expect exactly 1.0 always */
136 ASSERT_ALWAYS (mpf_cmp_ui (got, 1L) == 0);
138 PREC(got) = set_prec;
154 mpf_set_prec (got, 20L);
155 mpf_set_ui (u, 100L);
158 MPF_CHECK_FORMAT (got);
159 ASSERT_ALWAYS (mpf_cmp_ui (got, 25L) == 0);
161 /* 1/(2^n+1), a case where truncating the divisor would be wrong */
162 mpf_set_prec (got, 500L);
163 mpf_set_prec (v, 900L);
165 mpf_mul_2exp (v, v, 800L);
166 mpf_add_ui (v, v, 1L);
168 check_one ("1/2^n+1, separate", got, u, v);
182 check_reuse_three ();