Skip to content

Commit 7edf42c

Browse files
committed
feat: add math/base/special/negafibonaccif
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na ---
1 parent 611fed3 commit 7edf42c

32 files changed

+2880
-0
lines changed
Lines changed: 273 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,273 @@
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.
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+
<!-- <div class="equation" align="center" data-raw-text="0, 1, -1, 2, -3, 5, -8, 13, -21, 34, -55, 89, -144, \ldots" data-equation="eq:negafibonacci_sequence">
36+
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/negafibonacci/docs/img/equation_negafibonacci_sequence.svg" alt="NegaFibonacci sequence">
37+
<br>
38+
</div> -->
39+
40+
<!-- </equation> -->
41+
42+
The sequence is defined by the recurrence relation
43+
44+
<!-- <equation class="equation" label="eq:negafibonacci_recurrence_relation" align="center" raw="F_{n-2} = F_{n} - F_{n-1}" alt="NegaFibonacci sequence recurrence relation"> -->
45+
46+
```math
47+
F_{n-2} = F_{n} - F_{n-1}
48+
```
49+
50+
<!-- <div class="equation" align="center" data-raw-text="F_{n-2} = F_{n} - F_{n-1}" data-equation="eq:negafibonacci_recurrence_relation">
51+
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/negafibonacci/docs/img/equation_negafibonacci_recurrence_relation.svg" alt="NegaFibonacci sequence recurrence relation">
52+
<br>
53+
</div> -->
54+
55+
<!-- </equation> -->
56+
57+
which yields
58+
59+
<!-- <equation class="equation" label="eq:negafibonacci_fibonacci" align="center" raw="F_{-n} = (-1)^{n+1} F_n" alt="NegaFibonacci relationship to Fibonacci numbers"> -->
60+
61+
```math
62+
F_{-n} = (-1)^{n+1} F_n
63+
```
64+
65+
<!-- <div class="equation" align="center" data-raw-text="F_{-n} = (-1)^{n+1} F_n" data-equation="eq:negafibonacci_fibonacci">
66+
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/negafibonacci/docs/img/equation_negafibonacci_fibonacci.svg" alt="NegaFibonacci relationship to Fibonacci numbers">
67+
<br>
68+
</div> -->
69+
70+
<!-- </equation> -->
71+
72+
with seed values `F_0 = 0` and `F_{-1} = 1`.
73+
74+
</section>
75+
76+
<!-- /.intro -->
77+
78+
<section class="usage">
79+
80+
## Usage
81+
82+
```javascript
83+
var negafibonaccif = require( '@stdlib/math/base/special/negafibonaccif' );
84+
```
85+
86+
#### negafibonaccif( n )
87+
88+
Computes the nth [negaFibonacci number][fibonacci-number] as a single-precision floating-point number.
89+
90+
```javascript
91+
var v = negafibonaccif( 0 );
92+
// returns 0
93+
94+
v = negafibonaccif( -1 );
95+
// returns 1
96+
97+
v = negafibonaccif( -2 );
98+
// returns -1
99+
100+
v = negafibonaccif( -3 );
101+
// returns 2
102+
103+
v = negafibonaccif( -36 );
104+
// returns -14930352
105+
```
106+
107+
If `n < -36`, the function returns `NaN`, as larger [negaFibonacci numbers][fibonacci-number] cannot be safely represented in [single-precision floating-point format][ieee754].
108+
109+
```javascript
110+
var v = negafibonaccif( -37 );
111+
// returns NaN
112+
```
113+
114+
If not provided a nonpositive integer value, the function returns `NaN`.
115+
116+
```javascript
117+
var v = negafibonaccif( -3.14 );
118+
// returns NaN
119+
120+
v = negafibonaccif( 1 );
121+
// returns NaN
122+
```
123+
124+
If provided `NaN`, the function returns `NaN`.
125+
126+
```javascript
127+
var v = negafibonaccif( NaN );
128+
// returns NaN
129+
```
130+
131+
</section>
132+
133+
<!-- /.usage -->
134+
135+
<section class="notes">
136+
137+
</section>
138+
139+
<!-- /.notes -->
140+
141+
<section class="examples">
142+
143+
## Examples
144+
145+
<!-- eslint no-undef: "error" -->
146+
147+
```javascript
148+
var negafibonaccif = require( '@stdlib/math/base/special/negafibonaccif' );
149+
150+
var v;
151+
var i;
152+
153+
for ( i = 0; i > -37; i-- ) {
154+
v = negafibonaccif( i );
155+
console.log( v );
156+
}
157+
```
158+
159+
</section>
160+
161+
<!-- /.examples -->
162+
163+
<!-- C interface documentation. -->
164+
165+
* * *
166+
167+
<section class="c">
168+
169+
## C APIs
170+
171+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
172+
173+
<section class="intro">
174+
175+
</section>
176+
177+
<!-- /.intro -->
178+
179+
<!-- C usage documentation. -->
180+
181+
<section class="usage">
182+
183+
### Usage
184+
185+
```c
186+
#include "stdlib/math/base/special/negafibonaccif.h"
187+
```
188+
189+
#### stdlib_base_negafibonaccif( n )
190+
191+
Computes the nth [negaFibonacci number][fibonacci-number] as a single-precision floating-point number.
192+
193+
```c
194+
float out = stdlib_base_negafibonaccif( 0 );
195+
// returns 0.0f
196+
197+
out = stdlib_base_fibonaccif( -1 );
198+
// returns 1.0f
199+
```
200+
201+
The function accepts the following arguments:
202+
203+
- **n**: `[in] int32_t` input value.
204+
205+
```c
206+
float stdlib_base_negafibonaccif( const int32_t n );
207+
```
208+
209+
</section>
210+
211+
<!-- /.usage -->
212+
213+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
214+
215+
<section class="notes">
216+
217+
</section>
218+
219+
<!-- /.notes -->
220+
221+
<!-- C API usage examples. -->
222+
223+
<section class="examples">
224+
225+
### Examples
226+
227+
```c
228+
#include "stdlib/math/base/special/negafibonaccif.h"
229+
#include <stdio.h>
230+
#include <stdint.h>
231+
232+
int main( void ) {
233+
int32_t i;
234+
float v;
235+
236+
for ( i = 0; i > -37; i-- ) {
237+
v = stdlib_base_negafibonaccif( i );
238+
printf( "negafibonaccif(%d) = %f\n", i, v );
239+
}
240+
}
241+
```
242+
243+
</section>
244+
245+
<!-- /.examples -->
246+
247+
</section>
248+
249+
<!-- /.c -->
250+
251+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
252+
253+
<section class="related">
254+
255+
</section>
256+
257+
<!-- /.related -->
258+
259+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
260+
261+
<section class="links">
262+
263+
[fibonacci-number]: https://en.wikipedia.org/wiki/Fibonacci_number
264+
265+
[ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985
266+
267+
<!-- <related-links> -->
268+
269+
<!-- </related-links> -->
270+
271+
</section>
272+
273+
<!-- /.links -->

0 commit comments

Comments
 (0)