README.md (5192B)
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 # iterLog 22 23 > Create an [iterator][mdn-iterator-protocol] which iteratively computes the base `b` [logarithm][@stdlib/math/base/special/log]. 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 </section> 30 31 <!-- /.intro --> 32 33 <!-- Package usage documentation. --> 34 35 <section class="usage"> 36 37 ## Usage 38 39 ```javascript 40 var iterLog = require( '@stdlib/math/iter/special/log' ); 41 ``` 42 43 #### iterLog( x, b ) 44 45 Returns an [iterator][mdn-iterator-protocol] which iteratively computes the base `b` [logarithm][@stdlib/math/base/special/log] of `x`. 46 47 ```javascript 48 var array2iterator = require( '@stdlib/array/to-iterator' ); 49 50 var x = array2iterator( [ 2.0, 2.0, 10.0 ] ); 51 var y = array2iterator( [ 2.0, 6.0, 2.0 ] ); 52 53 var it = iterLog( x, y ); 54 // returns <Object> 55 56 var r = it.next().value; 57 // returns 1.0 58 59 r = it.next().value; 60 // returns ~0.3869 61 62 r = it.next().value; 63 // returns ~3.3219 64 65 // ... 66 ``` 67 68 The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the following properties: 69 70 - **next**: function which returns an [iterator][mdn-iterator-protocol] protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the iterator is finished. 71 - **return**: function which closes an [iterator][mdn-iterator-protocol] and returns a single (optional) argument in an [iterator][mdn-iterator-protocol] protocol-compliant object. 72 73 If provided a numeric value as an [`iterator`][mdn-iterator-protocol] argument, the value is broadcast as an **infinite** [iterator][mdn-iterator-protocol] which **always** returns the provided value. 74 75 ```javascript 76 var array2iterator = require( '@stdlib/array/to-iterator' ); 77 78 var x = array2iterator( [ 2.0, 6.0 ] ); 79 80 var it = iterLog( x, 2.0 ); 81 // returns <Object> 82 83 var v = it.next().value; 84 // returns 1.0 85 86 v = it.next().value; 87 // returns ~2.58496 88 89 var bool = it.next().done; 90 // returns true 91 ``` 92 93 </section> 94 95 <!-- /.usage --> 96 97 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 98 99 <section class="notes"> 100 101 ## Notes 102 103 - For negative `b` or `x` iterated values, the returned [iterator][mdn-iterator-protocol] returns `NaN`. 104 - If an iterated value is non-numeric (including `NaN`), the returned [iterator][mdn-iterator-protocol] returns `NaN`. If non-numeric iterated values are possible, you are advised to provide an [`iterator`][mdn-iterator-protocol] which type checks and handles non-numeric values accordingly. 105 - The length of the returned [iterator][mdn-iterator-protocol] is equal to the length of the shortest provided [iterator][mdn-iterator-protocol]. In other words, the returned [iterator][mdn-iterator-protocol] ends once **one** of the provided [iterators][mdn-iterator-protocol] ends. 106 - If an environment supports `Symbol.iterator` **and** a provided [iterator][mdn-iterator-protocol] is iterable, the returned [iterator][mdn-iterator-protocol] is iterable. 107 108 </section> 109 110 <!-- /.notes --> 111 112 <!-- Package usage examples. --> 113 114 <section class="examples"> 115 116 ## Examples 117 118 <!-- eslint no-undef: "error" --> 119 120 ```javascript 121 var uniform = require( '@stdlib/random/iter/uniform' ); 122 var iterLog = require( '@stdlib/math/iter/special/log' ); 123 124 // Create seeded iterators for generating pseudorandom numbers: 125 var x = uniform( 0.0, 100.0, { 126 'seed': 1234, 127 'iter': 10 128 }); 129 130 var y = uniform( 0.0, 10.0, { 131 'seed': 4567, 132 'iter': 10 133 }); 134 135 // Create an iterator which consumes the pseudorandom number iterators: 136 var it = iterLog( x, y ); 137 138 // Perform manual iteration... 139 var r; 140 while ( true ) { 141 r = it.next(); 142 if ( r.done ) { 143 break; 144 } 145 console.log( r.value ); 146 } 147 ``` 148 149 </section> 150 151 <!-- /.examples --> 152 153 <!-- 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. --> 154 155 <section class="references"> 156 157 </section> 158 159 <!-- /.references --> 160 161 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 162 163 <section class="links"> 164 165 [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol 166 167 [@stdlib/math/base/special/log]: https://www.npmjs.com/package/@stdlib/math/tree/main/base/special/log 168 169 </section> 170 171 <!-- /.links -->