Skip to content

Commit 3656652

Browse files
hrshyastdlib-botanandkaranubc
authored
feat: add math/base/special/lucasf
PR-URL: #6223 Ref: #649 Signed-off-by: Harsh <[email protected]> Co-authored-by: stdlib-bot <[email protected]> Co-authored-by: Karan Anand <[email protected]> Reviewed-by: Karan Anand <[email protected]>
1 parent 1871022 commit 3656652

File tree

29 files changed

+2682
-0
lines changed

29 files changed

+2682
-0
lines changed
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+
# Lucasf
22+
23+
> Compute the nth [Lucas number][lucas-number] as a single-precision floating-point number.
24+
25+
<section class="intro">
26+
27+
The [Lucas numbers][lucas-number] are the integer sequence
28+
29+
<!-- <equation class="equation" label="eq:lucas_sequence" align="center" raw="2, 1, 3, 4, 7, 11, 18, 29, 47, 76, 123, 199, 322, \ldots" alt="Lucas sequence"> -->
30+
31+
```math
32+
2, 1, 3, 4, 7, 11, 18, 29, 47, 76, 123, 199, 322, \ldots
33+
```
34+
35+
<!-- </equation> -->
36+
37+
The sequence is defined by the recurrence relation
38+
39+
<!-- <equation class="equation" label="eq:lucas_recurrence_relation" align="center" raw="L_n = \begin{cases}2 & \textrm{if}\ n = 0\\1 & \textrm{if}\ n = 1\\L_{n-1} + L_{n-2} & \textrm{if}\ n > 1\end{cases}" alt="Lucas sequence recurrence relation"> -->
40+
41+
```math
42+
L_n = \begin{cases}2 & \textrm{if}\ n = 0\\1 & \textrm{if}\ n = 1\\L_{n-1} + L_{n-2} & \textrm{if}\ n > 1\end{cases}
43+
```
44+
45+
<!-- </equation> -->
46+
47+
</section>
48+
49+
<!-- /.intro -->
50+
51+
<section class="usage">
52+
53+
## Usage
54+
55+
```javascript
56+
var lucasf = require( '@stdlib/math/base/special/lucasf' );
57+
```
58+
59+
#### lucasf( n )
60+
61+
Computes the nth [Lucas number][lucas-number] as a single-precision floating-point number.
62+
63+
```javascript
64+
var v = lucasf( 0 );
65+
// returns 2
66+
67+
v = lucasf( 1 );
68+
// returns 1
69+
70+
v = lucasf( 2 );
71+
// returns 3
72+
73+
v = lucasf( 3 );
74+
// returns 4
75+
76+
v = lucasf( 34 );
77+
// returns 12752043
78+
```
79+
80+
If `n > 34`, the function returns `NaN`, as larger [Lucas numbers][lucas-number] cannot be safely represented in [single-precision floating-point format][ieee754].
81+
82+
```javascript
83+
var v = lucasf( 35 );
84+
// returns NaN
85+
```
86+
87+
If not provided a nonnegative integer value, the function returns `NaN`.
88+
89+
```javascript
90+
var v = lucasf( 3.14 );
91+
// returns NaN
92+
93+
v = lucasf( -1 );
94+
// returns NaN
95+
```
96+
97+
If provided `NaN`, the function returns `NaN`.
98+
99+
```javascript
100+
var v = lucasf( NaN );
101+
// returns NaN
102+
```
103+
104+
</section>
105+
106+
<!-- /.usage -->
107+
108+
<section class="notes">
109+
110+
</section>
111+
112+
<!-- /.notes -->
113+
114+
<section class="examples">
115+
116+
## Examples
117+
118+
<!-- eslint no-undef: "error" -->
119+
120+
```javascript
121+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
122+
var logEachMap = require( '@stdlib/console/log-each-map' );
123+
var lucasf = require( '@stdlib/math/base/special/lucasf' );
124+
125+
var x = discreteUniform( 10, 0, 34, {
126+
'dtype': 'int32'
127+
});
128+
129+
logEachMap( 'lucasf(%d) = %0.1f', x, lucasf );
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/lucasf.h"
160+
```
161+
162+
#### stdlib_base_lucasf( n )
163+
164+
Compute the nth [Lucas number][lucas-number] as a single-precision floating-point number.
165+
166+
```c
167+
float out = stdlib_base_lucasf( 0 );
168+
// returns 2.0f
169+
170+
out = stdlib_base_lucasf( 1 );
171+
// returns 1.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_lucasf( 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/lucasf.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 < 35; i++ ) {
210+
v = stdlib_base_lucasf( i );
211+
printf( "lucasf(%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+
[lucas-number]: https://en.wikipedia.org/wiki/Lucas_number
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)