Skip to content

Commit a9cb99b

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 0283804 commit a9cb99b

File tree

8 files changed

+30
-29
lines changed

8 files changed

+30
-29
lines changed

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,19 +174,19 @@ for ( i = 0; i < 77; i++ ) {
174174
Computes the nth [Lucas number][lucas-number].
175175

176176
```c
177-
double out = stdlib_base_lucas( 0 );
178-
// returns 2
177+
double out = stdlib_base_lucas( 0.0 );
178+
// returns 2.0
179179

180-
out = stdlib_base_lucas( 1 );
181-
// returns 1
180+
out = stdlib_base_lucas( 1.0 );
181+
// returns 1.0
182182
```
183183

184184
The function accepts the following arguments:
185185

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

188188
```c
189-
double stdlib_base_lucas( const int32_t n );
189+
double stdlib_base_lucas( const double n );
190190
```
191191
192192
</section>
@@ -210,15 +210,14 @@ double stdlib_base_lucas( const int32_t n );
210210
```c
211211
#include "stdlib/math/base/special/lucas.h"
212212
#include <stdio.h>
213-
#include <stdint.h>
214213
215214
int main( void ) {
216-
int32_t i;
215+
double i;
217216
double v;
218217
219-
for ( i = 0; i < 77; i++ ) {
218+
for ( i = 0.0; i < 77.0; i++ ) {
220219
v = stdlib_base_lucas( i );
221-
printf( "lucas(%d) = %lf\n", i, v );
220+
printf( "lucas(%lf) = %lf\n", i, v );
222221
}
223222
}
224223
```

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

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

9999
t = tic();
100100
for ( i = 0; i < ITERATIONS; i++ ) {
101-
x = (int32_t)( 76.0*rand_double() );
101+
x = ( 76.0*rand_double() );
102102
y = stdlib_base_lucas( x );
103103
if ( y != y ) {
104104
printf( "should not return NaN\n" );

lib/node_modules/@stdlib/math/base/special/lucas/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/lucas.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 < 77; i++ ) {
26+
for ( i = 0.0; i < 77.0; i++ ) {
2827
v = stdlib_base_lucas( i );
29-
printf( "lucas(%d) = %lf\n", i, v );
28+
printf( "lucas(%lf) = %lf\n", i, v );
3029
}
3130
}

lib/node_modules/@stdlib/math/base/special/lucas/include/stdlib/math/base/special/lucas.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_LUCAS_H
2020
#define STDLIB_MATH_BASE_SPECIAL_LUCAS_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 Lucas number.
3331
*/
34-
double stdlib_base_lucas( const int32_t n );
32+
double stdlib_base_lucas( const double n );
3533

3634
#ifdef __cplusplus
3735
}

lib/node_modules/@stdlib/math/base/special/lucas/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_LUCAS = require( '@stdlib/constants/float64/max-safe-nth-lucas' );
2626
var LUCAS = require( './lucas.json' );
2727

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

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"libpath": [],
3838
"dependencies": [
3939
"@stdlib/math/base/napi/unary",
40+
"@stdlib/math/base/assert/is-nonnegative-integer",
4041
"@stdlib/constants/float64/max-safe-nth-lucas"
4142
]
4243
},
@@ -51,6 +52,7 @@
5152
"libraries": [],
5253
"libpath": [],
5354
"dependencies": [
55+
"@stdlib/math/base/assert/is-nonnegative-integer",
5456
"@stdlib/constants/float64/max-safe-nth-lucas"
5557
]
5658
},
@@ -65,6 +67,7 @@
6567
"libraries": [],
6668
"libpath": [],
6769
"dependencies": [
70+
"@stdlib/math/base/assert/is-nonnegative-integer",
6871
"@stdlib/constants/float64/max-safe-nth-lucas"
6972
]
7073
}

lib/node_modules/@stdlib/math/base/special/lucas/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/lucas.h"
2020
#include "stdlib/math/base/napi/unary.h"
2121

22-
STDLIB_MATH_BASE_NAPI_MODULE_I_D( stdlib_base_lucas )
22+
STDLIB_MATH_BASE_NAPI_MODULE_D_D( stdlib_base_lucas )

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
*/
1818

1919
#include "stdlib/math/base/special/lucas.h"
20+
#include "stdlib/math/base/assert/is_nonnegative_integer.h"
2021
#include "stdlib/constants/float64/max_safe_nth_lucas.h"
22+
#include <stdint.h>
23+
#include <stdlib.h>
2124

2225
static const int64_t lucas_value[ 77 ] = {
2326
2,
@@ -106,16 +109,16 @@ static const int64_t lucas_value[ 77 ] = {
106109
* @return output value
107110
*
108111
* @example
109-
* double out = stdlib_base_lucas( 1 );
110-
* // returns 1
112+
* double out = stdlib_base_lucas( 1.0 );
113+
* // returns 1.0
111114
*
112115
* @example
113-
* double out = stdlib_base_lucas( -1 );
116+
* double out = stdlib_base_lucas( -1.0 );
114117
* // returns NaN
115118
*/
116-
double stdlib_base_lucas( const int32_t n ) {
117-
if ( n < 0 || n > STDLIB_CONSTANT_FLOAT64_MAX_SAFE_NTH_LUCAS ) {
119+
double stdlib_base_lucas( const double n ) {
120+
if ( !stdlib_base_is_nonnegative_integer( n ) || n > STDLIB_CONSTANT_FLOAT64_MAX_SAFE_NTH_LUCAS ) {
118121
return 0.0 / 0.0; // NaN
119122
}
120-
return lucas_value[ n ];
123+
return lucas_value[ (size_t)n ];
121124
}

0 commit comments

Comments
 (0)