|
| 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 | +# Non-Fibonacci |
| 22 | + |
| 23 | +> Compute the nth [non-Fibonacci][fibonacci-number] single-precision floating-point number. |
| 24 | +
|
| 25 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 26 | + |
| 27 | +<section class="intro"> |
| 28 | + |
| 29 | +The nth [non-Fibonacci number][fibonacci-number] is given by |
| 30 | + |
| 31 | +<!-- <equation class="equation" label="eq:nonfibonaccif_number" align="center" raw="f(n) = \left \lfloor{ n + 1 + \log_\varphi \biggl( \sqrt{5}( n + 1 + \log_\varphi(\sqrt{5}(n+1))) - 5 + \tfrac{3}{n+1} \biggr) - 2 } \right \rfloor" alt="Formula to compute the nth non-Fibonacci number."> --> |
| 32 | + |
| 33 | +```math |
| 34 | +f(n) = \left \lfloor{ n + 1 + \log_\varphi \biggl( \sqrt{5}( n + 1 + \log_\varphi(\sqrt{5}(n+1))) - 5 + \tfrac{3}{n+1} \biggr) - 2 } \right \rfloor |
| 35 | +``` |
| 36 | + |
| 37 | +<!-- <div class="equation" align="center" data-raw-text="f(n) = \left \lfloor{ n + 1 + \log_\varphi \biggl( \sqrt{5}( n + 1 + \log_\varphi(\sqrt{5}(n+1))) - 5 + \tfrac{3}{n+1} \biggr) - 2 } \right \rfloor" data-equation="eq:nonfibonaccif_number"> |
| 38 | + <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/nonfibonaccif/docs/img/equation_nonfibonacci_number.svg" alt="Formula to compute the nth non-Fibonacci number."> |
| 39 | + <br> |
| 40 | +</div> --> |
| 41 | + |
| 42 | +<!-- </equation> --> |
| 43 | + |
| 44 | +where `φ` is the [golden ratio][golden-ratio]. |
| 45 | + |
| 46 | +</section> |
| 47 | + |
| 48 | +<!-- /.intro --> |
| 49 | + |
| 50 | +<!-- Package usage documentation. --> |
| 51 | + |
| 52 | +<section class="usage"> |
| 53 | + |
| 54 | +## Usage |
| 55 | + |
| 56 | +```javascript |
| 57 | +var nonfibonaccif = require( '@stdlib/math/base/special/nonfibonaccif' ); |
| 58 | +``` |
| 59 | + |
| 60 | +#### nonfibonaccif( n ) |
| 61 | + |
| 62 | +Computes the nth [non-Fibonacci][fibonacci-number] single-precision floating-point number. |
| 63 | + |
| 64 | +```javascript |
| 65 | +var v = nonfibonaccif( 1 ); |
| 66 | +// returns 4 |
| 67 | + |
| 68 | +v = nonfibonaccif( 2 ); |
| 69 | +// returns 6 |
| 70 | + |
| 71 | +v = nonfibonaccif( 3 ); |
| 72 | +// returns 7 |
| 73 | +``` |
| 74 | + |
| 75 | +If provided either a non-integer or `n < 1`, the function returns `NaN`. |
| 76 | + |
| 77 | +```javascript |
| 78 | +var v = nonfibonaccif( -1 ); |
| 79 | +// returns NaN |
| 80 | + |
| 81 | +v = nonfibonaccif( 3.14 ); |
| 82 | +// returns NaN |
| 83 | +``` |
| 84 | + |
| 85 | +If provided `NaN`, the function returns `NaN`. |
| 86 | + |
| 87 | +```javascript |
| 88 | +var v = nonfibonaccif( NaN ); |
| 89 | +// returns NaN |
| 90 | +``` |
| 91 | + |
| 92 | +</section> |
| 93 | + |
| 94 | +<!-- /.usage --> |
| 95 | + |
| 96 | +<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 97 | + |
| 98 | +<section class="notes"> |
| 99 | + |
| 100 | +</section> |
| 101 | + |
| 102 | +<!-- /.notes --> |
| 103 | + |
| 104 | +<section class="examples"> |
| 105 | + |
| 106 | +## Examples |
| 107 | + |
| 108 | +<!-- eslint no-undef: "error" --> |
| 109 | + |
| 110 | +```javascript |
| 111 | +var nonfibonaccif = require( '@stdlib/math/base/special/nonfibonaccif' ); |
| 112 | + |
| 113 | +var i; |
| 114 | +for ( i = 1; i < 100; i++ ) { |
| 115 | + console.log( 'nonfibonaccif(%d) = %d', i, nonfibonaccif( i ) ); |
| 116 | +} |
| 117 | +``` |
| 118 | + |
| 119 | +</section> |
| 120 | + |
| 121 | +<!-- /.examples --> |
| 122 | + |
| 123 | +<!-- C interface documentation. --> |
| 124 | + |
| 125 | +* * * |
| 126 | + |
| 127 | +<section class="c"> |
| 128 | + |
| 129 | +## C APIs |
| 130 | + |
| 131 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 132 | + |
| 133 | +<section class="intro"> |
| 134 | + |
| 135 | +</section> |
| 136 | + |
| 137 | +<!-- /.intro --> |
| 138 | + |
| 139 | +<!-- C usage documentation. --> |
| 140 | + |
| 141 | +<section class="usage"> |
| 142 | + |
| 143 | +### Usage |
| 144 | + |
| 145 | +```c |
| 146 | +#include "stdlib/math/base/special/nonfibonaccif.h" |
| 147 | +``` |
| 148 | + |
| 149 | +#### stdlib_base_nonfibonaccif( x ) |
| 150 | + |
| 151 | +Computes the nth non-Fibonacci single-precision floating-point number. |
| 152 | + |
| 153 | +```c |
| 154 | +float out = stdlib_base_nonfibonaccif( 1 ); |
| 155 | +// returns 4.0f |
| 156 | + |
| 157 | +out = stdlib_base_nonfibonaccif( 2 ); |
| 158 | +// returns 6.0f |
| 159 | +``` |
| 160 | + |
| 161 | +The function accepts the following arguments: |
| 162 | + |
| 163 | +- **x**: `[in] int32_t` input value. |
| 164 | + |
| 165 | +```c |
| 166 | +float stdlib_base_nonfibonaccif( const int32_t x ); |
| 167 | +``` |
| 168 | +
|
| 169 | +</section> |
| 170 | +
|
| 171 | +<!-- /.usage --> |
| 172 | +
|
| 173 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 174 | +
|
| 175 | +<section class="notes"> |
| 176 | +
|
| 177 | +</section> |
| 178 | +
|
| 179 | +<!-- /.notes --> |
| 180 | +
|
| 181 | +<!-- C API usage examples. --> |
| 182 | +
|
| 183 | +<section class="examples"> |
| 184 | +
|
| 185 | +### Examples |
| 186 | +
|
| 187 | +```c |
| 188 | +#include "stdlib/math/base/special/nonfibonaccif.h" |
| 189 | +#include <stdio.h> |
| 190 | +
|
| 191 | +int main( void ) { |
| 192 | + int i; |
| 193 | + |
| 194 | + for ( i = 1; i < 12; i++ ) { |
| 195 | + printf( "x: %i => result: %f", i , stdlib_base_nonfibonaccif( i ) ); |
| 196 | + } |
| 197 | +} |
| 198 | +``` |
| 199 | + |
| 200 | +</section> |
| 201 | + |
| 202 | +<!-- /.examples --> |
| 203 | + |
| 204 | +</section> |
| 205 | + |
| 206 | +<!-- /.c --> |
| 207 | + |
| 208 | +<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 209 | + |
| 210 | +* * * |
| 211 | + |
| 212 | +<section class="references"> |
| 213 | + |
| 214 | +## References |
| 215 | + |
| 216 | +- Gould, H.W. 1965. "Non-Fibonacci Numbers." _Fibonacci Quarterly_, no. 3: 177–83. [<http://www.fq.math.ca/Scanned/3-3/gould.pdf>][@gould:1965a]. |
| 217 | +- Farhi, Bakir. 2011. "An explicit formula generating the non-Fibonacci numbers." _arXiv_ abs/1105.1127 \[Math.NT] (May): 1–5. [<https://arxiv.org/abs/1105.1127>][@farhi:2011a]. |
| 218 | + |
| 219 | +</section> |
| 220 | + |
| 221 | +<!-- /.references --> |
| 222 | + |
| 223 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 224 | + |
| 225 | +<section class="related"> |
| 226 | + |
| 227 | +</section> |
| 228 | + |
| 229 | +<!-- /.related --> |
| 230 | + |
| 231 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 232 | + |
| 233 | +<section class="links"> |
| 234 | + |
| 235 | +[fibonacci-number]: https://en.wikipedia.org/wiki/Fibonacci_number |
| 236 | + |
| 237 | +[golden-ratio]: https://en.wikipedia.org/wiki/Golden_ratio |
| 238 | + |
| 239 | +[@gould:1965a]: http://www.fq.math.ca/Scanned/3-3/gould.pdf |
| 240 | + |
| 241 | +[@farhi:2011a]: https://arxiv.org/abs/1105.1127 |
| 242 | + |
| 243 | +<!-- <related-links> --> |
| 244 | + |
| 245 | +<!-- </related-links> --> |
| 246 | + |
| 247 | +</section> |
| 248 | + |
| 249 | +<!-- /.links --> |
0 commit comments