README.md (2921B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2018 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 # Fibonacci Number Index 22 23 > Compute the [Fibonacci number][fibonacci-number] index. 24 25 <section class="intro"> 26 27 The [Fibonacci number][fibonacci-number] index is given by 28 29 <!-- <equation class="equation" label="eq:fibonacci_number_index" align="center" raw="n = \left \lfloor{\log_\varphi \biggl(F \cdot \sqrt{5} + \tfrac{1}{2}\biggr)}\right \rfloor" alt="Formula to compute the Fibonacci number index."> --> 30 31 <div class="equation" align="center" data-raw-text="n = \left \lfloor{\log_\varphi \biggl(F \cdot \sqrt{5} + \tfrac{1}{2}\biggr)}\right \rfloor" data-equation="eq:fibonacci_number_index"> 32 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/fibonacci-index/docs/img/equation_fibonacci_number_index.svg" alt="Formula to compute the Fibonacci number index."> 33 <br> 34 </div> 35 36 <!-- </equation> --> 37 38 where `φ` is the [golden ratio][golden-ratio] and `F > 1`. 39 40 </section> 41 42 <!-- /.intro --> 43 44 <section class="usage"> 45 46 ## Usage 47 48 ```javascript 49 var fibonacciIndex = require( '@stdlib/math/base/special/fibonacci-index' ); 50 ``` 51 52 #### fibonacciIndex( F ) 53 54 Computes the [Fibonacci number][fibonacci-number] index for `F_n > 1`. 55 56 ```javascript 57 var n = fibonacciIndex( 2 ); 58 // returns 3 59 60 n = fibonacciIndex( 3 ); 61 // returns 4 62 63 n = fibonacciIndex( 5 ); 64 // returns 5 65 ``` 66 67 If provided either a non-integer or `F_n <= 1`, the function returns `NaN`. 68 69 ```javascript 70 var n = fibonacciIndex( -1 ); 71 // returns NaN 72 73 n = fibonacciIndex( 3.14 ); 74 // returns NaN 75 ``` 76 77 If provided `NaN`, the function returns `NaN`. 78 79 ```javascript 80 var n = fibonacciIndex( NaN ); 81 // returns NaN 82 ``` 83 84 </section> 85 86 <!-- /.usage --> 87 88 <section class="notes"> 89 90 </section> 91 92 <!-- /.notes --> 93 94 <section class="examples"> 95 96 ## Examples 97 98 <!-- eslint no-undef: "error" --> 99 100 ```javascript 101 var fibonacciIndex = require( '@stdlib/math/base/special/fibonacci-index' ); 102 103 var F1; 104 var F2; 105 var FN; 106 var n; 107 var i; 108 109 F1 = 1; 110 F2 = 1; 111 for ( i = 3; i < 79; i++ ) { 112 FN = F1 + F2; 113 F1 = F2; 114 F2 = FN; 115 n = fibonacciIndex( FN ); 116 console.log( 'n(%d) = %d', FN, n ); 117 } 118 ``` 119 120 </section> 121 122 <!-- /.examples --> 123 124 <section class="links"> 125 126 [fibonacci-number]: https://en.wikipedia.org/wiki/Fibonacci_number 127 128 [golden-ratio]: https://en.wikipedia.org/wiki/Golden_ratio 129 130 </section> 131 132 <!-- /.links -->