source: trunk/third/gmp/tests/mpz/t-lucnum_ui.c @ 18191

Revision 18191, 2.7 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18190, which included commits to RCS files with non-trunk default branches.
Line 
1/* Test mpz_lucnum_ui and mpz_lucnum2_ui.
2
3Copyright 2001 Free Software Foundation, Inc.
4
5This file is part of the GNU MP Library.
6
7The GNU MP Library is free software; you can redistribute it and/or modify
8it under the terms of the GNU Lesser General Public License as published by
9the Free Software Foundation; either version 2.1 of the License, or (at your
10option) any later version.
11
12The GNU MP Library is distributed in the hope that it will be useful, but
13WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
15License for more details.
16
17You should have received a copy of the GNU Lesser General Public License
18along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
19the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20MA 02111-1307, USA. */
21
22#include <stdio.h>
23#include <stdlib.h>
24#include "gmp.h"
25#include "gmp-impl.h"
26#include "tests.h"
27
28
29/* Usage: t-lucnum_ui [n]
30
31   Test up to L[n], or if n is omitted then the default limit below.  A
32   literal "x" for the limit means continue forever, this being meant only
33   for development.  */
34
35
36void
37check_sequence (int argc, char *argv[])
38{
39  unsigned long  n;
40  unsigned long  limit = 100 * BITS_PER_MP_LIMB;
41  mpz_t          want_ln, want_ln1, got_ln, got_ln1;
42
43  if (argc > 1 && argv[1][0] == 'x')
44    limit = ULONG_MAX;
45  else if (argc > 1)
46    limit = atoi (argv[1]);
47
48  /* start at n==0 */
49  mpz_init_set_si (want_ln1, -1); /* L[-1] */
50  mpz_init_set_ui (want_ln,  2);  /* L[0]   */
51  mpz_init (got_ln);
52  mpz_init (got_ln1);
53
54  for (n = 0; n < limit; n++)
55    {
56      mpz_lucnum2_ui (got_ln, got_ln1, n);
57      MPZ_CHECK_FORMAT (got_ln);
58      MPZ_CHECK_FORMAT (got_ln1);
59      if (mpz_cmp (got_ln, want_ln) != 0 || mpz_cmp (got_ln1, want_ln1) != 0)
60        {
61          printf ("mpz_lucnum2_ui(%lu) wrong\n", n);
62          mpz_trace ("want ln ", want_ln);
63          mpz_trace ("got  ln ",  got_ln);
64          mpz_trace ("want ln1", want_ln1);
65          mpz_trace ("got  ln1",  got_ln1);
66          abort ();
67        }
68
69      mpz_lucnum_ui (got_ln, n);
70      MPZ_CHECK_FORMAT (got_ln);
71      if (mpz_cmp (got_ln, want_ln) != 0)
72        {
73          printf ("mpz_lucnum_ui(%lu) wrong\n", n);
74          mpz_trace ("want ln", want_ln);
75          mpz_trace ("got  ln", got_ln);
76          abort ();
77        }
78
79      mpz_add (want_ln1, want_ln1, want_ln);  /* L[n+1] = L[n] + L[n-1] */
80      mpz_swap (want_ln1, want_ln);
81    }
82
83  mpz_clear (want_ln);
84  mpz_clear (want_ln1);
85  mpz_clear (got_ln);
86  mpz_clear (got_ln1);
87}
88
89int
90main (int argc, char *argv[])
91{
92  tests_start ();
93  mp_trace_base = -16;
94
95  check_sequence (argc, argv);
96
97  tests_end ();
98  exit (0);
99}
Note: See TracBrowser for help on using the repository browser.