|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2024 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 | +# negaLucas |
| 22 | + |
| 23 | +> Compute the nth [negaLucas number][lucas-number] in single-precision floating-point format. |
| 24 | +
|
| 25 | +<section class="intro"> |
| 26 | + |
| 27 | +The [negaLucas numbers][lucas-number] are the integer sequence |
| 28 | + |
| 29 | +<!-- <equation class="equation" label="eq:negalucasf_sequence" align="center" raw="2, -1, 3, -4, 7, -11, 18, -29, 47, -76, 123, -199, 322, \ldots" alt="NegaLucas 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:negalucasf_sequence"> |
| 36 | + <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/negalucasf/docs/img/equation_negalucas_sequence.svg" alt="NegaLucas 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:negalucasf_recurrence_relation" align="center" raw="L_{n-2} = L_{n} - L_{n-1}" alt="NegaLucas sequence recurrence relation"> --> |
| 45 | + |
| 46 | +```math |
| 47 | +L_{n-2} = L_{n} - L_{n-1} |
| 48 | +``` |
| 49 | + |
| 50 | +<!-- <div class="equation" align="center" data-raw-text="L_{n-2} = L_{n} - L_{n-1}" data-equation="eq:negalucasf_recurrence_relation"> |
| 51 | + <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/negalucasf/docs/img/equation_negalucas_recurrence_relation.svg" alt="NegaLucas sequence recurrence relation"> |
| 52 | + <br> |
| 53 | +</div> --> |
| 54 | + |
| 55 | +<!-- </equation> --> |
| 56 | + |
| 57 | +which yields |
| 58 | + |
| 59 | +<!-- <equation class="equation" label="eq:negalucasf_lucas" align="center" raw="L_{-n} = (-1)^{n} L_n" alt="NegaLucas relationship to Lucas numbers"> --> |
| 60 | + |
| 61 | +```math |
| 62 | +L_{-n} = (-1)^{n} L_n |
| 63 | +``` |
| 64 | + |
| 65 | +<!-- <div class="equation" align="center" data-raw-text="L_{-n} = (-1)^{n} L_n" data-equation="eq:negalucasf_lucas"> |
| 66 | + <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/negalucasf/docs/img/equation_negalucas_lucas.svg" alt="NegaLucas relationship to Lucas numbers"> |
| 67 | + <br> |
| 68 | +</div> --> |
| 69 | + |
| 70 | +<!-- </equation> --> |
| 71 | + |
| 72 | +with seed values `L_0 = 2` and `L_{-1} = -1`. |
| 73 | + |
| 74 | +</section> |
| 75 | + |
| 76 | +<!-- /.intro --> |
| 77 | + |
| 78 | +<section class="usage"> |
| 79 | + |
| 80 | +## Usage |
| 81 | + |
| 82 | +```javascript |
| 83 | +var negalucasf = require( '@stdlib/math/base/special/negalucasf' ); |
| 84 | +``` |
| 85 | + |
| 86 | +#### negalucasf( n ) |
| 87 | + |
| 88 | +Computes the nth [negaLucas number][lucas-number] in single-precision floating-point format. |
| 89 | + |
| 90 | +```javascript |
| 91 | +var v = negalucasf( 0 ); |
| 92 | +// returns 2 |
| 93 | + |
| 94 | +v = negalucasf( -1 ); |
| 95 | +// returns -1 |
| 96 | + |
| 97 | +v = negalucasf( -2 ); |
| 98 | +// returns 3 |
| 99 | + |
| 100 | +v = negalucasf( -3 ); |
| 101 | +// returns -4 |
| 102 | + |
| 103 | +v = negalucasf( -34 ); |
| 104 | +// returns 12752043 |
| 105 | +``` |
| 106 | + |
| 107 | +If `n < -34`, the function returns `NaN`, as larger [negaLucas numbers][lucas-number] cannot be safely represented in [single-precision floating-point format][ieee754]. |
| 108 | + |
| 109 | +```javascript |
| 110 | +var v = negalucasf( -35 ); |
| 111 | +// returns NaN |
| 112 | +``` |
| 113 | + |
| 114 | +If not provided a nonpositive integer value, the function returns `NaN`. |
| 115 | + |
| 116 | +```javascript |
| 117 | +var v = negalucasf( -3.14 ); |
| 118 | +// returns NaN |
| 119 | + |
| 120 | +v = negalucasf( 1 ); |
| 121 | +// returns NaN |
| 122 | +``` |
| 123 | + |
| 124 | +If provided `NaN`, the function returns `NaN`. |
| 125 | + |
| 126 | +```javascript |
| 127 | +var v = negalucasf( 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 negalucasf = require( '@stdlib/math/base/special/negalucasf' ); |
| 149 | + |
| 150 | +var v; |
| 151 | +var i; |
| 152 | + |
| 153 | +for ( i = 0; i > -35; i-- ) { |
| 154 | + v = negalucasf( 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/negalucasf.h" |
| 187 | +``` |
| 188 | + |
| 189 | +#### stdlib_base_negalucasf( n ) |
| 190 | + |
| 191 | +Computes the nth [negaLucas number][lucas-number] in single-precision floating-point format. |
| 192 | + |
| 193 | +```c |
| 194 | +float out = stdlib_base_negalucasf( 0 ); |
| 195 | +// returns 0.0f |
| 196 | + |
| 197 | +out = stdlib_base_negalucasf( -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_negalucasf( 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/negalucasf.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 > -35; i-- ) { |
| 237 | + v = stdlib_base_negalucasf( i ); |
| 238 | + printf( "negalucasf(%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 | +[lucas-number]: https://en.wikipedia.org/wiki/Lucas_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