File tree Expand file tree Collapse file tree 8 files changed +31
-30
lines changed
lib/node_modules/@stdlib/math/base/special/lucas
include/stdlib/math/base/special Expand file tree Collapse file tree 8 files changed +31
-30
lines changed Original file line number Diff line number Diff line change @@ -174,19 +174,19 @@ for ( i = 0; i < 77; i++ ) {
174
174
Computes the nth [ Lucas number] [ lucas-number ] .
175
175
176
176
``` c
177
- double out = stdlib_base_lucas( 0 );
178
- // returns 2
177
+ double out = stdlib_base_lucas( 0.0 );
178
+ // returns 2.0
179
179
180
- out = stdlib_base_lucas( 1 );
181
- // returns 1
180
+ out = stdlib_base_lucas( 1.0 );
181
+ // returns 1.0
182
182
```
183
183
184
184
The function accepts the following arguments:
185
185
186
- - ** n** : ` [in] int32_t ` input value.
186
+ - ** n** : ` [in] double ` input value.
187
187
188
188
``` c
189
- double stdlib_base_lucas ( const int32_t n );
189
+ double stdlib_base_lucas ( const double n );
190
190
```
191
191
192
192
</section>
@@ -210,15 +210,14 @@ double stdlib_base_lucas( const int32_t n );
210
210
```c
211
211
#include "stdlib/math/base/special/lucas.h"
212
212
#include <stdio.h>
213
- #include <stdint.h>
214
213
215
214
int main( void ) {
216
- int32_t i;
215
+ double i;
217
216
double v;
218
217
219
- for ( i = 0; i < 77; i++ ) {
218
+ for ( i = 0.0 ; i < 77.0 ; i++ ) {
220
219
v = stdlib_base_lucas( i );
221
- printf( "lucas(%d ) = %lf\n", i, v );
220
+ printf( "lucas(%lf ) = %lf\n", i, v );
222
221
}
223
222
}
224
223
```
Original file line number Diff line number Diff line change 30
30
/**
31
31
* Prints the TAP version.
32
32
*/
33
- void print_version () {
33
+ static void print_version ( void ) {
34
34
printf ( "TAP version 13\n" );
35
35
}
36
36
@@ -91,14 +91,14 @@ static double rand_double( void ) {
91
91
*/
92
92
static double benchmark ( void ) {
93
93
double elapsed ;
94
- int32_t x ;
94
+ double x ;
95
95
double t ;
96
96
double y ;
97
97
int i ;
98
98
99
99
t = tic ();
100
100
for ( i = 0 ; i < ITERATIONS ; i ++ ) {
101
- x = (int32_t )( 76.0 * rand_double () );
101
+ x = ( 76.0 * rand_double () );
102
102
y = stdlib_base_lucas ( x );
103
103
if ( y != y ) {
104
104
printf ( "should not return NaN\n" );
Original file line number Diff line number Diff line change 18
18
19
19
#include "stdlib/math/base/special/lucas.h"
20
20
#include <stdio.h>
21
- #include <stdint.h>
22
21
23
22
int main ( void ) {
24
- int32_t i ;
23
+ double i ;
25
24
double v ;
26
25
27
- for ( i = 0 ; i < 77 ; i ++ ) {
26
+ for ( i = 0.0 ; i < 77.0 ; i ++ ) {
28
27
v = stdlib_base_lucas ( i );
29
- printf ( "lucas(%d ) = %lf\n" , i , v );
28
+ printf ( "lucas(%lf ) = %lf\n" , i , v );
30
29
}
31
30
}
Original file line number Diff line number Diff line change 19
19
#ifndef STDLIB_MATH_BASE_SPECIAL_LUCAS_H
20
20
#define STDLIB_MATH_BASE_SPECIAL_LUCAS_H
21
21
22
- #include <stdint.h>
23
-
24
22
/*
25
23
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
26
24
*/
@@ -31,7 +29,7 @@ extern "C" {
31
29
/**
32
30
* Computes the nth Lucas number.
33
31
*/
34
- double stdlib_base_lucas ( const int32_t n );
32
+ double stdlib_base_lucas ( const double n );
35
33
36
34
#ifdef __cplusplus
37
35
}
Original file line number Diff line number Diff line change 21
21
// MODULES //
22
22
23
23
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' ) ;
25
25
var MAX_LUCAS = require ( '@stdlib/constants/float64/max-safe-nth-lucas' ) ;
26
26
var LUCAS = require ( './lucas.json' ) ;
27
27
@@ -77,8 +77,7 @@ var LUCAS = require( './lucas.json' );
77
77
function lucas ( n ) {
78
78
if (
79
79
isnan ( n ) ||
80
- isInteger ( n ) === false ||
81
- n < 0 ||
80
+ ! isNonNegativeInteger ( n ) ||
82
81
n > MAX_LUCAS
83
82
) {
84
83
return NaN ;
Original file line number Diff line number Diff line change 37
37
"libpath" : [],
38
38
"dependencies" : [
39
39
" @stdlib/math/base/napi/unary" ,
40
+ " @stdlib/math/base/assert/is-nonnegative-integer" ,
40
41
" @stdlib/constants/float64/max-safe-nth-lucas"
41
42
]
42
43
},
51
52
"libraries" : [],
52
53
"libpath" : [],
53
54
"dependencies" : [
55
+ " @stdlib/math/base/assert/is-nonnegative-integer" ,
54
56
" @stdlib/constants/float64/max-safe-nth-lucas"
55
57
]
56
58
},
65
67
"libraries" : [],
66
68
"libpath" : [],
67
69
"dependencies" : [
70
+ " @stdlib/math/base/assert/is-nonnegative-integer" ,
68
71
" @stdlib/constants/float64/max-safe-nth-lucas"
69
72
]
70
73
}
Original file line number Diff line number Diff line change 19
19
#include "stdlib/math/base/special/lucas.h"
20
20
#include "stdlib/math/base/napi/unary.h"
21
21
22
- STDLIB_MATH_BASE_NAPI_MODULE_I_D ( stdlib_base_lucas )
22
+ STDLIB_MATH_BASE_NAPI_MODULE_D_D ( stdlib_base_lucas )
Original file line number Diff line number Diff line change 17
17
*/
18
18
19
19
#include "stdlib/math/base/special/lucas.h"
20
+ #include "stdlib/math/base/assert/is_nonnegative_integer.h"
20
21
#include "stdlib/constants/float64/max_safe_nth_lucas.h"
22
+ #include <stdint.h>
23
+ #include <stdlib.h>
21
24
22
25
static const int64_t lucas_value [ 77 ] = {
23
26
2 ,
@@ -106,16 +109,16 @@ static const int64_t lucas_value[ 77 ] = {
106
109
* @return output value
107
110
*
108
111
* @example
109
- * double out = stdlib_base_lucas( 1 );
110
- * // returns 1
112
+ * double out = stdlib_base_lucas( 1.0 );
113
+ * // returns 1.0
111
114
*
112
115
* @example
113
- * double out = stdlib_base_lucas( -1 );
116
+ * double out = stdlib_base_lucas( -1.0 );
114
117
* // returns NaN
115
118
*/
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 ) {
118
121
return 0.0 / 0.0 ; // NaN
119
122
}
120
- return lucas_value [ n ];
123
+ return lucas_value [ ( size_t ) n ];
121
124
}
You can’t perform that action at this time.
0 commit comments