Skip to content

Commit 6724610

Browse files
Neerajpathak07kgrytestdlib-botanandkaranubc
authored
feat: add math/base/special/tribonaccif
PR-URL: #6066 Ref: #649 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com> Co-authored-by: stdlib-bot <noreply@stdlib.io> Co-authored-by: Karan Anand <anandkarancompsci@gmail.com> Reviewed-by: Gunj Joshi <gunjjoshi8372@gmail.com> Reviewed-by: Karan Anand <anandkarancompsci@gmail.com>
1 parent 223ace2 commit 6724610

File tree

27 files changed

+2471
-0
lines changed

27 files changed

+2471
-0
lines changed
Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
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] as a [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+
<!-- </equation> -->
36+
37+
The sequence is defined by the recurrence relation
38+
39+
<!-- <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"> -->
40+
41+
```math
42+
F_n = F_{n-1} + F_{n-2} + F_{n-3}
43+
```
44+
45+
<!-- </equation> -->
46+
47+
with seed values `F_0 = 0`, `F_1 = 0`, and `F_2 = 1`.
48+
49+
</section>
50+
51+
<!-- /.intro -->
52+
53+
<section class="usage">
54+
55+
## Usage
56+
57+
```javascript
58+
var tribonaccif = require( '@stdlib/math/base/special/tribonaccif' );
59+
```
60+
61+
#### tribonaccif( n )
62+
63+
Computes the nth [Tribonacci number][tribonacci-number] as a [single-precision floating-point number][ieee754].
64+
65+
```javascript
66+
var v = tribonaccif( 0 );
67+
// returns 0
68+
69+
v = tribonaccif( 1 );
70+
// returns 0
71+
72+
v = tribonaccif( 2 );
73+
// returns 1
74+
75+
v = tribonaccif( 3 );
76+
// returns 1
77+
78+
v = tribonaccif( 30 );
79+
// returns 15902591
80+
```
81+
82+
If `n > 30`, the function returns `NaN`, as larger [Tribonacci numbers][tribonacci-number] cannot be safely represented in [single-precision floating-point format][ieee754].
83+
84+
```javascript
85+
var v = tribonaccif( 31 );
86+
// returns NaN
87+
```
88+
89+
If not provided a nonnegative integer value, the function returns `NaN`.
90+
91+
```javascript
92+
var v = tribonaccif( 3.14 );
93+
// returns NaN
94+
95+
v = tribonaccif( -1 );
96+
// returns NaN
97+
```
98+
99+
If provided `NaN`, the function returns `NaN`.
100+
101+
```javascript
102+
var v = tribonaccif( NaN );
103+
// returns NaN
104+
```
105+
106+
</section>
107+
108+
<!-- /.usage -->
109+
110+
<section class="notes">
111+
112+
</section>
113+
114+
<!-- /.notes -->
115+
116+
<section class="examples">
117+
118+
## Examples
119+
120+
<!-- eslint no-undef: "error" -->
121+
122+
```javascript
123+
var logEachMap = require( '@stdlib/console/log-each-map' );
124+
var linspace = require( '@stdlib/array/base/linspace' );
125+
var tribonaccif = require( '@stdlib/math/base/special/tribonaccif' );
126+
127+
var v = linspace( 0, 30, 31 );
128+
129+
logEachMap( 'tribonaccif(%d) = %0.4f', v, tribonaccif );
130+
```
131+
132+
</section>
133+
134+
<!-- /.examples -->
135+
136+
<!-- C interface documentation. -->
137+
138+
* * *
139+
140+
<section class="c">
141+
142+
## C APIs
143+
144+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
145+
146+
<section class="intro">
147+
148+
</section>
149+
150+
<!-- /.intro -->
151+
152+
<!-- C usage documentation. -->
153+
154+
<section class="usage">
155+
156+
### Usage
157+
158+
```c
159+
#include "stdlib/math/base/special/tribonaccif.h"
160+
```
161+
162+
#### stdlib_base_tribonaccif( n )
163+
164+
Computes the nth [Tribonacci number][tribonacci-number] as a [single-precision floating-point number][ieee754].
165+
166+
```c
167+
float out = stdlib_base_tribonaccif( 0 );
168+
// returns 0.0f
169+
170+
out = stdlib_base_tribonaccif( 4 );
171+
// returns 2.0f
172+
```
173+
174+
The function accepts the following arguments:
175+
176+
- **n**: `[in] int32_t` input value.
177+
178+
```c
179+
float stdlib_base_tribonaccif( const int32_t n );
180+
```
181+
182+
</section>
183+
184+
<!-- /.usage -->
185+
186+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
187+
188+
<section class="notes">
189+
190+
</section>
191+
192+
<!-- /.notes -->
193+
194+
<!-- C API usage examples. -->
195+
196+
<section class="examples">
197+
198+
### Examples
199+
200+
```c
201+
#include "stdlib/math/base/special/tribonaccif.h"
202+
#include <stdio.h>
203+
#include <stdint.h>
204+
205+
int main( void ) {
206+
int32_t i;
207+
float v;
208+
209+
for ( i = 0; i < 31; i++ ) {
210+
v = stdlib_base_tribonaccif( i );
211+
printf( "tribonaccif(%d) = %f\n", i, v );
212+
}
213+
}
214+
```
215+
216+
</section>
217+
218+
<!-- /.examples -->
219+
220+
</section>
221+
222+
<!-- /.c -->
223+
224+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
225+
226+
<section class="related">
227+
228+
</section>
229+
230+
<!-- /.related -->
231+
232+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
233+
234+
<section class="links">
235+
236+
[tribonacci-number]: https://en.wikipedia.org/wiki/Generalizations_of_Fibonacci_numbers#Tribonacci_numbers
237+
238+
[ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985
239+
240+
<!-- <related-links> -->
241+
242+
<!-- </related-links> -->
243+
244+
</section>
245+
246+
<!-- /.links -->

0 commit comments

Comments
 (0)