FIBNUM 3CW "12 December 2009" "mathcw-1.00"

Table of contents


NAME

fibnum - n-th Fibonacci number

SYNOPSIS

cc [ flags ] -I/usr/local/include file(s) -L/usr/local/lib -lmcw [ ... ]

#include <mathcw.h>

extern float fibnumf (int n);

extern double fibnum (int n);

extern long double fibnuml (int n);

extern __float80 fibnumw (int n);

extern __float128 fibnumq (int n);

extern long_long_double fibnumll (int n);

extern decimal_float fibnumdf (int n);

extern decimal_double fibnumd (int n);

extern decimal_long_double fibnumdl (int n);

extern decimal_long_long_double fibnumdll (int n);

NB: Functions with prototypes containing underscores in type names may be available only with certain extended compilers.


DESCRIPTION

Determine the n-th Fibonacci number, F[n], by fast, and exact, table lookup, where n >= 0. Computation above the table boundary requires a single power-function call.

The Fibonacci numbers are defined by the recurrence relation

F[0] = 0; F[1] = 1; F[k] = F[k - 1] + F[k - 2] (for k > 1)
and are positive for nonnegative indexes.

The recurrence can be applied downward to reach negative indexes, and negative Fibonacci numbers, although this is uncommon. Apart from the signs, the sequence is the same, so we have the index-symmetry relation

F[-k] = (-1)**(k + 1) * F[k].

In IEEE 754 32-bit binary arithmetic, the result is +Infinity for n > 186. The overflow limits in IEEE 754 binary 64-bit, 80-bit, and 128-bit arithmetic are reached for n values above 1476, 23601, and 23601, respectively. The corresponding values in IEEE 754 32-bit, 64-bit, and 128-bit decimal arithmetic are 465, 1843, and 29405, respectively.

Once overflow is detected, the index that caused it is remembered so that unnecessary computation can be avoided if it is exceeded in subsequent calls.


RETURN VALUES

Return the n-th Fibonacci number.

ERRORS

If the result overflows, set errno to ERANGE, and return an Infinity, if available, and otherwise, the largest finite floating-point value.

SEE ALSO

bernum(3CW), betnm1(3CW), betnum(3CW), eulnum(3CW), zetnm1(3CW), zetnum(3CW).