time-to-botec

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

README.md (4179B)


      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 # iterCos
     22 
     23 > Create an [iterator][mdn-iterator-protocol] which iteratively computes the [cosine][@stdlib/math/base/special/cos].
     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 iterCos = require( '@stdlib/math/iter/special/cos' );
     41 ```
     42 
     43 #### iterCos( iterator )
     44 
     45 Returns an [iterator][mdn-iterator-protocol] which iteratively computes the [cosine][@stdlib/math/base/special/cos].
     46 
     47 ```javascript
     48 var array2iterator = require( '@stdlib/array/to-iterator' );
     49 
     50 var src = [ 0.0, 3.141592653589793/4.0, -3.141592653589793/6.0 ];
     51 var it = iterCos( 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.707
     59 
     60 r = it.next().value;
     61 // returns ~0.866
     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 -   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.
     82 -   If an environment supports `Symbol.iterator` **and** a provided [iterator][mdn-iterator-protocol] is iterable, the returned [iterator][mdn-iterator-protocol] is iterable.
     83 
     84 </section>
     85 
     86 <!-- /.notes -->
     87 
     88 <!-- Package usage examples. -->
     89 
     90 <section class="examples">
     91 
     92 ## Examples
     93 
     94 <!-- eslint no-undef: "error" -->
     95 
     96 ```javascript
     97 var randu = require( '@stdlib/random/iter/randu' );
     98 var iterCos = require( '@stdlib/math/iter/special/cos' );
     99 
    100 // Create a seeded iterator for generating pseudorandom numbers:
    101 var rand = randu({
    102     'seed': 1234,
    103     'iter': 10
    104 });
    105 
    106 // Create an iterator which consumes the pseudorandom number iterator:
    107 var it = iterCos( rand );
    108 
    109 // Perform manual iteration...
    110 var r;
    111 while ( true ) {
    112     r = it.next();
    113     if ( r.done ) {
    114         break;
    115     }
    116     console.log( r.value );
    117 }
    118 ```
    119 
    120 </section>
    121 
    122 <!-- /.examples -->
    123 
    124 <!-- 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. -->
    125 
    126 <section class="references">
    127 
    128 </section>
    129 
    130 <!-- /.references -->
    131 
    132 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    133 
    134 <section class="links">
    135 
    136 [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol
    137 
    138 [@stdlib/math/base/special/cos]: https://www.npmjs.com/package/@stdlib/math/tree/main/base/special/cos
    139 
    140 </section>
    141 
    142 <!-- /.links -->