1 /* Exercise mpf_mul_ui.
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, unsigned long v)
30 mp_size_t usize, usign;
34 MPF_CHECK_FORMAT (got);
36 /* this code not nailified yet */
37 ASSERT_ALWAYS (BITS_PER_ULONG <= GMP_NUMB_BITS);
40 wp = refmpn_malloc_limbs (usize + 1);
41 wp[usize] = mpn_mul_1 (wp, PTR(u), usize, (mp_limb_t) v);
44 SIZ(want) = (usign >= 0 ? usize+1 : -(usize+1));
45 EXP(want) = EXP(u) + 1;
46 refmpf_normalize (want);
48 if (! refmpf_validate ("mpf_mul_ui", got, want))
51 printf (" %s\n", desc);
53 printf (" v %ld 0x%lX\n", v, v);
63 unsigned long min_prec = __GMPF_BITS_TO_PREC (1);
64 gmp_randstate_ptr rands = RANDS;
66 unsigned long prec, v;
69 /* The nails code in mpf_mul_ui currently isn't exact, so suppress these
71 if (BITS_PER_ULONG > GMP_NUMB_BITS)
77 for (i = 0; i < 200; i++)
80 prec = min_prec + gmp_urandomm_ui (rands, 15L);
81 refmpf_set_prec_limbs (got, prec);
84 prec = min_prec + gmp_urandomm_ui (rands, 15L);
85 refmpf_set_prec_limbs (u, prec);
87 /* u, possibly negative */
88 mpf_random2 (u, PREC(u), (mp_exp_t) 20);
89 if (gmp_urandomb_ui (rands, 1L))
92 /* v, 0 to BITS_PER_ULONG bits (inclusive) */
93 prec = gmp_urandomm_ui (rands, BITS_PER_ULONG+1);
94 v = gmp_urandomb_ui (rands, prec);
99 mpf_mul_ui (got, u, v);
100 check_one ("separate", got, u, v);
105 prec = refmpf_set_overlap (got, u);
106 mpf_mul_ui (got, got, v);
107 check_one ("overlap src==dst", got, u, v);
109 mpf_set_prec_raw (got, prec);
123 mpf_init2 (u, 2*8*sizeof(long));
124 mpf_init2 (got, 2*8*sizeof(long));
125 mpf_init2 (want, 2*8*sizeof(long));
129 mpf_mul_ui (got, u, ULONG_MAX);
130 MPF_CHECK_FORMAT (got);
131 mpf_set_ui (want, 0L);
132 if (mpf_cmp (got, want) != 0)
135 printf ("Wrong result from %s\n", s);
137 mpf_trace ("got ", got);
138 mpf_trace ("want", want);
144 mpf_mul_ui (got, u, ULONG_MAX);
145 MPF_CHECK_FORMAT (got);
146 mpf_set_ui (want, ULONG_MAX);
147 if (mpf_cmp (got, want) != 0)