Skip to content

Commit aa37d2f

Browse files
committed
docs: update description and examples
1 parent 47c542c commit aa37d2f

File tree

8 files changed

+54
-75
lines changed

8 files changed

+54
-75
lines changed

lib/node_modules/@stdlib/math/base/tools/evalpoly/README.md

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020

2121
# evalpoly
2222

23-
> Evaluate a [polynomial][polynomial].
23+
> Evaluate a [polynomial][polynomial] using double-precision floating-point arithmetic.
2424
2525
<section class="intro">
2626

@@ -66,7 +66,7 @@ The coefficients should be ordered in **ascending** degree, thus matching summat
6666

6767
#### evalpoly.factory( c )
6868

69-
Uses code generation to in-line coefficients and return a `function` for evaluating a [polynomial][polynomial].
69+
Uses code generation to in-line coefficients and return a function for evaluating a [polynomial][polynomial] using double-precision floating-point arithmetic.
7070

7171
```javascript
7272
var polyval = evalpoly.factory( [ 3.0, 2.0, 1.0 ] );
@@ -100,38 +100,25 @@ v = polyval( 5.0 ); // => 3*5^0 + 2*5^1 + 1*5^2
100100
<!-- eslint no-undef: "error" -->
101101

102102
```javascript
103-
var randu = require( '@stdlib/random/base/randu' );
104-
var round = require( '@stdlib/math/base/special/round' );
105-
var Float64Array = require( '@stdlib/array/float64' );
103+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
104+
var uniform = require( '@stdlib/random/base/uniform' );
106105
var evalpoly = require( '@stdlib/math/base/tools/evalpoly' );
107106

108-
var polyval;
109-
var coef;
110-
var sign;
107+
// Create an array of random coefficients:
108+
var coef = discreteUniform( 10, -100, 100 );
109+
110+
// Evaluate the polynomial at random values:
111111
var v;
112112
var i;
113-
114-
// Create an array of random coefficients...
115-
coef = new Float64Array( 10 );
116-
for ( i = 0; i < coef.length; i++ ) {
117-
if ( randu() < 0.5 ) {
118-
sign = -1.0;
119-
} else {
120-
sign = 1.0;
121-
}
122-
coef[ i ] = sign * round( randu()*100.0 );
123-
}
124-
125-
// Evaluate the polynomial at random values...
126113
for ( i = 0; i < 100; i++ ) {
127-
v = randu() * 100.0;
114+
v = uniform( 0.0, 100.0 );
128115
console.log( 'f(%d) = %d', v, evalpoly( coef, v ) );
129116
}
130117

