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
24 changes: 13 additions & 11 deletions lib/node_modules/@stdlib/math/base/special/nonfibonacci/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,19 @@ for ( i = 1; i < 100; i++ ) {
Computes the nth non-Fibonacci number.

```c
double out = stdlib_base_nonfibonacci( 1 );
// returns 4
double out = stdlib_base_nonfibonacci( 1.0 );
// returns 4.0

out = stdlib_base_nonfibonacci( 2 );
// returns 6
out = stdlib_base_nonfibonacci( 2.0 );
// returns 6.0
```

The function accepts the following arguments:

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

```c
double stdlib_base_nonfibonacci( const int32_t x );
double stdlib_base_nonfibonacci( const double x );
```

</section>
Expand All @@ -190,12 +190,14 @@ double stdlib_base_nonfibonacci( const int32_t x );
```c
#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 );
double i;
double v;

for ( i = 1.0; i < 12.0; i++ ) {
v = stdlib_base_nonfibonacci( i );
printf( "nonfibonacci(%lf) = %lf\n", i, v );
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ static double rand_double( void ) {
*/
static double benchmark( void ) {
double elapsed;
double x[ 100 ];
double t;
double y;
int x[ 100 ];
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = (int)floor( (100.0*rand_double()) + 1.0 );
x[ i ] = floor( (100.0*rand_double()) + 1.0 );
}

t = tic();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
#include <stdio.h>

int main( void ) {
int i;
for ( i = 1; i < 12; i++ ) {
double result = stdlib_base_nonfibonacci( i );
printf( "x: %i => result: %lf\n", i, result );
double i;
double v;

for ( i = 1.0; i < 12.0; i++ ) {
v = stdlib_base_nonfibonacci( i );
printf( "nonfibonacci(%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_NONFIBONACCI_H
#define STDLIB_MATH_BASE_SPECIAL_NONFIBONACCI_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 non-Fibonacci number.
*/
double stdlib_base_nonfibonacci( const int32_t n );
double stdlib_base_nonfibonacci( const double n );

#ifdef __cplusplus
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
"@stdlib/math/base/napi/unary",
"@stdlib/constants/float64/nan",
"@stdlib/math/base/special/floor",
"@stdlib/math/base/special/ln"
"@stdlib/math/base/special/ln",
"@stdlib/math/base/assert/is-integer",
"@stdlib/constants/float64/pinf"
]
},
{
Expand All @@ -55,7 +57,9 @@
"dependencies": [
"@stdlib/constants/float64/nan",
"@stdlib/math/base/special/floor",
"@stdlib/math/base/special/ln"
"@stdlib/math/base/special/ln",
"@stdlib/math/base/assert/is-integer",
"@stdlib/constants/float64/pinf"
]
},
{
Expand All @@ -71,7 +75,9 @@
"dependencies": [
"@stdlib/constants/float64/nan",
"@stdlib/math/base/special/floor",
"@stdlib/math/base/special/ln"
"@stdlib/math/base/special/ln",
"@stdlib/math/base/assert/is-integer",
"@stdlib/constants/float64/pinf"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
#include "stdlib/math/base/special/nonfibonacci.h"
#include "stdlib/math/base/napi/unary.h"

STDLIB_MATH_BASE_NAPI_MODULE_I_D( stdlib_base_nonfibonacci )
STDLIB_MATH_BASE_NAPI_MODULE_D_D( stdlib_base_nonfibonacci )
20 changes: 11 additions & 9 deletions lib/node_modules/@stdlib/math/base/special/nonfibonacci/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
*/

#include "stdlib/math/base/special/nonfibonacci.h"
#include "stdlib/math/base/assert/is_integer.h"
#include "stdlib/constants/float64/nan.h"
#include "stdlib/constants/float64/pinf.h"
#include "stdlib/math/base/special/floor.h"
#include "stdlib/math/base/special/ln.h"
#include <stdint.h>

static const double SQRT5 = 2.23606797749979;
static const double LN_PHI = 0.48121182506;
Expand All @@ -32,31 +33,32 @@ static const double LN_PHI = 0.48121182506;
* @return output value
*
* @example
* double y = stdlib_base_nonfibonacci( 2 );
* double y = stdlib_base_nonfibonacci( 2.0 );
* // returns 6.0
*
* @example
* double y = stdlib_base_nonfibonacci( 1 );
* double y = stdlib_base_nonfibonacci( 1.0 );
* // returns 4.0
*
* @example
* double y = stdlib_base_nonfibonacci( 3 );
* double y = stdlib_base_nonfibonacci( 3.0 );
* // returns 7.0
*
* @example
* double y = stdlib_base_nonfibonacci( -1 );
* double y = stdlib_base_nonfibonacci( -1.0 );
* // returns NaN
*/
double stdlib_base_nonfibonacci( const int32_t n ) {
double stdlib_base_nonfibonacci( const double n ) {
double mut_n;
double a;
double b;
int32_t mut_n = n;

if ( n < 1 ) {
mut_n = n;
if ( !stdlib_base_is_integer( n ) || n == STDLIB_CONSTANT_FLOAT64_PINF || n < 1.0 ) {
return STDLIB_CONSTANT_FLOAT64_NAN;
}

mut_n += 1;
mut_n += 1.0;
a = stdlib_base_ln( mut_n * SQRT5 ) / LN_PHI;
b = stdlib_base_ln( (SQRT5 * (mut_n + a)) - 5.0 + (3.0 / mut_n) ) / LN_PHI;

Expand Down