File tree Expand file tree Collapse file tree 7 files changed +43
-33
lines changed
lib/node_modules/@stdlib/math/base/special/nonfibonacci
include/stdlib/math/base/special Expand file tree Collapse file tree 7 files changed +43
-33
lines changed Original file line number Diff line number Diff line change @@ -154,19 +154,19 @@ for ( i = 1; i < 100; i++ ) {
154
154
Computes the nth non-Fibonacci number.
155
155
156
156
``` c
157
- double out = stdlib_base_nonfibonacci( 1 );
158
- // returns 4
157
+ double out = stdlib_base_nonfibonacci( 1.0 );
158
+ // returns 4.0
159
159
160
- out = stdlib_base_nonfibonacci( 2 );
161
- // returns 6
160
+ out = stdlib_base_nonfibonacci( 2.0 );
161
+ // returns 6.0
162
162
```
163
163
164
164
The function accepts the following arguments:
165
165
166
- - ** x** : ` [in] int32_t ` input value.
166
+ - ** x** : ` [in] double ` input value.
167
167
168
168
``` c
169
- double stdlib_base_nonfibonacci ( const int32_t x );
169
+ double stdlib_base_nonfibonacci ( const double x );
170
170
```
171
171
172
172
</section>
@@ -190,12 +190,14 @@ double stdlib_base_nonfibonacci( const int32_t x );
190
190
```c
191
191
#include "stdlib/math/base/special/nonfibonacci.h"
192
192
#include <stdio.h>
193
- #include <stdlib.h>
193
+
194
194
int main( void ) {
195
- int i;
196
- for ( i = 1; i < 12; i++ ) {
197
- double result = stdlib_base_nonfibonacci( i );
198
- printf( "x: %i => result: %lf", i, result );
195
+ double i;
196
+ double v;
197
+
198
+ for ( i = 1.0; i < 12.0; i++ ) {
199
+ v = stdlib_base_nonfibonacci( i );
200
+ printf( "nonfibonacci(%lf) = %lf\n", i, v );
199
201
}
200
202
}
201
203
```
Original file line number Diff line number Diff line change @@ -90,13 +90,13 @@ static double rand_double( void ) {
90
90
*/
91
91
static double benchmark ( void ) {
92
92
double elapsed ;
93
+ double x [ 100 ];
93
94
double t ;
94
95
double y ;
95
- int x [ 100 ];
96
96
int i ;
97
97
98
98
for ( i = 0 ; i < 100 ; i ++ ) {
99
- x [ i ] = ( int ) floor ( (100.0 * rand_double ()) + 1.0 );
99
+ x [ i ] = floor ( (100.0 * rand_double ()) + 1.0 );
100
100
}
101
101
102
102
t = tic ();
Original file line number Diff line number Diff line change 20
20
#include <stdio.h>
21
21
22
22
int main ( void ) {
23
- int i ;
24
- for ( i = 1 ; i < 12 ; i ++ ) {
25
- double result = stdlib_base_nonfibonacci ( i );
26
- printf ( "x: %i => result: %lf\n" , i , result );
23
+ double i ;
24
+ double v ;
25
+
26
+ for ( i = 1.0 ; i < 12.0 ; i ++ ) {
27
+ v = stdlib_base_nonfibonacci ( i );
28
+ printf ( "nonfibonacci(%lf) = %lf\n" , i , v );
27
29
}
28
30
}
Original file line number Diff line number Diff line change 19
19
#ifndef STDLIB_MATH_BASE_SPECIAL_NONFIBONACCI_H
20
20
#define STDLIB_MATH_BASE_SPECIAL_NONFIBONACCI_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 non-Fibonacci number.
33
31
*/
34
- double stdlib_base_nonfibonacci ( const int32_t n );
32
+ double stdlib_base_nonfibonacci ( const double n );
35
33
36
34
#ifdef __cplusplus
37
35
}
Original file line number Diff line number Diff line change 39
39
" @stdlib/math/base/napi/unary" ,
40
40
" @stdlib/constants/float64/nan" ,
41
41
" @stdlib/math/base/special/floor" ,
42
- " @stdlib/math/base/special/ln"
42
+ " @stdlib/math/base/special/ln" ,
43
+ " @stdlib/math/base/assert/is-integer" ,
44
+ " @stdlib/constants/float64/pinf"
43
45
]
44
46
},
45
47
{
55
57
"dependencies" : [
56
58
" @stdlib/constants/float64/nan" ,
57
59
" @stdlib/math/base/special/floor" ,
58
- " @stdlib/math/base/special/ln"
60
+ " @stdlib/math/base/special/ln" ,
61
+ " @stdlib/math/base/assert/is-integer" ,
62
+ " @stdlib/constants/float64/pinf"
59
63
]
60
64
},
61
65
{
71
75
"dependencies" : [
72
76
" @stdlib/constants/float64/nan" ,
73
77
" @stdlib/math/base/special/floor" ,
74
- " @stdlib/math/base/special/ln"
78
+ " @stdlib/math/base/special/ln" ,
79
+ " @stdlib/math/base/assert/is-integer" ,
80
+ " @stdlib/constants/float64/pinf"
75
81
]
76
82
}
77
83
]
Original file line number Diff line number Diff line change 19
19
#include "stdlib/math/base/special/nonfibonacci.h"
20
20
#include "stdlib/math/base/napi/unary.h"
21
21
22
- STDLIB_MATH_BASE_NAPI_MODULE_I_D ( stdlib_base_nonfibonacci )
22
+ STDLIB_MATH_BASE_NAPI_MODULE_D_D ( stdlib_base_nonfibonacci )
Original file line number Diff line number Diff line change 17
17
*/
18
18
19
19
#include "stdlib/math/base/special/nonfibonacci.h"
20
+ #include "stdlib/math/base/assert/is_integer.h"
20
21
#include "stdlib/constants/float64/nan.h"
22
+ #include "stdlib/constants/float64/pinf.h"
21
23
#include "stdlib/math/base/special/floor.h"
22
24
#include "stdlib/math/base/special/ln.h"
23
- #include <stdint.h>
24
25
25
26
static const double SQRT5 = 2.23606797749979 ;
26
27
static const double LN_PHI = 0.48121182506 ;
@@ -32,31 +33,32 @@ static const double LN_PHI = 0.48121182506;
32
33
* @return output value
33
34
*
34
35
* @example
35
- * double y = stdlib_base_nonfibonacci( 2 );
36
+ * double y = stdlib_base_nonfibonacci( 2.0 );
36
37
* // returns 6.0
37
38
*
38
39
* @example
39
- * double y = stdlib_base_nonfibonacci( 1 );
40
+ * double y = stdlib_base_nonfibonacci( 1.0 );
40
41
* // returns 4.0
41
42
*
42
43
* @example
43
- * double y = stdlib_base_nonfibonacci( 3 );
44
+ * double y = stdlib_base_nonfibonacci( 3.0 );
44
45
* // returns 7.0
45
46
*
46
47
* @example
47
- * double y = stdlib_base_nonfibonacci( -1 );
48
+ * double y = stdlib_base_nonfibonacci( -1.0 );
48
49
* // returns NaN
49
50
*/
50
- double stdlib_base_nonfibonacci ( const int32_t n ) {
51
+ double stdlib_base_nonfibonacci ( const double n ) {
52
+ double mut_n ;
51
53
double a ;
52
54
double b ;
53
- int32_t mut_n = n ;
54
55
55
- if ( n < 1 ) {
56
+ mut_n = n ;
57
+ if ( !stdlib_base_is_integer ( n ) || n == STDLIB_CONSTANT_FLOAT64_PINF || n < 1.0 ) {
56
58
return STDLIB_CONSTANT_FLOAT64_NAN ;
57
59
}
58
60
59
- mut_n += 1 ;
61
+ mut_n += 1.0 ;
60
62
a = stdlib_base_ln ( mut_n * SQRT5 ) / LN_PHI ;
61
63
b = stdlib_base_ln ( (SQRT5 * (mut_n + a )) - 5.0 + (3.0 / mut_n ) ) / LN_PHI ;
62
64
You can’t perform that action at this time.
0 commit comments