README.md (4286B)
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 # iterCospi 22 23 > Create an [iterator][mdn-iterator-protocol] which computes the [cosine][@stdlib/math/base/special/cospi] of each iterated value times π. 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 iterCospi = require( '@stdlib/math/iter/special/cospi' ); 41 ``` 42 43 #### iterCospi( iterator ) 44 45 Returns an [iterator][mdn-iterator-protocol] which computes the [cosine][@stdlib/math/base/special/cospi] of each iterated value times π. 46 47 ```javascript 48 var array2iterator = require( '@stdlib/array/to-iterator' ); 49 50 var src = [ 0.0, 0.5, 0.1 ]; 51 var it = iterCospi( array2iterator( src ) ); 52 // returns <Object> 53 54 var r = it.next().value; 55 // returns 1.0 56 57 r = it.next().value; 58 // returns 0.0 59 60 r = it.next().value; 61 // returns ~0.951 62 63 // ... 64 ``` 65 66 The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the following properties: 67 68 - **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. 69 - **return**: function which closes an [iterator][mdn-iterator-protocol] and returns a single (optional) argument in an [iterator][mdn-iterator-protocol] protocol-compliant object. 70 71 </section> 72 73 <!-- /.usage --> 74 75 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 76 77 <section class="notes"> 78 79 ## Notes 80 81 - Computes `cos(πx)` more accurately than `cos(pi*x)`, especially for large `x`. 82 - 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. 83 - If an environment supports `Symbol.iterator` **and** a provided [iterator][mdn-iterator-protocol] is iterable, the returned [iterator][mdn-iterator-protocol] is iterable. 84 85 </section> 86 87 <!-- /.notes --> 88 89 <!-- Package usage examples. --> 90 91 <section class="examples"> 92 93 ## Examples 94 95 <!-- eslint no-undef: "error" --> 96 97 ```javascript 98 var randu = require( '@stdlib/random/iter/randu' ); 99 var iterCospi = require( '@stdlib/math/iter/special/cospi' ); 100 101 // Create a seeded iterator for generating pseudorandom numbers: 102 var rand = randu({ 103 'seed': 1234, 104 'iter': 10 105 }); 106 107 // Create an iterator which consumes the pseudorandom number iterator: 108 var it = iterCospi( rand ); 109 110 // Perform manual iteration... 111 var r; 112 while ( true ) { 113 r = it.next(); 114 if ( r.done ) { 115 break; 116 } 117 console.log( r.value ); 118 } 119 ``` 120 121 </section> 122 123 <!-- /.examples --> 124 125 <!-- 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. --> 126 127 <section class="references"> 128 129 </section> 130 131 <!-- /.references --> 132 133 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 134 135 <section class="links"> 136 137 [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol 138 139 [@stdlib/math/base/special/cospi]: https://www.npmjs.com/package/@stdlib/math/tree/main/base/special/cospi 140 141 </section> 142 143 <!-- /.links -->