gmp_libmpz_fib2_ui Method |
Namespace: Math.Gmp.Native
Assembly: Math.Gmp.Native (in Math.Gmp.Native.dll) Version: 1.0.0.0 (1.0.0.0)

public static void mpz_fib2_ui( mpz_t fn, mpz_t fnsub1, uint n )
Public Shared Sub mpz_fib2_ui ( fn As mpz_t, fnsub1 As mpz_t, n As UInteger )
public: static void mpz_fib2_ui( mpz_t^ fn, mpz_t^ fnsub1, unsigned int n )
static member mpz_fib2_ui : fn : mpz_t * fnsub1 : mpz_t * n : uint32 -> unit
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.

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.

// 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);
' Create, initialize, and set the values of fn and fnsub1 to 0. Dim fn As New mpz_t() Dim fnsub1 As New mpz_t() gmp_lib.mpz_inits(fn, fnsub1, Nothing) ' Set fnsub1 and fn to the 19'th and 20'th Fibonacci numbers respectively. gmp_lib.mpz_fib2_ui(fn, fnsub1, 20UI) ' 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, Nothing)
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
