Skip to content

Commit c888997

Browse files
gururaj1512stdlib-botanandkaranubc
authored
feat: add math/base/special/negafibonaccif
PR-URL: #4939 Ref: #649 Signed-off-by: Gururaj Gurram <[email protected]> Co-authored-by: stdlib-bot <[email protected]> Co-authored-by: Karan Anand <[email protected]> Reviewed-by: Shabareesh Shetty <[email protected]> Reviewed-by: Karan Anand <[email protected]>
1 parent 5cc3bbe commit c888997

29 files changed

+2729
-0
lines changed
Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# negaFibonaccif
22+
23+
> Compute the nth [negaFibonacci number][fibonacci-number] as a [single-precision floating-point number][ieee754].
24+
25+
<section class="intro">
26+
27+
The [negaFibonacci numbers][fibonacci-number] are the integer sequence
28+
29+
<!-- <equation class="equation" label="eq:negafibonacci_sequence" align="center" raw="0, 1, -1, 2, -3, 5, -8, 13, -21, 34, -55, 89, -144, \ldots" alt="NegaFibonacci sequence"> -->
30+
31+
```math
32+
0, 1, -1, 2, -3, 5, -8, 13, -21, 34, -55, 89, -144, \ldots
33+
```
34+
35+
<!-- </equation> -->
36+
37+
The sequence is defined by the recurrence relation
38+
39+
<!-- <equation class="equation" label="eq:negafibonacci_recurrence_relation" align="center" raw="F_{n-2} = F_{n} - F_{n-1}" alt="NegaFibonacci sequence recurrence relation"> -->
40+
41+
```math
42+
F_{n-2} = F_{n} - F_{n-1}
43+
```
44+
45+
<!-- </equation> -->
46+
47+
which yields
48+
49+
<!-- <equation class="equation" label="eq:negafibonacci_fibonacci" align="center" raw="F_{-n} = (-1)^{n+1} F_n" alt="NegaFibonacci relationship to Fibonacci numbers"> -->
50+
51+
```math
52+
F_{-n} = (-1)^{n+1} F_n
53+
```
54+
55+
<!-- </equation> -->
56+
57+
with seed values `F_0 = 0` and `F_{-1} = 1`.
58+
59+
</section>
60+
61+
<!-- /.intro -->
62+
63+
<section class="usage">
64+
65+
## Usage
66+
67+
```javascript
68+
var negafibonaccif = require( '@stdlib/math/base/special/negafibonaccif' );
69+
```
70+
71+
#### negafibonaccif( n )
72+
73+
Computes the nth [negaFibonacci number][fibonacci-number] as a [single-precision floating-point number][ieee754].
74+
75+
```javascript
76+
var v = negafibonaccif( 0 );
77+
// returns 0
78+
79+
v = negafibonaccif( -1 );
80+
// returns 1
81+
82+
v = negafibonaccif( -2 );
83+
// returns -1
84+
85+
v = negafibonaccif( -3 );
86+
// returns 2
87+
88+
v = negafibonaccif( -36 );
89+
// returns -14930352
90+
```
91+
92+
If `n < -36`, the function returns `NaN`, as larger [negaFibonacci numbers][fibonacci-number] cannot be safely represented in [single-precision floating-point format][ieee754].
93+
94+
```javascript
95+
var v = negafibonaccif( -37 );
96+
// returns NaN
97+
```
98+
99+
If not provided a nonpositive integer value, the function returns `NaN`.
100+
101+
```javascript
102+
var v = negafibonaccif( -3.14 );
103+
// returns NaN
104+
105+
v = negafibonaccif( 1 );
106+
// returns NaN
107+
```
108+
109+
If provided `NaN`, the function returns `NaN`.
110+
111+
```javascript
112+
var v = negafibonaccif( NaN );
113+
// returns NaN
114+
```
115+
116+
</section>
117+
118+
<!-- /.usage -->
119+
120+
<section class="notes">
121+
122+
</section>
123+
124+
<!-- /.notes -->
125+
126+
<section class="examples">
127+
128+
## Examples
129+
130+
<!-- eslint no-undef: "error" -->
131+
132+
```javascript
133+
var logEachMap = require( '@stdlib/console/log-each-map' );
134+
var linspace = require( '@stdlib/array/base/linspace' );
135+
var negafibonaccif = require( '@stdlib/math/base/special/negafibonaccif' );
136+
137+
var v = linspace( -36, 0, 37 );
138+
139+
logEachMap( 'negafibonaccif(%d) = %0.4f', v, negafibonaccif );
140+
```
141+
142+
</section>
143+
144+
<!-- /.examples -->
145+
146+
<!-- C interface documentation. -->
147+
148+
* * *
149+
150+
<section class="c">
151+
152+
## C APIs
153+
154+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
155+
156+
<section class="intro">
157+
158+
</section>
159+
160+
<!-- /.intro -->
161+
162+
<!-- C usage documentation. -->
163+
164+
<section class="usage">
165+
166+
### Usage
167+
168+
```c
169+
#include "stdlib/math/base/special/negafibonaccif.h"
170+
```
171+
172+
#### stdlib_base_negafibonaccif( n )
173+
174+
Computes the nth [negaFibonacci number][fibonacci-number] as a [single-precision floating-point number][ieee754].
175+
176+
```c
177+
float out = stdlib_base_negafibonaccif( 0 );
178+
// returns 0.0f
179+
180+
out = stdlib_base_negafibonaccif( -1 );
181+
// returns 1.0f
182+
```
183+
184+
The function accepts the following arguments:
185+
186+
- **n**: `[in] int32_t` input value.
187+
188+
```c
189+
float stdlib_base_negafibonaccif( const int32_t n );
190+
```
191+
192+
</section>
193+
194+
<!-- /.usage -->
195+
196+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
197+
198+
<section class="notes">
199+
200+
</section>
201+
202+
<!-- /.notes -->
203+
204+
<!-- C API usage examples. -->
205+
206+
<section class="examples">
207+
208+
### Examples
209+
210+
```c
211+
#include "stdlib/math/base/special/negafibonaccif.h"
212+
#include <stdio.h>
213+
#include <stdint.h>
214+
215+
int main( void ) {
216+
int32_t i;
217+
float v;
218+
219+
for ( i = 0; i > -37; i-- ) {
220+
v = stdlib_base_negafibonaccif( i );
221+
printf( "negafibonaccif(%d) = %f\n", i, v );
222+
}
223+
}
224+
```
225+
226+
</section>
227+
228+
<!-- /.examples -->
229+
230+
</section>
231+
232+
<!-- /.c -->
233+
234+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
235+
236+
<section class="related">
237+
238+
</section>
239+
240+
<!-- /.related -->
241+
242+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
243+
244+
<section class="links">
245+
246+
[fibonacci-number]: https://en.wikipedia.org/wiki/Fibonacci_number
247+
248+
[ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985
249+
250+
<!-- <related-links> -->
251+
252+
<!-- </related-links> -->
253+
254+
</section>
255+
256+
<!-- /.links -->

0 commit comments

Comments
 (0)