1
/* Exercise mpz_bin_ui and mpz_bin_uiui. */
4
Copyright (C) 2000 Free Software Foundation, Inc.
6
This file is part of the GNU MP Library.
8
The GNU MP Library is free software; you can redistribute it and/or modify
9
it under the terms of the GNU Lesser General Public License as published by
10
the Free Software Foundation; either version 2.1 of the License, or (at your
11
option) any later version.
13
The GNU MP Library is distributed in the hope that it will be useful, but
14
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16
License for more details.
18
You should have received a copy of the GNU Lesser General Public License
19
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
20
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
32
mpz_out_str (FILE *stream, int base, mpz_srcptr x);
34
mpz_out_str (stream, base, x);
38
try_mpz_bin_ui (mpz_srcptr want, mpz_srcptr n, unsigned long k)
43
mpz_bin_ui (got, n, k);
44
MPZ_CHECK_FORMAT (got);
45
if (mpz_cmp (got, want) != 0)
47
printf ("mpz_bin_ui wrong\n");
48
printf (" n="); mpz_out_str (stdout, 10, n); printf ("\n");
49
printf (" k=%lu\n", k);
50
printf (" got="); mpz_out_str (stdout, 10, got); printf ("\n");
51
printf (" want="); mpz_out_str (stdout, 10, want); printf ("\n");
59
try_mpz_bin_uiui (mpz_srcptr want, unsigned long n, unsigned long k)
64
mpz_bin_uiui (got, n, k);
65
MPZ_CHECK_FORMAT (got);
66
if (mpz_cmp (got, want) != 0)
68
printf ("mpz_bin_uiui wrong\n");
69
printf (" n=%lu\n", n);
70
printf (" k=%lu\n", k);
71
printf (" got="); mpz_out_str (stdout, 10, got); printf ("\n");
72
printf (" want="); mpz_out_str (stdout, 10, want); printf ("\n");
100
{ "1", 123456, "0" },
107
{ "2", 123456, "0" },
115
{ "3", 123456, "0" },
124
{ "4", 123456, "0" },
139
{ "10", 123456, "0" },
141
/* negatives, using bin(-n,k)=bin(n+k-1,k) */
164
{ "40", 20, "137846528820" },
165
{ "60", 30, "118264581564861424" },
174
for (i = 0; i < numberof (data); i++)
176
mpz_set_str (n, data[i].n, 0);
177
mpz_set_str (want, data[i].want, 0);
179
try_mpz_bin_ui (want, n, data[i].k);
181
if (mpz_fits_ulong_p (n))
182
try_mpz_bin_uiui (want, mpz_get_ui (n), data[i].k);
190
/* Test some bin(2k,k) cases. This produces some biggish numbers to
191
exercise the limb accumulating code. */
201
mpz_set_ui (want, (unsigned long) 2);
202
for (k = 1; k < 200; k++)
205
try_mpz_bin_ui (want, n, k);
207
try_mpz_bin_uiui (want, 2*k, k);
209
mpz_mul_ui (want, want, 2*(2*k+1));
210
mpz_fdiv_q_ui (want, want, k+1);