File tree Expand file tree Collapse file tree 7 files changed +30
-29
lines changed
lib/node_modules/@stdlib/math/base/special/negafibonacci
include/stdlib/math/base/special Expand file tree Collapse file tree 7 files changed +30
-29
lines changed Original file line number Diff line number Diff line change @@ -191,19 +191,19 @@ for ( i = 0; i > -79; i-- ) {
191
191
Computes the nth [ negaFibonacci number] [ fibonacci-number ] .
192
192
193
193
``` c
194
- double out = stdlib_base_negafibonacci( 0 );
195
- // returns 0
194
+ double out = stdlib_base_negafibonacci( 0.0 );
195
+ // returns 0.0
196
196
197
- out = stdlib_base_negafibonacci( -1 );
198
- // returns 1
197
+ out = stdlib_base_negafibonacci( -1.0 );
198
+ // returns 1.0
199
199
```
200
200
201
201
The function accepts the following arguments:
202
202
203
- - ** n** : ` [in] int32_t ` input value.
203
+ - ** n** : ` [in] double ` input value.
204
204
205
205
``` c
206
- double stdlib_base_negafibonacci ( const int32_t n );
206
+ double stdlib_base_negafibonacci ( const double n );
207
207
```
208
208
209
209
</section>
@@ -227,15 +227,14 @@ double stdlib_base_negafibonacci( const int32_t n );
227
227
```c
228
228
#include "stdlib/math/base/special/negafibonacci.h"
229
229
#include <stdio.h>
230
- #include <stdint.h>
231
230
232
231
int main( void ) {
233
- int32_t i;
232
+ double i;
234
233
double v;
235
234
236
- for ( i = 0; i > -79; i-- ) {
235
+ for ( i = 0.0 ; i > -79.0 ; i-- ) {
237
236
v = stdlib_base_negafibonacci( i );
238
- printf( "negafibonacci(%d ) = %lf\n", i, v );
237
+ printf( "negafibonacci(%lf ) = %lf\n", i, v );
239
238
}
240
239
}
241
240
```
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/negafibonacci.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_negafibonacci ( i );
29
- printf ( "negafibonacci(%d ) = %lf\n" , i , v );
28
+ printf ( "negafibonacci(%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_NEGAFIBONACCI_H
20
20
#define STDLIB_MATH_BASE_SPECIAL_NEGAFIBONACCI_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 negaFibonacci number.
33
31
*/
34
- double stdlib_base_negafibonacci ( const int32_t n );
32
+ double stdlib_base_negafibonacci ( const double n );
35
33
36
34
#ifdef __cplusplus
37
35
}
Original file line number Diff line number Diff line change 38
38
"dependencies" : [
39
39
" @stdlib/math/base/napi/unary" ,
40
40
" @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"
42
43
]
43
44
},
44
45
{
53
54
"libpath" : [],
54
55
"dependencies" : [
55
56
" @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"
57
59
]
58
60
},
59
61
{
68
70
"libpath" : [],
69
71
"dependencies" : [
70
72
" @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"
72
75
]
73
76
}
74
77
]
Original file line number Diff line number Diff line change 20
20
#include "stdlib/math/base/napi/unary.h"
21
21
#include <stdint.h>
22
22
23
- STDLIB_MATH_BASE_NAPI_MODULE_I_D ( stdlib_base_negafibonacci )
23
+ STDLIB_MATH_BASE_NAPI_MODULE_D_D ( stdlib_base_negafibonacci )
Original file line number Diff line number Diff line change 16
16
* limitations under the License.
17
17
*/
18
18
19
+ #include "stdlib/math/base/assert/is_integer.h"
19
20
#include "stdlib/math/base/special/negafibonacci.h"
20
21
#include "stdlib/math/base/special/abs.h"
21
22
#include "stdlib/constants/float64/max_safe_nth_fibonacci.h"
23
+ #include <stdlib.h>
22
24
23
25
static const double negafibonacci_value [ 79 ] = {
24
26
0.0 ,
@@ -109,17 +111,17 @@ static const double negafibonacci_value[ 79 ] = {
109
111
* @return output value
110
112
*
111
113
* @example
112
- * double out = stdlib_base_negafibonacci( -1 );
113
- * // returns 1
114
+ * double out = stdlib_base_negafibonacci( -1.0 );
115
+ * // returns 1.0
114
116
*/
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 ) {
118
120
return 0.0 / 0.0 ; // NaN
119
121
}
120
122
an = stdlib_base_abs ( n );
121
123
if ( an > STDLIB_CONSTANT_FLOAT64_MAX_SAFE_NTH_FIBONACCI ) {
122
124
return 0.0 / 0.0 ; // NaN
123
125
}
124
- return negafibonacci_value [ an ];
126
+ return negafibonacci_value [ ( size_t ) an ];
125
127
}
You can’t perform that action at this time.
0 commit comments