Skip to content

Commit f67e2a7

Browse files
feat: add-tribonaccif
1 parent 39e505f commit f67e2a7

File tree

27 files changed

+2346
-0
lines changed

27 files changed

+2346
-0
lines changed
Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
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+
# Tribonaccif
22+
23+
> Compute the nth [Tribonacci number][tribonacci-number] for [single-precision floating-point number][ieee754].
24+
25+
<section class="intro">
26+
27+
The [Tribonacci numbers][tribonacci-number] are the integer sequence
28+
29+
<!-- <equation class="equation" label="eq:tribonacci_sequence" align="center" raw="0, 0, 1, 1, 2, 4, 7, 13, 24, 44, 81, 149, 274, 504, 927, 1705, \ldots" alt="Tribonacci sequence"> -->
30+
31+
```math
32+
0, 0, 1, 1, 2, 4, 7, 13, 24, 44, 81, 149, 274, 504, 927, 1705, \ldots
33+
```
34+
35+
<!-- <div class="equation" align="center" data-raw-text="0, 0, 1, 1, 2, 4, 7, 13, 24, 44, 81, 149, 274, 504, 927, 1705, \ldots" data-equation="eq:tribonacci_sequence">
36+
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@3249a68fb57cd71148f87ef3b2774be70a04d80a/lib/node_modules/@stdlib/math/base/special/tribonacci/docs/img/equation_tribonacci_sequence.svg" alt="Tribonacci 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:tribonacci_recurrence_relation" align="center" raw="F_n = F_{n-1} + F_{n-2} + F_{n-3}" alt="Tribonacci sequence recurrence relation"> -->
45+
46+
```math
47+
F_n = F_{n-1} + F_{n-2} + F_{n-3}
48+
```
49+
50+
<!-- <div class="equation" align="center" data-raw-text="F_n = F_{n-1} + F_{n-2} + F_{n-3}" data-equation="eq:tribonacci_recurrence_relation">
51+
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@3249a68fb57cd71148f87ef3b2774be70a04d80a/lib/node_modules/@stdlib/math/base/special/tribonacci/docs/img/equation_tribonacci_recurrence_relation.svg" alt="Tribonacci sequence recurrence relation">
52+
<br>
53+
</div> -->
54+
55+
<!-- </equation> -->
56+
57+
with seed values `F_0 = 0`, `F_1 = 0`, and `F_2 = 1`.
58+
59+
</section>
60+
61+
<!-- /.intro -->
62+
63+
<section class="usage">
64+
65+
## Usage
66+
67+
```javascript
68+
var tribonaccif = require( '@stdlib/math/base/special/tribonaccif' );
69+
```
70+
71+
#### tribonaccif( n )
72+
73+
Computes the nth [Tribonacci number][tribonacci-number] for [single-precision floating-point number][ieee754].
74+
75+
```javascript
76+
var v = tribonaccif( 0 );
77+
// returns 0
78+
79+
v = tribonaccif( 1 );
80+
// returns 0
81+
82+
v = tribonaccif( 2 );
83+
// returns 1
84+
85+
v = tribonaccif( 3 );
86+
// returns 1
87+
88+
v = tribonaccif( 30 );
89+
// returns 15902591
90+
```
91+
92+
If `n > 30`, the function returns `NaN`, as larger [Tribonacci numbers][tribonacci-number] cannot be safely represented in [single-precision floating-point format][ieee754].
93+
94+
```javascript
95+
var v = tribonaccif( 32 );
96+
// returns NaN
97+
```
98+
99+
If not provided a nonnegative integer value, the function returns `NaN`.
100+
101+
```javascript
102+
var v = tribonaccif( 3.14 );
103+
// returns NaN
104+
105+
v = tribonaccif( -1 );
106+
// returns NaN
107+
```
108+
109+
If provided `NaN`, the function returns `NaN`.
110+
111+
```javascript
112+
var v = tribonaccif( 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 tribonaccif = require( '@stdlib/math/base/special/tribonaccif' );
134+
135+
var v;
136+
var i;
137+
138+
for ( i = 0; i < 31; i++ ) {
139+
v = tribonaccif( i );
140+
console.log( v );
141+
}
142+
```
143+
144+
</section>
145+
146+
<!-- /.examples -->
147+
148+
<!-- C interface documentation. -->
149+
150+
* * *
151+
152+
<section class="c">
153+
154+
## C APIs
155+
156+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
157+
158+
<section class="intro">
159+
160+
</section>
161+
162+
<!-- /.intro -->
163+
164+
<!-- C usage documentation. -->
165+
166+
<section class="usage">
167+
168+
### Usage
169+
170+
```c
171+
#include "stdlib/math/base/special/tribonacci.h"
172+
```
173+
174+
#### stdlib_base_tribonaccif( n )
175+
176+
Computes the nth [Tribonacci number][tribonacci-number] [single-precision floating-point number][ieee754].
177+
178+
```c
179+
float out = stdlib_base_tribonaccif( 0 );
180+
// returns 0
181+
182+
out = stdlib_base_tribonaccif( 1 );
183+
// returns 0
184+
```
185+
186+
The function accepts the following arguments:
187+
188+
- **n**: `[in] int32_t` input value.
189+
190+
```c
191+
float stdlib_base_tribonaccif( const int32_t n );
192+
```
193+
194+
</section>
195+
196+
<!-- /.usage -->
197+
198+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
199+
200+
<section class="notes">
201+
202+
</section>
203+
204+
<!-- /.notes -->
205+
206+
<!-- C API usage examples. -->
207+
208+
<section class="examples">
209+
210+
### Examples
211+
212+
```c
213+
#include "stdlib/math/base/special/tribonaccif.h"
214+
#include <stdio.h>
215+
#include <stdint.h>
216+
217+
int main( void ) {
218+
int32_t i;
219+
float v;
220+
221+
for ( i = 0; i < 31; i++ ) {
222+
v = stdlib_base_tribonaccif( i );
223+
printf( "tribonacci(%d) = %f\n", i, v );
224+
}
225+
}
226+
```
227+
228+
</section>
229+
230+
<!-- /.examples -->
231+
232+
</section>
233+
234+
<!-- /.c -->
235+
236+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
237+
238+
<section class="related">
239+
240+
* * *
241+
242+
## See Also
243+
244+
- <span class="package-name">[`@stdlib/math/base/special/tribonacci`][@stdlib/math/base/special/tribonacci]</span><span class="delimiter">: </span><span class="description">compute the nth Tribonacci number.</span>
245+
246+
</section>
247+
248+
<!-- /.related -->
249+
250+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
251+
252+
<section class="links">
253+
254+
[tribonacci-number]: https://en.wikipedia.org/wiki/Generalizations_of_Fibonacci_numbers#Tribonacci_numbers
255+
256+
[ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985
257+
258+
<!-- <related-links> -->
259+
260+
[@stdlib/math/base/special/tribonacci]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/tribonacci
261+
262+
<!-- </related-links> -->
263+
264+
</section>
265+
266+
<!-- /.links -->

0 commit comments

Comments
 (0)