Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions lib/node_modules/@stdlib/math/base/special/fibonacci/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ out = stdlib_base_fibonacci( 1 );

The function accepts the following arguments:

- **n**: `[in] int32_t` input value.
- **n**: `[in] double` input value.

```c
double stdlib_base_fibonacci( const int32_t n );
double stdlib_base_fibonacci( const double n );
```

</section>
Expand All @@ -212,15 +212,14 @@ double stdlib_base_fibonacci( const int32_t n );
```c
#include "stdlib/math/base/special/fibonacci.h"
#include <stdio.h>
#include <stdint.h>

int main( void ) {
int32_t i;
double i;
double v;

for ( i = 0; i < 79; i++ ) {
for ( i = 0.0; i < 79.0; i++ ) {
v = stdlib_base_fibonacci( i );
printf( "fibonacci(%d) = %lf\n", i, v );
printf( "fibonacci(%lf) = %lf\n", i, v );
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ static double rand_double( void ) {
*/
static double benchmark( void ) {
double elapsed;
int32_t x[ 100 ];
double x[ 100 ];
double t;
double y;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = (int32_t)floor( 40.0*rand_double() );
x[ i ] = floor( 40.0*rand_double() );
}

t = tic();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@

#include "stdlib/math/base/special/fibonacci.h"
#include <stdio.h>
#include <stdint.h>

int main( void ) {
int32_t i;
double i;
double v;

for ( i = 0; i < 79; i++ ) {
for ( i = 0.0; i < 79.0; i++ ) {
v = stdlib_base_fibonacci( i );
printf( "fibonacci(%d) = %lf\n", i, v );
printf( "fibonacci(%lf) = %lf\n", i, v );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#ifndef STDLIB_MATH_BASE_SPECIAL_FIBONACCI_H
#define STDLIB_MATH_BASE_SPECIAL_FIBONACCI_H

#include <stdint.h>

/*
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
*/
Expand All @@ -31,7 +29,7 @@ extern "C" {
/**
* Computes the nth Fibonacci number.
*/
double stdlib_base_fibonacci( const int32_t n );
double stdlib_base_fibonacci( const double n );

#ifdef __cplusplus
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// MODULES //

var isnan = require( '@stdlib/math/base/assert/is-nan' );
var isInteger = require( '@stdlib/math/base/assert/is-integer' );
var isNonnegativeInteger = require( '@stdlib/math/base/assert/is-nonnegative-integer' );
var MAX_FIBONACCI = require( '@stdlib/constants/float64/max-safe-nth-fibonacci' );
var FIBONACCI = require( './fibonacci.json' );

Expand Down Expand Up @@ -77,8 +77,7 @@ var FIBONACCI = require( './fibonacci.json' );
function fibonacci( n ) {
if (
isnan( n ) ||
isInteger( n ) === false ||
n < 0 ||
!isNonnegativeInteger( n ) ||
n > MAX_FIBONACCI
) {
return NaN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"libpath": [],
"dependencies": [
"@stdlib/math/base/napi/unary",
"@stdlib/constants/float64/max-safe-nth-fibonacci"
"@stdlib/constants/float64/max-safe-nth-fibonacci",
"@stdlib/math/base/assert/is-nonnegative-integer"
]
},
{
Expand All @@ -51,7 +52,8 @@
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/constants/float64/max-safe-nth-fibonacci"
"@stdlib/constants/float64/max-safe-nth-fibonacci",
"@stdlib/math/base/assert/is-nonnegative-integer"
]
},
{
Expand All @@ -65,7 +67,8 @@
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/constants/float64/max-safe-nth-fibonacci"
"@stdlib/constants/float64/max-safe-nth-fibonacci",
"@stdlib/math/base/assert/is-nonnegative-integer"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
#include "stdlib/math/base/special/fibonacci.h"
#include "stdlib/math/base/napi/unary.h"

STDLIB_MATH_BASE_NAPI_MODULE_I_D( stdlib_base_fibonacci )
STDLIB_MATH_BASE_NAPI_MODULE_D_D( stdlib_base_fibonacci )
13 changes: 8 additions & 5 deletions lib/node_modules/@stdlib/math/base/special/fibonacci/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

#include "stdlib/math/base/special/fibonacci.h"
#include "stdlib/constants/float64/max_safe_nth_fibonacci.h"
#include "stdlib/math/base/assert/is_nonnegative_integer.h"
#include <stdint.h>
#include <stdlib.h>

static const int64_t fibonacci_value[ 79 ] = {
0,
Expand Down Expand Up @@ -108,12 +111,12 @@ static const int64_t fibonacci_value[ 79 ] = {
* @return output value
*
* @example
* double out = stdlib_base_fibonacci( 1 );
* // returns 1
* double out = stdlib_base_fibonacci( 1.0 );
* // returns 1.0
*/
double stdlib_base_fibonacci( const int32_t n ) {
if ( n < 0 || n > STDLIB_CONSTANT_FLOAT64_MAX_SAFE_NTH_FIBONACCI ) {
double stdlib_base_fibonacci( const double n ) {
if ( !stdlib_base_is_nonnegative_integer( n ) || n > STDLIB_CONSTANT_FLOAT64_MAX_SAFE_NTH_FIBONACCI ) {
return 0.0 / 0.0; // NaN
}
return fibonacci_value[ n ];
return fibonacci_value[ (size_t)n ];
}