131-
// Generate an `evalpoly` function...
132-
polyval = evalpoly.factory( coef );
118+
// Generate an `evalpoly` function:
119+
var polyval = evalpoly.factory( coef );
133120
for ( i = 0; i < 100; i++ ) {
134-
v = (randu()*100.0) - 50.0;
121+
v = uniform( -50.0, 50.0 );
135122
console.log( 'f(%d) = %d', v, polyval( v ) );
136123
}
137124
```

lib/node_modules/@stdlib/math/base/tools/evalpoly/docs/repl.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
{{alias}}( c, x )
3-
Evaluates a polynomial.
3+
Evaluates a polynomial using double-precision floating-point arithmetic.
44

55
Parameters
66
----------
@@ -25,7 +25,8 @@
2525

2626

2727
{{alias}}.factory( c )
28-
Returns a function for evaluating a polynomial.
28+
Returns a function for evaluating a polynomial using double-precision
29+
floating-point arithmetic.
2930

3031
Parameters
3132
----------

lib/node_modules/@stdlib/math/base/tools/evalpoly/docs/types/index.d.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@
1818

1919
// TypeScript Version: 4.1
2020

21+
/// <reference types="@stdlib/types"/>
22+
23+
import { Collection } from '@stdlib/types/array';
24+
2125
/**
22-
* Evaluates a polynomial.
26+
* Evaluates a polynomial using double-precision floating-point arithmetic.
2327
*
2428
* @param x - value at which to evaluate a polynomial
2529
* @returns evaluated polynomial
@@ -31,7 +35,7 @@ type EvaluationFunction = ( x: number ) => number;
3135
*/
3236
interface EvalPoly {
3337
/**
34-
* Evaluates a polynomial.
38+
* Evaluates a polynomial using double-precision floating-point arithmetic.
3539
*
3640
* ## Notes
3741
*
@@ -48,10 +52,10 @@ interface EvalPoly {
4852
* var v = evalpoly( [3.0,2.0,1.0], 10.0 ); // 3*10^0 + 2*10^1 + 1*10^2
4953
* // returns 123.0
5054
*/
51-
( c: Array<number>, x: number ): number;
55+
( c: Collection<number>, x: number ): number;
5256

5357
/**
54-
* Generates a function for evaluating a polynomial.
58+
* Generates a function for evaluating a polynomial using double-precision floating-point arithmetic.
5559
*
5660
* ## Notes
5761
*
@@ -72,11 +76,11 @@ interface EvalPoly {
7276
* v = polyval( 5.0 ); // => 3*5^0 + 2*5^1 + 1*5^2
7377
* // returns 38.0
7478
*/
75-
factory( c: Array<number> ): EvaluationFunction;
79+
factory( c: Collection<number> ): EvaluationFunction;
7680
}
7781

7882
/**
79-
* Evaluates a polynomial.
83+
* Evaluates a polynomial using double-precision floating-point arithmetic.
8084
*
8185
* ## Notes
8286
*

lib/node_modules/@stdlib/math/base/tools/evalpoly/examples/index.js

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,46 +18,10 @@
1818

1919
'use strict';
2020

21-
var randu = require( '@stdlib/random/base/randu' );
22-
var round = require( '@stdlib/math/base/special/round' );
23-
var Float64Array = require( '@stdlib/array/float64' );
21+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
22+
var uniform = require( '@stdlib/random/base/uniform' );
2423
var evalpoly = require( './../lib' );
2524

26-
var polyval;
27-
var coef;
28-
var sign;
29-
var eqn;
30-
var v;
31-
var i;
32-
33-
// Create an array of random coefficients...
34-
coef = new Float64Array( 10 );
35-
for ( i = 0; i < coef.length; i++ ) {
36-
if ( randu() < 0.5 ) {
37-
sign = -1.0;
38-
} else {
39-
sign = 1.0;
40-
}
41-
coef[ i ] = sign * round( randu()*100.0 );
42-
}
43-
eqn = toStr( coef );
44-
console.log( 'f(x) = %s', eqn );
45-
46-
// Evaluate the polynomial at random values...
47-
for ( i = 0; i < 100; i++ ) {
48-
v = randu() * 100.0;
49-
console.log( 'f(%d) = %d', v, evalpoly( coef, v ) );
50-
}
51-
52-
// Generate an `evalpoly` function...
53-
polyval = evalpoly.factory( coef );
54-
55-
console.log( '\nf(x) = %s', eqn );
56-
for ( i = 0; i < 100; i++ ) {
57-
v = (randu()*100.0) - 50.0;
58-
console.log( 'f(%d) = %d', v, polyval( v ) );
59-
}
60-
6125
function toStr( coef ) {
6226
var str;
6327
var c;
@@ -78,3 +42,26 @@ function toStr( coef ) {
7842
}
7943
return str;
8044
}
45+
46+
// Create an array of random coefficients:
47+
var coef = discreteUniform( 10, -100, 100 );
48+
49+
// Generate a polynomial equation:
50+
var eqn = toStr( coef );
51+
console.log( 'f(x) = %s', eqn );
52+
53+
// Evaluate the polynomial at random values:
54+
var v;
55+
var i;
56+
for ( i = 0; i < 100; i++ ) {
57+
v = uniform( 0.0, 100.0 );
58+
console.log( 'f(%d) = %d', v, evalpoly( coef, v ) );
59+
}
60+
61+
// Generate an `evalpoly` function:
62+
var polyval = evalpoly.factory( coef );
63+
console.log( '\nf(x) = %s', eqn );
64+
for ( i = 0; i < 100; i++ ) {
65+
v = uniform( -50.0, 50.0 );
66+
console.log( 'f(%d) = %d', v, polyval( v ) );
67+
}

lib/node_modules/@stdlib/math/base/tools/evalpoly/lib/factory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var evalpoly = require( './main.js' );
2727
// MAIN //
2828

2929
/**
30-
* Generates a function for evaluating a polynomial.
30+
* Generates a function for evaluating a polynomial using double-precision floating-point arithmetic.
3131
*
3232
* ## Notes
3333
*

lib/node_modules/@stdlib/math/base/tools/evalpoly/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
'use strict';
2020

2121
/**
22-
* Evaluate a polynomial.
22+
* Evaluate a polynomial using double-precision floating-point arithmetic.
2323
*
2424
* @module @stdlib/math/base/tools/evalpoly
2525
*

lib/node_modules/@stdlib/math/base/tools/evalpoly/lib/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// MAIN //
2222

2323
/**
24-
* Evaluates a polynomial.
24+
* Evaluates a polynomial using double-precision floating-point arithmetic.
2525
*
2626
* ## Notes
2727
*

lib/node_modules/@stdlib/math/base/tools/evalpoly/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@stdlib/math/base/tools/evalpoly",
33
"version": "0.0.0",
4-
"description": "Evaluate a polynomial.",
4+
"description": "Evaluate a polynomial using double-precision floating-point arithmetic.",
55
"license": "Apache-2.0",
66
"author": {
77
"name": "The Stdlib Authors",

0 commit comments

Comments
 (0)