time-to-botec

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

repl.txt (1837B)


      1 
      2 {{alias}}( generator[, options] )
      3     Sum the elements of the series given by the supplied function.
      4 
      5     Parameters
      6     ----------
      7     generator: Function
      8         Series function.
      9 
     10     options: Object (optional)
     11         Options.
     12 
     13     options.maxTerms: integer (optional)
     14         Maximum number of terms to be added. Default: `1000000`.
     15 
     16     options.tolerance: number (optional)
     17         Further terms are only added as long as the next term is greater than
     18         the current term times the tolerance. Default: `2.22e-16`.
     19 
     20     options.initialValue: number (optional)
     21         Initial value of the resulting sum. Default: `0`.
     22 
     23     Returns
     24     -------
     25     out: number
     26         Sum of series terms.
     27 
     28     Examples
     29     --------
     30     // Using an ES6 generator function:
     31     > function* geometricSeriesGenerator( x ) {
     32     ...     var exponent = 0;
     33     ...     while ( true ) {
     34     ...         yield Math.pow( x, exponent );
     35     ...         exponent += 1;
     36     ...     }
     37     ... };
     38     > var gen = geometricSeriesGenerator( 0.9 );
     39     > var out = {{alias}}( gen )
     40     10
     41 
     42     // Using a closure:
     43     > function geometricSeriesClosure( x ) {
     44     ...     var exponent = -1;
     45     ...     return function() {
     46     ...         exponent += 1;
     47     ...         return Math.pow( x, exponent );
     48     ...     };
     49     ... };
     50     > gen = geometricSeriesClosure( 0.9 );
     51     > out = {{alias}}( gen )
     52     10
     53 
     54     // Setting an initial value for the sum:
     55     > out = {{alias}}( geometricSeriesGenerator( 0.5 ), { 'initialValue': 1 } )
     56     3
     57     // Changing the maximum number of terms to be summed:
     58     > out = {{alias}}( geometricSeriesGenerator( 0.5 ), { 'maxTerms': 10 } )
     59     ~1.998 // Infinite sum is 2
     60 
     61     // Adjusting the used tolerance:
     62     > out = {{alias}}( geometricSeriesGenerator( 0.5 ), { 'tolerance': 1e-3 } )
     63     ~1.998
     64 
     65     See Also
     66     --------
     67