1 /* Test mpz_lucnum_ui and mpz_lucnum2_ui.
3 Copyright 2001 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/. */
27 /* Usage: t-lucnum_ui [n]
29 Test up to L[n], or if n is omitted then the default limit below. A
30 literal "x" for the limit means continue forever, this being meant only
35 check_sequence (int argc, char *argv[])
38 unsigned long limit = 100 * GMP_LIMB_BITS;
39 mpz_t want_ln, want_ln1, got_ln, got_ln1;
41 if (argc > 1 && argv[1][0] == 'x')
44 limit = atoi (argv[1]);
47 mpz_init_set_si (want_ln1, -1); /* L[-1] */
48 mpz_init_set_ui (want_ln, 2); /* L[0] */
52 for (n = 0; n < limit; n++)
54 mpz_lucnum2_ui (got_ln, got_ln1, n);
55 MPZ_CHECK_FORMAT (got_ln);
56 MPZ_CHECK_FORMAT (got_ln1);
57 if (mpz_cmp (got_ln, want_ln) != 0 || mpz_cmp (got_ln1, want_ln1) != 0)
59 printf ("mpz_lucnum2_ui(%lu) wrong\n", n);
60 mpz_trace ("want ln ", want_ln);
61 mpz_trace ("got ln ", got_ln);
62 mpz_trace ("want ln1", want_ln1);
63 mpz_trace ("got ln1", got_ln1);
67 mpz_lucnum_ui (got_ln, n);
68 MPZ_CHECK_FORMAT (got_ln);
69 if (mpz_cmp (got_ln, want_ln) != 0)
71 printf ("mpz_lucnum_ui(%lu) wrong\n", n);
72 mpz_trace ("want ln", want_ln);
73 mpz_trace ("got ln", got_ln);
77 mpz_add (want_ln1, want_ln1, want_ln); /* L[n+1] = L[n] + L[n-1] */
78 mpz_swap (want_ln1, want_ln);
88 main (int argc, char *argv[])
93 check_sequence (argc, argv);