Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 9 additions & 10 deletions lib/node_modules/@stdlib/math/base/special/negafibonacci/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,19 +191,19 @@ for ( i = 0; i > -79; i-- ) {
Computes the nth [negaFibonacci number][fibonacci-number].

```c
double out = stdlib_base_negafibonacci( 0 );
// returns 0
double out = stdlib_base_negafibonacci( 0.0 );
// returns 0.0

out = stdlib_base_negafibonacci( -1 );
// returns 1
out = stdlib_base_negafibonacci( -1.0 );
// returns 1.0
```

The function accepts the following arguments:

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

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

</section>
Expand All @@ -227,15 +227,14 @@ 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 i;
double v;

for ( i = 0; i > -79; i-- ) {
for ( i = 0.0; i > -79.0; i-- ) {
v = stdlib_base_negafibonacci( i );
printf( "negafibonacci(%d) = %lf\n", i, v );
printf( "negafibonacci(%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/negafibonacci.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_negafibonacci( i );
printf( "negafibonacci(%d) = %lf\n", i, v );
printf( "negafibonacci(%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_NEGAFIBONACCI_H
#define STDLIB_MATH_BASE_SPECIAL_NEGAFIBONACCI_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 negaFibonacci number.
*/
double stdlib_base_negafibonacci( const int32_t n );
double stdlib_base_negafibonacci( const double n );

#ifdef __cplusplus
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"dependencies": [
"@stdlib/math/base/napi/unary",
"@stdlib/constants/float64/max-safe-nth-fibonacci",
"@stdlib/math/base/special/abs"
"@stdlib/math/base/special/abs",
"@stdlib/math/base/assert/is-integer"
]
},
{
Expand All @@ -53,7 +54,8 @@
"libpath": [],
"dependencies": [
"@stdlib/constants/float64/max-safe-nth-fibonacci",
"@stdlib/math/base/special/abs"
"@stdlib/math/base/special/abs",
"@stdlib/math/base/assert/is-integer"
]
},
{
Expand All @@ -68,7 +70,8 @@
"libpath": [],
"dependencies": [
"@stdlib/constants/float64/max-safe-nth-fibonacci",
"@stdlib/math/base/special/abs"
"@stdlib/math/base/special/abs",
"@stdlib/math/base/assert/is-integer"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
#include "stdlib/math/base/napi/unary.h"
#include<stdint.h>

STDLIB_MATH_BASE_NAPI_MODULE_I_D( stdlib_base_negafibonacci )
STDLIB_MATH_BASE_NAPI_MODULE_D_D( stdlib_base_negafibonacci )
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
* limitations under the License.
*/

#include "stdlib/math/base/assert/is_integer.h"
#include "stdlib/math/base/special/negafibonacci.h"
#include "stdlib/math/base/special/abs.h"
#include "stdlib/constants/float64/max_safe_nth_fibonacci.h"
#include <stdlib.h>

static const double negafibonacci_value[ 79 ] = {
0.0,
Expand Down Expand Up @@ -109,17 +111,17 @@ static const double negafibonacci_value[ 79 ] = {
* @return output value
*
* @example
* double out = stdlib_base_negafibonacci( -1 );
* // returns 1
* double out = stdlib_base_negafibonacci( -1.0 );
* // returns 1.0
*/
double stdlib_base_negafibonacci( const int32_t n ) {
int32_t an;
if ( n > 0 ) {
double stdlib_base_negafibonacci( const double n ) {
double an;
if ( !stdlib_base_is_integer( n ) || n > 0.0 ) {
return 0.0 / 0.0; // NaN
}
an = stdlib_base_abs( n );
if ( an > STDLIB_CONSTANT_FLOAT64_MAX_SAFE_NTH_FIBONACCI ) {
return 0.0 / 0.0; // NaN
}
return negafibonacci_value[ an ];
return negafibonacci_value[ (size_t)an ];
}