time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

README.md (3652B)


      1 <!--
      2 
      3 @license Apache-2.0
      4 
      5 Copyright (c) 2020 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 # Tribonacci
     22 
     23 > Compute the nth [Tribonacci number][tribonacci-number].
     24 
     25 <section class="intro">
     26 
     27 The [Tribonacci numbers][tribonacci-number] are the integer sequence
     28 
     29 <!-- <equation class="equation" label="eq:tribonacci_sequence" align="center" raw="0, 0, 1, 1, 2, 4, 7, 13, 24, 44, 81, 149, 274, 504, 927, 1705, \ldots" alt="Tribonacci sequence"> -->
     30 
     31 <div class="equation" align="center" data-raw-text="0, 0, 1, 1, 2, 4, 7, 13, 24, 44, 81, 149, 274, 504, 927, 1705, \ldots" data-equation="eq:tribonacci_sequence">
     32     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@3249a68fb57cd71148f87ef3b2774be70a04d80a/lib/node_modules/@stdlib/math/base/special/tribonacci/docs/img/equation_tribonacci_sequence.svg" alt="Tribonacci sequence">
     33     <br>
     34 </div>
     35 
     36 <!-- </equation> -->
     37 
     38 The sequence is defined by the recurrence relation
     39 
     40 <!-- <equation class="equation" label="eq:tribonacci_recurrence_relation" align="center" raw="F_n = F_{n-1} + F_{n-2} + F_{n-3}" alt="Tribonacci sequence recurrence relation"> -->
     41 
     42 <div class="equation" align="center" data-raw-text="F_n = F_{n-1} + F_{n-2} + F_{n-3}" data-equation="eq:tribonacci_recurrence_relation">
     43     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@3249a68fb57cd71148f87ef3b2774be70a04d80a/lib/node_modules/@stdlib/math/base/special/tribonacci/docs/img/equation_tribonacci_recurrence_relation.svg" alt="Tribonacci sequence recurrence relation">
     44     <br>
     45 </div>
     46 
     47 <!-- </equation> -->
     48 
     49 with seed values `F_0 = 0`, `F_1 = 0`, and `F_2 = 1`.
     50 
     51 </section>
     52 
     53 <!-- /.intro -->
     54 
     55 <section class="usage">
     56 
     57 ## Usage
     58 
     59 ```javascript
     60 var tribonacci = require( '@stdlib/math/base/special/tribonacci' );
     61 ```
     62 
     63 #### tribonacci( n )
     64 
     65 Computes the nth [Tribonacci number][tribonacci-number].
     66 
     67 ```javascript
     68 var v = tribonacci( 0 );
     69 // returns 0
     70 
     71 v = tribonacci( 1 );
     72 // returns 0
     73 
     74 v = tribonacci( 2 );
     75 // returns 1
     76 
     77 v = tribonacci( 3 );
     78 // returns 1
     79 
     80 v = tribonacci( 63 );
     81 // returns 8607945812375585
     82 ```
     83 
     84 If `n > 63`, the function returns `NaN`, as larger [Tribonacci numbers][tribonacci-number] cannot be safely represented in [double-precision floating-point format][ieee754].
     85 
     86 ```javascript
     87 var v = tribonacci( 64 );
     88 // returns NaN
     89 ```
     90 
     91 If not provided a nonnegative integer value, the function returns `NaN`.
     92 
     93 ```javascript
     94 var v = tribonacci( 3.14 );
     95 // returns NaN
     96 
     97 v = tribonacci( -1 );
     98 // returns NaN
     99 ```
    100 
    101 If provided `NaN`, the function returns `NaN`.
    102 
    103 ```javascript
    104 var v = tribonacci( NaN );
    105 // returns NaN
    106 ```
    107 
    108 </section>
    109 
    110 <!-- /.usage -->
    111 
    112 <section class="notes">
    113 
    114 </section>
    115 
    116 <!-- /.notes -->
    117 
    118 <section class="examples">
    119 
    120 ## Examples
    121 
    122 <!-- eslint no-undef: "error" -->
    123 
    124 ```javascript
    125 var tribonacci = require( '@stdlib/math/base/special/tribonacci' );
    126 
    127 var v;
    128 var i;
    129 
    130 for ( i = 0; i < 64; i++ ) {
    131     v = tribonacci( i );
    132     console.log( v );
    133 }
    134 ```
    135 
    136 </section>
    137 
    138 <!-- /.examples -->
    139 
    140 <section class="links">
    141 
    142 [tribonacci-number]: https://en.wikipedia.org/wiki/Generalizations_of_Fibonacci_numbers#Tribonacci_numbers
    143 
    144 [ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985
    145 
    146 </section>
    147 
    148 <!-- /.links -->