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