@stdlib/math-base-special-nonfibonacci
v0.3.0
Published
Compute the nth non-Fibonacci number.
Downloads
69
Readme
Non-Fibonacci
Compute the nth non-Fibonacci number.
The nth non-Fibonacci number is given by
where φ
is the golden ratio.
Installation
npm install @stdlib/math-base-special-nonfibonacci
Usage
var nonfibonacci = require( '@stdlib/math-base-special-nonfibonacci' );
nonfibonacci( n )
Computes the nth non-Fibonacci number.
var v = nonfibonacci( 1 );
// returns 4
v = nonfibonacci( 2 );
// returns 6
v = nonfibonacci( 3 );
// returns 7
If provided either a non-integer or n < 1
, the function returns NaN
.
var v = nonfibonacci( -1 );
// returns NaN
v = nonfibonacci( 3.14 );
// returns NaN
If provided NaN
, the function returns NaN
.
var v = nonfibonacci( NaN );
// returns NaN
Examples
var nonfibonacci = require( '@stdlib/math-base-special-nonfibonacci' );
var v;
var i;
for ( i = 1; i < 100; i++ ) {
v = nonfibonacci( i );
console.log( 'nonfibonacci(%d) = %d', i, v );
}
C APIs
Usage
#include "stdlib/math/base/special/nonfibonacci.h"
stdlib_base_nonfibonacci( x )
Computes the nth non-Fibonacci number.
double out = stdlib_base_nonfibonacci( 1 );
// returns 4
out = stdlib_base_nonfibonacci( 2 );
// returns 6
The function accepts the following arguments:
- x:
[in] int32_t
input value.
double stdlib_base_nonfibonacci( const int32_t x );
Examples
#include "stdlib/math/base/special/nonfibonacci.h"
#include <stdio.h>
#include <stdlib.h>
int main( void ) {
int i;
for ( i = 1; i < 12; i++ ) {
double result = stdlib_base_nonfibonacci( i );
printf( "x: %i => result: %lf", i , result );
}
}
References
- Gould, H.W. 1965. "Non-Fibonacci Numbers." Fibonacci Quarterly, no. 3: 177–83. <http://www.fq.math.ca/Scanned/3-3/gould.pdf>.
- Farhi, Bakir. 2011. "An explicit formula generating the non-Fibonacci numbers." arXiv abs/1105.1127 [Math.NT] (May): 1–5. <https://arxiv.org/abs/1105.1127>.
See Also
@stdlib/math-base/special/fibonacci
: compute the nth Fibonacci number.
Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2024. The Stdlib Authors.