File tree Expand file tree Collapse file tree 8 files changed +28
-27
lines changed
lib/node_modules/@stdlib/math/base/special/fibonacci
include/stdlib/math/base/special Expand file tree Collapse file tree 8 files changed +28
-27
lines changed Original file line number Diff line number Diff line change @@ -185,10 +185,10 @@ out = stdlib_base_fibonacci( 1 );
185
185
186
186
The function accepts the following arguments:
187
187
188
- - ** n** : ` [in] int32_t ` input value.
188
+ - ** n** : ` [in] double ` input value.
189
189
190
190
``` c
191
- double stdlib_base_fibonacci ( const int32_t n );
191
+ double stdlib_base_fibonacci ( const double n );
192
192
```
193
193
194
194
</section>
@@ -212,15 +212,14 @@ double stdlib_base_fibonacci( const int32_t n );
212
212
```c
213
213
#include "stdlib/math/base/special/fibonacci.h"
214
214
#include <stdio.h>
215
- #include <stdint.h>
216
215
217
216
int main( void ) {
218
- int32_t i;
217
+ double i;
219
218
double v;
220
219
221
- for ( i = 0; i < 79; i++ ) {
220
+ for ( i = 0.0 ; i < 79.0 ; i++ ) {
222
221
v = stdlib_base_fibonacci( i );
223
- printf( "fibonacci(%d ) = %lf\n", i, v );
222
+ printf( "fibonacci(%lf ) = %lf\n", i, v );
224
223
}
225
224
}
226
225
```
Original file line number Diff line number Diff line change @@ -91,13 +91,13 @@ static double rand_double( void ) {
91
91
*/
92
92
static double benchmark ( void ) {
93
93
double elapsed ;
94
- int32_t x [ 100 ];
94
+ double x [ 100 ];
95
95
double t ;
96
96
double y ;
97
97
int i ;
98
98
99
99
for ( i = 0 ; i < 100 ; i ++ ) {
100
- x [ i ] = ( int32_t ) floor ( 40.0 * rand_double () );
100
+ x [ i ] = floor ( 40.0 * rand_double () );
101
101
}
102
102
103
103
t = tic ();
Original file line number Diff line number Diff line change 18
18
19
19
#include "stdlib/math/base/special/fibonacci.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 < 79 ; i ++ ) {
26
+ for ( i = 0.0 ; i < 79.0 ; i ++ ) {
28
27
v = stdlib_base_fibonacci ( i );
29
- printf ( "fibonacci(%d ) = %lf\n" , i , v );
28
+ printf ( "fibonacci(%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_FIBONACCI_H
20
20
#define STDLIB_MATH_BASE_SPECIAL_FIBONACCI_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 Fibonacci number.
33
31
*/
34
- double stdlib_base_fibonacci ( const int32_t n );
32
+ double stdlib_base_fibonacci ( 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_FIBONACCI = require ( '@stdlib/constants/float64/max-safe-nth-fibonacci' ) ;
26
26
var FIBONACCI = require ( './fibonacci.json' ) ;
27
27
@@ -77,8 +77,7 @@ var FIBONACCI = require( './fibonacci.json' );
77
77
function fibonacci ( n ) {
78
78
if (
79
79
isnan ( n ) ||
80
- isInteger ( n ) === false ||
81
- n < 0 ||
80
+ ! isNonnegativeInteger ( n ) ||
82
81
n > MAX_FIBONACCI
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/constants/float64/max-safe-nth-fibonacci"
40
+ " @stdlib/constants/float64/max-safe-nth-fibonacci" ,
41
+ " @stdlib/math/base/assert/is-nonnegative-integer"
41
42
]
42
43
},
43
44
{
51
52
"libraries" : [],
52
53
"libpath" : [],
53
54
"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"
55
57
]
56
58
},
57
59
{
65
67
"libraries" : [],
66
68
"libpath" : [],
67
69
"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"
69
72
]
70
73
}
71
74
]
Original file line number Diff line number Diff line change 19
19
#include "stdlib/math/base/special/fibonacci.h"
20
20
#include "stdlib/math/base/napi/unary.h"
21
21
22
- STDLIB_MATH_BASE_NAPI_MODULE_I_D ( stdlib_base_fibonacci )
22
+ STDLIB_MATH_BASE_NAPI_MODULE_D_D ( stdlib_base_fibonacci )
Original file line number Diff line number Diff line change 18
18
19
19
#include "stdlib/math/base/special/fibonacci.h"
20
20
#include "stdlib/constants/float64/max_safe_nth_fibonacci.h"
21
+ #include "stdlib/math/base/assert/is_nonnegative_integer.h"
22
+ #include <stdint.h>
23
+ #include <stdlib.h>
21
24
22
25
static const int64_t fibonacci_value [ 79 ] = {
23
26
0 ,
@@ -108,12 +111,12 @@ static const int64_t fibonacci_value[ 79 ] = {
108
111
* @return output value
109
112
*
110
113
* @example
111
- * double out = stdlib_base_fibonacci( 1 );
112
- * // returns 1
114
+ * double out = stdlib_base_fibonacci( 1.0 );
115
+ * // returns 1.0
113
116
*/
114
- double stdlib_base_fibonacci ( const int32_t n ) {
115
- if ( n < 0 || n > STDLIB_CONSTANT_FLOAT64_MAX_SAFE_NTH_FIBONACCI ) {
117
+ double stdlib_base_fibonacci ( const double n ) {
118
+ if ( ! stdlib_base_is_nonnegative_integer ( n ) || n > STDLIB_CONSTANT_FLOAT64_MAX_SAFE_NTH_FIBONACCI ) {
116
119
return 0.0 / 0.0 ; // NaN
117
120
}
118
- return fibonacci_value [ n ];
121
+ return fibonacci_value [ ( size_t ) n ];
119
122
}
You can’t perform that action at this time.
0 commit comments