Compute the nth negaFibonacci number.
We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we’ve built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.
The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.
When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.
To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url]
Compute the nth [negaFibonacci number][fibonacci-number].
math
0, 1, -1, 2, -3, 5, -8, 13, -21, 34, -55, 89, -144, \ldots
math
F_{n-2} = F_{n} - F_{n-1}
math
F_{-n} = (-1)^{n+1} F_n
F_0 = 0
and F_{-1} = 1
.bash
npm install @stdlib/math-base-special-negafibonacci
script
tag without installation and bundlers, use the [ES Module][es-module] available on the [esm
][esm-url] branch (see [README][esm-readme]).deno
][deno-url] branch (see [README][deno-readme] for usage intructions).umd
][umd-url] branch (see [README][umd-readme]).javascript
var negafibonacci = require( '@stdlib/math-base-special-negafibonacci' );
javascript
var v = negafibonacci( 0 );
// returns 0
v = negafibonacci( -1 );
// returns 1
v = negafibonacci( -2 );
// returns -1
v = negafibonacci( -3 );
// returns 2
v = negafibonacci( -78 );
// returns -8944394323791464
n < -78
, the function returns NaN
, as larger [negaFibonacci numbers][fibonacci-number] cannot be safely represented in [double-precision floating-point format][ieee754].javascript
var v = negafibonacci( -79 );
// returns NaN
NaN
.javascript
var v = negafibonacci( -3.14 );
// returns NaN
v = negafibonacci( 1 );
// returns NaN
NaN
, the function returns NaN
.javascript
var v = negafibonacci( NaN );
// returns NaN
javascript
var negafibonacci = require( '@stdlib/math-base-special-negafibonacci' );
var v;
var i;
for ( i = 0; i > -79; i-- ) {
v = negafibonacci( i );
console.log( v );
}
c
#include "stdlib/math/base/special/negafibonacci.h"
c
double out = stdlib_base_negafibonacci( 0 );
// returns 0
out = stdlib_base_negafibonacci( -1 );
// returns 1
[in] int32_t
input value.c
double stdlib_base_negafibonacci( const int32_t n );
c
#include "stdlib/math/base/special/negafibonacci.h"
#include <stdio.h>
#include <stdint.h>
int main( void ) {
int32_t i;
double v;
for ( i = 0; i > -79; i-- ) {
v = stdlib_base_negafibonacci( i );
printf( "negafibonacci(%d) = %lf\n", i, v );
}
}