Skip to content

Commit 5422b20

Browse files
author
aayush0325
committed
feat: c files added
1 parent 3ddc39e commit 5422b20

File tree

3 files changed

+214
-0
lines changed

3 files changed

+214
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
/**
22+
* Compute the nth non-Fibonacci number in single-precision floating-point format.
23+
*
24+
* @module @stdlib/math/base/special/nonfibonaccif
25+
*
26+
* @example
27+
* var nonfibonaccif = require( '@stdlib/math/base/special/nonfibonaccif' );
28+
*
29+
* var v = nonfibonaccif( 1 );
30+
* // returns 4
31+
*
32+
* v = nonfibonaccif( 2 );
33+
* // returns 6
34+
*
35+
* v = nonfibonaccif( 3 );
36+
* // returns 7
37+
*/
38+
39+
// MODULES //
40+
41+
var main = require( './main.js' );
42+
43+
44+
// EXPORTS //
45+
46+
module.exports = main;
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
24+
var isIntegerf = require( '@stdlib/math/base/assert/is-integerf' );
25+
var lnf = require( '@stdlib/math/base/special/lnf' );
26+
var floorf = require( '@stdlib/math/base/special/floorf' );
27+
var PHI = require( '@stdlib/constants/float32/phi' );
28+
var PINF = require( '@stdlib/constants/float32/pinf' );
29+
30+
31+
// VARIABLES //
32+
33+
var SQRT_5 = 2.23606797749979;
34+
var LN_PHI = lnf( PHI );
35+
36+
37+
// MAIN //
38+
39+
/**
40+
* Computes the nth non-Fibonacci number.
41+
*
42+
* ## References
43+
*
44+
* - Gould, H.W. 1965. "Non-Fibonacci Numbers." _Fibonacci Quarterly_, no. 3: 177–83. <http://www.fq.math.ca/Scanned/3-3/gould.pdf>.
45+
* - Farhi, Bakir. 2011. "An explicit formula generating the non-Fibonacci numbers." _arXiv_ abs/1105.1127 \[Math.NT\] (May): 1–5. <https://arxiv.org/abs/1105.1127>.
46+
*
47+
* @param {NonNegativeInteger} n - the non-Fibonacci number to compute
48+
* @returns {NonNegativeInteger} non-Fibonacci number
49+
*
50+
* @example
51+
* var v = nonfibonaccif( 1 );
52+
* // returns 4
53+
*
54+
* @example
55+
* var v = nonfibonaccif( 2 );
56+
* // returns 6
57+
*
58+
* @example
59+
* var v = nonfibonaccif( 3 );
60+
* // returns 7
61+
*
62+
* @example
63+
* var v = nonfibonaccif( NaN );
64+
* // returns NaN
65+
*
66+
* @example
67+
* var v = nonfibonaccif( 3.14 );
68+
* // returns NaN
69+
*
70+
* @example
71+
* var v = nonfibonaccif( -1 );
72+
* // returns NaN
73+
*/
74+
function nonfibonaccif( n ) {
75+
var a;
76+
var b;
77+
if (
78+
isnanf( n ) ||
79+
isIntegerf( n ) === false ||
80+
n < 1 ||
81+
n === PINF
82+
) {
83+
return NaN;
84+
}
85+
n += 1;
86+
a = lnf( n * SQRT_5 ) / LN_PHI;
87+
b = lnf( ( SQRT_5 * ( n + a ) ) - 5.0 + ( 3.0 / n ) ) / LN_PHI;
88+
return floorf( n + b - 2.0 );
89+
}
90+
91+
92+
// EXPORTS //
93+
94+
module.exports = nonfibonaccif;
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var isIntegerf = require( '@stdlib/math/base/assert/is-integerf' );
24+
var addon = require( './../src/addon.node' );
25+
26+
27+
// MAIN //
28+
29+
/**
30+
* Computes the nth non-Fibonacci number.
31+
*
32+
* ## References
33+
*
34+
* - Gould, H.W. 1965. "Non-Fibonacci Numbers." _Fibonacci Quarterly_, no. 3: 177–83. <http://www.fq.math.ca/Scanned/3-3/gould.pdf>.
35+
* - Farhi, Bakir. 2011. "An explicit formula generating the non-Fibonacci numbers." _arXiv_ abs/1105.1127 \[Math.NT\] (May): 1–5. <https://arxiv.org/abs/1105.1127>.
36+
*
37+
* @param {NonNegativeInteger} n - the non-Fibonacci number to compute
38+
* @returns {NonNegativeInteger} non-Fibonacci number
39+
*
40+
* @example
41+
* var v = nonfibonaccif( 1 );
42+
* // returns 4
43+
*
44+
* @example
45+
* var v = nonfibonaccif( 2 );
46+
* // returns 6
47+
*
48+
* @example
49+
* var v = nonfibonaccif( 3 );
50+
* // returns 7
51+
*
52+
* @example
53+
* var v = nonfibonaccif( NaN );
54+
* // returns NaN
55+
*
56+
* @example
57+
* var v = nonfibonaccif( 3.14 );
58+
* // returns NaN
59+
*
60+
* @example
61+
* var v = nonfibonaccif( -1 );
62+
* // returns NaN
63+
*/
64+
function nonfibonaccif( n ) {
65+
if ( isIntegerf( n ) === false ) {
66+
return NaN;
67+
}
68+
return addon( n );
69+
}
70+
71+
72+
// EXPORTS //
73+
74+
module.exports = nonfibonaccif;

0 commit comments

Comments
 (0)