Skip to content

Commit e053444

Browse files
committed
refactor: modify C implementation to accept double
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 5ef479c commit e053444

File tree

8 files changed

+27
-27
lines changed

8 files changed

+27
-27
lines changed

lib/node_modules/@stdlib/math/base/special/fibonacci/README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@ out = stdlib_base_fibonacci( 1 );
185185

186186
The function accepts the following arguments:
187187

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

190190
```c
191-
double stdlib_base_fibonacci( const int32_t n );
191+
double stdlib_base_fibonacci( const double n );
192192
```
193193
194194
</section>
@@ -212,15 +212,14 @@ double stdlib_base_fibonacci( const int32_t n );
212212
```c
213213
#include "stdlib/math/base/special/fibonacci.h"
214214
#include <stdio.h>
215-
#include <stdint.h>
216215
217216
int main( void ) {
218-
int32_t i;
217+
double i;
219218
double v;
220219
221-
for ( i = 0; i < 79; i++ ) {
220+
for ( i = 0.0; i < 79.0; i++ ) {
222221
v = stdlib_base_fibonacci( i );
223-
printf( "fibonacci(%d) = %lf\n", i, v );
222+
printf( "fibonacci(%lf) = %lf\n", i, v );
224223
}
225224
}
226225
```

lib/node_modules/@stdlib/math/base/special/fibonacci/benchmark/c/native/benchmark.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ static double rand_double( void ) {
9191
*/
9292
static double benchmark( void ) {
9393
double elapsed;
94-
int32_t x[ 100 ];
94+
double x[ 100 ];
9595
double t;
9696
double y;
9797
int i;
9898

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

103103
t = tic();

lib/node_modules/@stdlib/math/base/special/fibonacci/examples/c/example.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@
1818

1919
#include "stdlib/math/base/special/fibonacci.h"
2020
#include <stdio.h>
21-
#include <stdint.h>
2221

2322
int main( void ) {
24-
int32_t i;
23+
double i;
2524
double v;
2625

27-
for ( i = 0; i < 79; i++ ) {
26+
for ( i = 0.0; i < 79.0; i++ ) {
2827
v = stdlib_base_fibonacci( i );
29-
printf( "fibonacci(%d) = %lf\n", i, v );
28+
printf( "fibonacci(%lf) = %lf\n", i, v );
3029
}
3130
}

lib/node_modules/@stdlib/math/base/special/fibonacci/include/stdlib/math/base/special/fibonacci.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
#ifndef STDLIB_MATH_BASE_SPECIAL_FIBONACCI_H
2020
#define STDLIB_MATH_BASE_SPECIAL_FIBONACCI_H
2121

22-
#include <stdint.h>
23-
2422
/*
2523
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
2624
*/
@@ -31,7 +29,7 @@ extern "C" {
3129
/**
3230
* Computes the nth Fibonacci number.
3331
*/
34-
double stdlib_base_fibonacci( const int32_t n );
32+
double stdlib_base_fibonacci( const double n );
3533

3634
#ifdef __cplusplus
3735
}

lib/node_modules/@stdlib/math/base/special/fibonacci/lib/main.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// MODULES //
2222

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

@@ -77,8 +77,7 @@ var FIBONACCI = require( './fibonacci.json' );
7777
function fibonacci( n ) {
7878
if (
7979
isnan( n ) ||
80-
isInteger( n ) === false ||
81-
n < 0 ||
80+
!isNonnegativeInteger( n ) ||
8281
n > MAX_FIBONACCI
8382
) {
8483
return NaN;

lib/node_modules/@stdlib/math/base/special/fibonacci/manifest.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"libpath": [],
3838
"dependencies": [
3939
"@stdlib/math/base/napi/unary",
40-
"@stdlib/constants/float64/max-safe-nth-fibonacci"
40+
"@stdlib/constants/float64/max-safe-nth-fibonacci",
41+
"@stdlib/math/base/assert/is-nonnegative-integer"
4142
]
4243
},
4344
{
@@ -51,7 +52,8 @@
5152
"libraries": [],
5253
"libpath": [],
5354
"dependencies": [
54-
"@stdlib/constants/float64/max-safe-nth-fibonacci"
55+
"@stdlib/constants/float64/max-safe-nth-fibonacci",
56+
"@stdlib/math/base/assert/is-nonnegative-integer"
5557
]
5658
},
5759
{
@@ -65,7 +67,8 @@
6567
"libraries": [],
6668
"libpath": [],
6769
"dependencies": [
68-
"@stdlib/constants/float64/max-safe-nth-fibonacci"
70+
"@stdlib/constants/float64/max-safe-nth-fibonacci",
71+
"@stdlib/math/base/assert/is-nonnegative-integer"
6972
]
7073
}
7174
]

lib/node_modules/@stdlib/math/base/special/fibonacci/src/addon.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919
#include "stdlib/math/base/special/fibonacci.h"
2020
#include "stdlib/math/base/napi/unary.h"
2121

22-
STDLIB_MATH_BASE_NAPI_MODULE_I_D( stdlib_base_fibonacci )
22+
STDLIB_MATH_BASE_NAPI_MODULE_D_D( stdlib_base_fibonacci )

lib/node_modules/@stdlib/math/base/special/fibonacci/src/main.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
#include "stdlib/math/base/special/fibonacci.h"
2020
#include "stdlib/constants/float64/max_safe_nth_fibonacci.h"
21+
#include "stdlib/math/base/assert/is_nonnegative_integer.h"
22+
#include <stdint.h>
2123

2224
static const int64_t fibonacci_value[ 79 ] = {
2325
0,
@@ -108,12 +110,12 @@ static const int64_t fibonacci_value[ 79 ] = {
108110
* @return output value
109111
*
110112
* @example
111-
* double out = stdlib_base_fibonacci( 1 );
112-
* // returns 1
113+
* double out = stdlib_base_fibonacci( 1.0 );
114+
* // returns 1.0
113115
*/
114-
double stdlib_base_fibonacci( const int32_t n ) {
115-
if ( n < 0 || n > STDLIB_CONSTANT_FLOAT64_MAX_SAFE_NTH_FIBONACCI ) {
116+
double stdlib_base_fibonacci( const double n ) {
117+
if ( !stdlib_base_is_nonnegative_integer( n ) || n > STDLIB_CONSTANT_FLOAT64_MAX_SAFE_NTH_FIBONACCI ) {
116118
return 0.0 / 0.0; // NaN
117119
}
118-
return fibonacci_value[ n ];
120+
return fibonacci_value[ (int8_t)n ];
119121
}

0 commit comments

Comments
 (0)