|
| 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] in single-precision floating-point format. |
| 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 | +<!-- <div class="equation" align="center" data-raw-text="2, 1, 3, 4, 7, 11, 18, 29, 47, 76, 123, 199, 322, \ldots" data-equation="eq:lucas_sequence"> |
| 36 | + <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/lucas/docs/img/equation_lucas_sequence.svg" alt="Lucas 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: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"> --> |
| 45 | + |
| 46 | +```math |
| 47 | +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} |
| 48 | +``` |
| 49 | + |
| 50 | +<!-- <div class="equation" align="center" data-raw-text="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}" data-equation="eq:lucas_recurrence_relation"> |
| 51 | + <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/lucas/docs/img/equation_lucas_recurrence_relation.svg" alt="Lucas sequence recurrence relation"> |
| 52 | + <br> |
| 53 | +</div> --> |
| 54 | + |
| 55 | +<!-- </equation> --> |
| 56 | + |
| 57 | +</section> |
| 58 | + |
| 59 | +<!-- /.intro --> |
| 60 | + |
| 61 | +<section class="usage"> |
| 62 | + |
| 63 | +## Usage |
| 64 | + |
| 65 | +```javascript |
| 66 | +var lucasf = require( '@stdlib/math/base/special/lucasf' ); |
| 67 | +``` |
| 68 | + |
| 69 | +#### lucasf( n ) |
| 70 | + |
| 71 | +Computes the nth [Lucas number][lucas-number] in single-precision floating-point format. |
| 72 | + |
| 73 | +```javascript |
| 74 | +var v = lucasf( 0 ); |
| 75 | +// returns 2 |
| 76 | + |
| 77 | +v = lucasf( 1 ); |
| 78 | +// returns 1 |
| 79 | + |
| 80 | +v = lucasf( 2 ); |
| 81 | +// returns 3 |
| 82 | + |
| 83 | +v = lucasf( 3 ); |
| 84 | +// returns 4 |
| 85 | + |
| 86 | +v = lucasf( 34 ); |
| 87 | +// returns 12752043 |
| 88 | +``` |
| 89 | + |
| 90 | +If `n > 34`, the function returns `NaN`, as larger [Lucas numbers][lucas-number] cannot be safely represented in [single-precision floating-point format][ieee754]. |
| 91 | + |
| 92 | +```javascript |
| 93 | +var v = lucasf( 35 ); |
| 94 | +// returns NaN |
| 95 | +``` |
| 96 | + |
| 97 | +If not provided a nonnegative integer value, the function returns `NaN`. |
| 98 | + |
| 99 | +```javascript |
| 100 | +var v = lucasf( 3.14 ); |
| 101 | +// returns NaN |
| 102 | + |
| 103 | +v = lucasf( -1 ); |
| 104 | +// returns NaN |
| 105 | +``` |
| 106 | + |
| 107 | +If provided `NaN`, the function returns `NaN`. |
| 108 | + |
| 109 | +```javascript |
| 110 | +var v = lucasf( NaN ); |
| 111 | +// returns NaN |
| 112 | +``` |
| 113 | + |
| 114 | +</section> |
| 115 | + |
| 116 | +<!-- /.usage --> |
| 117 | + |
| 118 | +<section class="notes"> |
| 119 | + |
| 120 | +</section> |
| 121 | + |
| 122 | +<!-- /.notes --> |
| 123 | + |
| 124 | +<section class="examples"> |
| 125 | + |
| 126 | +## Examples |
| 127 | + |
| 128 | +<!-- eslint no-undef: "error" --> |
| 129 | + |
| 130 | +```javascript |
| 131 | +var lucasf = require( '@stdlib/math/base/special/lucasf' ); |
| 132 | + |
| 133 | +var v; |
| 134 | +var i; |
| 135 | + |
| 136 | +for ( i = 0; i < 35; i++ ) { |
| 137 | + v = lucasf( i ); |
| 138 | + console.log( v ); |
| 139 | +} |
| 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/lucasf.h" |
| 170 | +``` |
| 171 | + |
| 172 | +#### stdlib_base_lucasf( n ) |
| 173 | + |
| 174 | +Computes the nth [Lucas number][lucas-number] in single-precision floating-point format. |
| 175 | + |
| 176 | +```c |
| 177 | +double out = stdlib_base_lucasf( 0 ); |
| 178 | +// returns 2.0f |
| 179 | + |
| 180 | +out = stdlib_base_lucasf( 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_lucas( 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/lucasf.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 < 35; i++ ) { |
| 220 | + v = stdlib_base_lucasf( i ); |
| 221 | + printf( "lucasf(%d) = %lf\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 | +* * * |
| 239 | + |
| 240 | +## See Also |
| 241 | + |
| 242 | +- <span class="package-name">[`@stdlib/math/base/special/fibonacci`][@stdlib/math/base/special/fibonacci]</span><span class="delimiter">: </span><span class="description">compute the nth Fibonacci number.</span> |
| 243 | +- <span class="package-name">[`@stdlib/math/base/special/negalucas`][@stdlib/math/base/special/negalucas]</span><span class="delimiter">: </span><span class="description">compute the nth negaLucas number.</span> |
| 244 | + |
| 245 | +</section> |
| 246 | + |
| 247 | +<!-- /.related --> |
| 248 | + |
| 249 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 250 | + |
| 251 | +<section class="links"> |
| 252 | + |
| 253 | +[lucas-number]: https://en.wikipedia.org/wiki/Lucas_number |
| 254 | + |
| 255 | +[ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985 |
| 256 | + |
| 257 | +<!-- <related-links> --> |
| 258 | + |
| 259 | +[@stdlib/math/base/special/fibonacci]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/fibonacci |
| 260 | + |
| 261 | +[@stdlib/math/base/special/negalucas]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/negalucas |
| 262 | + |
| 263 | +<!-- </related-links> --> |
| 264 | + |
| 265 | +</section> |
| 266 | + |
| 267 | +<!-- /.links --> |
0 commit comments