time-to-botec

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

README.md (4786B)


      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 # isTriangularNumber
     22 
     23 > Test if a value is a [triangular number][triangular-number].
     24 
     25 <section class="intro">
     26 
     27 [Triangular numbers][triangular-number] can be computed using the following formula
     28 
     29 <!-- <equation class="equation" label="eq:triangular_number" align="center" raw="T_n = \frac{n(n+1)}{2}" alt="Triangular number formula."> -->
     30 
     31 <div class="equation" align="center" data-raw-text="T_n = \frac{n(n+1)}{2}" data-equation="eq:triangular_number">
     32     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@0e41839343d292d7f99581a15ee8086b1e1dea68/lib/node_modules/@stdlib/assert/is-triangular-number/docs/img/equation_triangular_number.svg" alt="Triangular number formula.">
     33     <br>
     34 </div>
     35 
     36 <!-- </equation> -->
     37 
     38 for `n >= 0`.
     39 
     40 By analogy with the square root of `x`, one can define the positive triangular root of `x` such that `T_n = x`
     41 
     42 <!-- <equation class="equation" label="eq:triangular_root" align="center" raw="n = \frac{\sqrt{8x+1} - 1}{2}" alt="Triangular root formula."> -->
     43 
     44 <div class="equation" align="center" data-raw-text="n = \frac{\sqrt{8x+1} - 1}{2}" data-equation="eq:triangular_root">
     45     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@0e41839343d292d7f99581a15ee8086b1e1dea68/lib/node_modules/@stdlib/assert/is-triangular-number/docs/img/equation_triangular_root.svg" alt="Triangular root formula.">
     46     <br>
     47 </div>
     48 
     49 <!-- </equation> -->
     50 
     51 Accordingly, an integer `x` is a [triangular number][triangular-number] **if and only** if `8x+1` is a [square number][@stdlib/assert/is-square-number].
     52 
     53 </section>
     54 
     55 <!-- /.intro -->
     56 
     57 <section class="usage">
     58 
     59 ## Usage
     60 
     61 ```javascript
     62 var isTriangularNumber = require( '@stdlib/assert/is-triangular-number' );
     63 ```
     64 
     65 #### isTriangularNumber( value )
     66 
     67 Tests if a `value` is a [triangular number][triangular-number].
     68 
     69 <!-- eslint-disable no-new-wrappers -->
     70 
     71 ```javascript
     72 var Number = require( '@stdlib/number/ctor' );
     73 
     74 var bool = isTriangularNumber( 36.0 );
     75 // returns true
     76 
     77 bool = isTriangularNumber( new Number( 36.0 ) );
     78 // returns true
     79 
     80 bool = isTriangularNumber( 3.14 );
     81 // returns false
     82 
     83 bool = isTriangularNumber( -5.0 );
     84 // returns false
     85 
     86 bool = isTriangularNumber( NaN );
     87 // returns false
     88 
     89 bool = isTriangularNumber( null );
     90 // returns false
     91 ```
     92 
     93 #### isTriangularNumber.isPrimitive( value )
     94 
     95 Tests if a `value` is a primitive [triangular number][triangular-number].
     96 
     97 <!-- eslint-disable no-new-wrappers -->
     98 
     99 ```javascript
    100 var Number = require( '@stdlib/number/ctor' );
    101 
    102 var bool = isTriangularNumber.isPrimitive( 36.0 );
    103 // returns true
    104 
    105 bool = isTriangularNumber.isPrimitive( new Number( 36.0 ) );
    106 // returns false
    107 ```
    108 
    109 #### isTriangularNumber.isObject( value )
    110 
    111 Tests if a `value` is a `Number` object having a value which is a [triangular number][triangular-number].
    112 
    113 <!-- eslint-disable no-new-wrappers -->
    114 
    115 ```javascript
    116 var Number = require( '@stdlib/number/ctor' );
    117 
    118 var bool = isTriangularNumber.isObject( 36.0 );
    119 // returns false
    120 
    121 bool = isTriangularNumber.isObject( new Number( 36.0 ) );
    122 // returns true
    123 ```
    124 
    125 </section>
    126 
    127 <!-- /.usage -->
    128 
    129 <section class="notes">
    130 
    131 ## Notes
    132 
    133 -   Return values are not reliable for numbers greater than `1125899906842624`.
    134 
    135 </section>
    136 
    137 <!-- /.notes -->
    138 
    139 <section class="examples">
    140 
    141 ## Examples
    142 
    143 <!-- eslint-disable no-new-wrappers -->
    144 
    145 <!-- eslint no-undef: "error" -->
    146 
    147 ```javascript
    148 var Number = require( '@stdlib/number/ctor' );
    149 var isTriangularNumber = require( '@stdlib/assert/is-triangular-number' );
    150 
    151 var bool = isTriangularNumber( 36.0 );
    152 // returns true
    153 
    154 bool = isTriangularNumber( new Number( 36.0 ) );
    155 // returns true
    156 
    157 bool = isTriangularNumber( 0.0 );
    158 // returns true
    159 
    160 bool = isTriangularNumber( 1.0 );
    161 // returns true
    162 
    163 bool = isTriangularNumber( 3.14 );
    164 // returns false
    165 
    166 bool = isTriangularNumber( -5.0 );
    167 // returns false
    168 
    169 bool = isTriangularNumber( NaN );
    170 // returns false
    171 
    172 bool = isTriangularNumber( '0.5' );
    173 // returns false
    174 
    175 bool = isTriangularNumber( null );
    176 // returns false
    177 ```
    178 
    179 </section>
    180 
    181 <!-- /.examples -->
    182 
    183 <section class="links">
    184 
    185 [triangular-number]: https://en.wikipedia.org/wiki/Triangular_number
    186 
    187 [@stdlib/assert/is-square-number]: https://www.npmjs.com/package/@stdlib/assert/tree/main/is-square-number
    188 
    189 </section>
    190 
    191 <!-- /.links -->