Click or drag to resize
gmp_libmpz_fib2_ui Method
Sets fn to F[n], and fnsub1 to F[n - 1].

Namespace:  Math.Gmp.Native
Assembly:  Math.Gmp.Native (in Math.Gmp.Native.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
public static void mpz_fib2_ui(
	mpz_t fn,
	mpz_t fnsub1,
	uint n
)

Parameters

fn
Type: Math.Gmp.Nativempz_t
The F[n] result.
fnsub1
Type: Math.Gmp.Nativempz_t
The F[n - 1] result.
n
Type: SystemUInt32
The operand integer.
Remarks

This function is designed for calculating isolated Fibonacci numbers. When a sequence of values is wanted it’s best to start with mpz_fib2_ui and iterate the defining F[n + 1] = F[n] + F[n - 1] or similar.

The Fibonacci numbers and Lucas numbers are related sequences, so it’s never necessary to call both mpz_fib2_ui and mpz_lucnum2_ui. The formulas for going from Fibonacci to Lucas can be found in GNU MP - Lucas Numbers Algorithm, the reverse is straightforward too.

Examples
// Create, initialize, and set the values of fn and fnsub1 to 0.
mpz_t fn = new mpz_t();
mpz_t fnsub1 = new mpz_t();
gmp_lib.mpz_inits(fn, fnsub1, null);

// Set fnsub1 and fn to the 19'th and 20'th Fibonacci numbers respectively.
gmp_lib.mpz_fib2_ui(fn, fnsub1, 20U);

// Assert that fnsub1 and fn are respectively 4181 and 6765.
Assert.IsTrue(gmp_lib.mpz_get_si(fnsub1) == 4181);
Assert.IsTrue(gmp_lib.mpz_get_si(fn) == 6765);

// Release unmanaged memory allocated for fn and fnsub1.
gmp_lib.mpz_clears(fn, fnsub1, null);
See Also