Skip to content

Commit 85f91d4

Browse files
committed
refactor: modify C implementation to accept double values
--- 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: na - 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 59f0fbb commit 85f91d4

File tree

7 files changed

+30
-29
lines changed

7 files changed

+30
-29
lines changed

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,19 +191,19 @@ for ( i = 0; i > -79; i-- ) {
191191
Computes the nth [negaFibonacci number][fibonacci-number].
192192

193193
```c
194-
double out = stdlib_base_negafibonacci( 0 );
195-
// returns 0
194+
double out = stdlib_base_negafibonacci( 0.0 );
195+
// returns 0.0
196196

197-
out = stdlib_base_negafibonacci( -1 );
198-
// returns 1
197+
out = stdlib_base_negafibonacci( -1.0 );
198+
// returns 1.0
199199
```
200200

201201
The function accepts the following arguments:
202202

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

205205
```c
206-
double stdlib_base_negafibonacci( const int32_t n );
206+
double stdlib_base_negafibonacci( const double n );
207207
```
208208
209209
</section>
@@ -227,15 +227,14 @@ double stdlib_base_negafibonacci( const int32_t n );
227227
```c
228228
#include "stdlib/math/base/special/negafibonacci.h"
229229
#include <stdio.h>
230-
#include <stdint.h>
231230
232231
int main( void ) {
233-
int32_t i;
232+
double i;
234233
double v;
235234
236-
for ( i = 0; i > -79; i-- ) {
235+
for ( i = 0.0; i > -79.0; i-- ) {
237236
v = stdlib_base_negafibonacci( i );
238-
printf( "negafibonacci(%d) = %lf\n", i, v );
237+
printf( "negafibonacci(%lf) = %lf\n", i, v );
239238
}
240239
}
241240
```

lib/node_modules/@stdlib/math/base/special/negafibonacci/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/negafibonacci/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/negafibonacci.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_negafibonacci( i );
29-
printf( "negafibonacci(%d) = %lf\n", i, v );
28+
printf( "negafibonacci(%lf) = %lf\n", i, v );
3029
}
3130
}

lib/node_modules/@stdlib/math/base/special/negafibonacci/include/stdlib/math/base/special/negafibonacci.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_NEGAFIBONACCI_H
2020
#define STDLIB_MATH_BASE_SPECIAL_NEGAFIBONACCI_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 negaFibonacci number.
3331
*/
34-
double stdlib_base_negafibonacci( const int32_t n );
32+
double stdlib_base_negafibonacci( const double n );
3533

3634
#ifdef __cplusplus
3735
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
"dependencies": [
3939
"@stdlib/math/base/napi/unary",
4040
"@stdlib/constants/float64/max-safe-nth-fibonacci",
41-
"@stdlib/math/base/special/abs"
41+
"@stdlib/math/base/special/abs",
42+
"@stdlib/math/base/assert/is-integer"
4243
]
4344
},
4445
{
@@ -53,7 +54,8 @@
5354
"libpath": [],
5455
"dependencies": [
5556
"@stdlib/constants/float64/max-safe-nth-fibonacci",
56-
"@stdlib/math/base/special/abs"
57+
"@stdlib/math/base/special/abs",
58+
"@stdlib/math/base/assert/is-integer"
5759
]
5860
},
5961
{
@@ -68,7 +70,8 @@
6870
"libpath": [],
6971
"dependencies": [
7072
"@stdlib/constants/float64/max-safe-nth-fibonacci",
71-
"@stdlib/math/base/special/abs"
73+
"@stdlib/math/base/special/abs",
74+
"@stdlib/math/base/assert/is-integer"
7275
]
7376
}
7477
]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
#include "stdlib/math/base/napi/unary.h"
2121
#include<stdint.h>
2222

23-
STDLIB_MATH_BASE_NAPI_MODULE_I_D( stdlib_base_negafibonacci )
23+
STDLIB_MATH_BASE_NAPI_MODULE_D_D( stdlib_base_negafibonacci )

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
* limitations under the License.
1717
*/
1818

19+
#include "stdlib/math/base/assert/is_integer.h"
1920
#include "stdlib/math/base/special/negafibonacci.h"
2021
#include "stdlib/math/base/special/abs.h"
2122
#include "stdlib/constants/float64/max_safe_nth_fibonacci.h"
23+
#include <stdlib.h>
2224

2325
static const double negafibonacci_value[ 79 ] = {
2426
0.0,
@@ -109,17 +111,17 @@ static const double negafibonacci_value[ 79 ] = {
109111
* @return output value
110112
*
111113
* @example
112-
* double out = stdlib_base_negafibonacci( -1 );
113-
* // returns 1
114+
* double out = stdlib_base_negafibonacci( -1.0 );
115+
* // returns 1.0
114116
*/
115-
double stdlib_base_negafibonacci( const int32_t n ) {
116-
int32_t an;
117-
if ( n > 0 ) {
117+
double stdlib_base_negafibonacci( const double n ) {
118+
double an;
119+
if ( !stdlib_base_is_integer( n ) || n > 0.0 ) {
118120
return 0.0 / 0.0; // NaN
119121
}
120122
an = stdlib_base_abs( n );
121123
if ( an > STDLIB_CONSTANT_FLOAT64_MAX_SAFE_NTH_FIBONACCI ) {
122124
return 0.0 / 0.0; // NaN
123125
}
124-
return negafibonacci_value[ an ];
126+
return negafibonacci_value[ (size_t)an ];
125127
}

0 commit comments

Comments
 (0)