GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
/* Generate Fibonacci table data.12Copyright 2001, 2002, 2004 Free Software Foundation, Inc.34This file is part of the GNU MP Library.56The GNU MP Library is free software; you can redistribute it and/or modify7it under the terms of the GNU Lesser General Public License as published by8the Free Software Foundation; either version 2.1 of the License, or (at your9option) any later version.1011The GNU MP Library is distributed in the hope that it will be useful, but12WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY13or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public14License for more details.1516You should have received a copy of the GNU Lesser General Public License17along with the GNU MP Library; see the file COPYING.LIB. If not, write to18the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,19MA 02110-1301, USA. */2021#include <stdio.h>22#include "dumbmp.c"2324mpz_t *f;25int fnum, fib_limit, luc_limit;2627void28generate (int numb_bits)29{30mpz_t limit, l;31int falloc, i;3233mpz_init_set_ui (limit, 1L);34mpz_mul_2exp (limit, limit, numb_bits);3536/* fib(2n) > 2^n, so use 2n as a limit for the table size */37falloc = 2 * numb_bits;38f = (mpz_t *) xmalloc (falloc * sizeof (*f));3940mpz_init_set_ui (f[0], 1L); /* F[-1] */41mpz_init_set_ui (f[1], 0L); /* F[0] */4243mpz_init (l);4445for (i = 2; ; i++)46{47ASSERT (i < falloc);4849/* F[i] = F[i-1] + F[i-2] */50mpz_init (f[i]);51mpz_add (f[i], f[i-1], f[i-2]);52if (mpz_cmp (f[i], limit) >= 0)53break;5455fnum = i+1;56fib_limit = i-1;5758/* L[i] = F[i]+2*F[i-1] */59mpz_add (l, f[i], f[i-1]);60mpz_add (l, l, f[i-1]);6162if (mpz_cmp (l, limit) < 0)63luc_limit = i-1;64}6566mpz_clear (limit);67}686970void71header (int numb_bits)72{73printf ("/* This file generated by gen-fib.c - DO NOT EDIT. */\n");74printf ("\n");75printf ("#if GMP_NUMB_BITS != %d\n", numb_bits);76printf ("Error, error, this data is for %d bits\n", numb_bits);77printf ("#endif\n");78printf ("\n");79printf ("#define FIB_TABLE_LIMIT %d\n", fib_limit);80printf ("#define FIB_TABLE_LUCNUM_LIMIT %d\n", luc_limit);81}8283void84table (int numb_bits)85{86int i;8788printf ("/* This file generated by gen-fib.c - DO NOT EDIT. */\n");89printf ("\n");90printf ("#include \"gmp.h\"\n");91printf ("#include \"gmp-impl.h\"\n");92printf ("\n");93printf ("#if GMP_NUMB_BITS != %d\n", numb_bits);94printf ("Error, error, this data is for %d bits\n", numb_bits);95printf ("#endif\n");96printf ("\n");97printf ("const mp_limb_t\n");98printf ("__gmp_fib_table[FIB_TABLE_LIMIT+2] = {\n");99100for (i = 0; i < fnum; i++)101{102printf (" CNST_LIMB (0x");103mpz_out_str (stdout, 16, f[i]);104printf ("), /* %d */\n", i-1);105}106printf ("};\n");107}108109int110main (int argc, char *argv[])111{112int limb_bits, nail_bits, numb_bits;113114if (argc != 4)115{116fprintf (stderr, "Usage: gen-bases <header|table> <limbbits> <nailbits>\n");117exit (1);118}119120limb_bits = atoi (argv[2]);121nail_bits = atoi (argv[3]);122123if (limb_bits <= 0124|| nail_bits < 0125|| nail_bits >= limb_bits)126{127fprintf (stderr, "Invalid limb/nail bits: %d %d\n",128limb_bits, nail_bits);129exit (1);130}131numb_bits = limb_bits - nail_bits;132133generate (numb_bits);134135if (strcmp (argv[1], "header") == 0)136header (numb_bits);137else if (strcmp (argv[1], "table") == 0)138table (numb_bits);139else140{141fprintf (stderr, "Invalid header/table choice: %s\n", argv[1]);142exit (1);143}144145return 0;146}147148149