Fibonacci: Fibonacci Numbers Tools for vli Objects

Description Usage Arguments Value Author(s) Examples

View source: R/Fibonacci.R

Description

The Fibonacci Sequence is defined as follows:

x[1] = 0,

x[2] = 1,

...

x[n] = x[n-1] + x[n-2].

A positive integer is said to be a Fibonacci Number if it is an element of the Fibonacci Sequence.

The function Fibonacci(m, output) computes and displays the first m elements of the Fibonacci Sequence.

The function nthFibonacci(n) computes and displays the n-th element of the Fibonacci Sequence.

The function is.Fibonacci(x) says whether or not x is a Fibonacci Number.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Fibonacci(m, output = "print")

## Default S3 method:
Fibonacci(m, output = "print")

## S3 method for class 'numeric'
Fibonacci(m, output = "print")

nthFibonacci(n)

## Default S3 method:
nthFibonacci(n)

## S3 method for class 'numeric'
nthFibonacci(n)

## S3 method for class 'vli'
nthFibonacci(n)

is.Fibonacci(x)

## Default S3 method:
is.Fibonacci(x)

## S3 method for class 'numeric'
is.Fibonacci(x)

## S3 method for class 'vli'
is.Fibonacci(x)

Arguments

m

object of class vli or 32 bits integer

output

chosen way for objects being returned: 'list' to return the result as a list of vli objects or 'print' (by default) to simply display the result on the screen; character

n

vli class object or 32 bits integer

x

vli class object or 32 bits integer

Value

The function Fibonacci(m, output) returns a list of objects of class vli or the result displayed on the screen, depending on the output argument.

The function nthFibonacci(n) returns a object of class vli.

The function is.Fibonacci(x) returns a boolean.

Author(s)

Javier Leiva Cuadrado

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
Fibonacci(200)

n <- as.vli("50000")
nthFibonacci(n)

x <- as.vli("5358359254990966640871840")
is.Fibonacci(x)

y <- x + 1
is.Fibonacci(y)

VeryLargeIntegers documentation built on March 26, 2020, 5:48 p.m.