Evaluates a polynomial.
$ npm install math-evalpoly
var evalpoly = ;
evalpoly( c, x )
Evaluates a polynomial having coefficients
c and degree
n at a value
n = c.length-1.
var v = ;// returns 123 => 3*10^0 + 2*10^1 + 1*10^2
The coefficients should be ordered in ascending degree. For example, for a polynomial
the coefficients would be
[c_0, c_1, ..., c_(n-1), c_n]
matching the summation notation.
evalpoly.factory( c )
Uses code generation to in-line coefficients and return a reusable
function for evaluating a polynomial.
var poly = evalpoly;var v = ;// returns 123 => 3*10^0 + 2*10^1 + 1*10^2v = ;// returns 38 => 3*5^0 + 2*5^1 + 1*5^2
Note: For hot code paths in which coefficients are invariant, the generated
function will be more performant than the main export.
var round = ;var evalpoly = ;var coef;var sign;var poly;var v;var i;// Create an array of random coefficients...coef = 10 ;for i = 0; i < coeflength; i++if Math < 05sign = -1;elsesign = 1;coef i = sign * ;// Evaluate the polynomial at random values...for i = 0; i < 100; i++v = Math * 100;console;// Generate an `evalpoly` function...poly = evalpoly;for i = 0; i < 100; i++v = Math*100 - 50;console;
To run the example code from the top-level application directory,
$ node ./examples/index.js
This repository uses tape for unit tests. To run the tests, execute the following command in the top-level application directory:
$ make test
All new feature development should have corresponding unit tests to validate correct functionality.
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
$ make test-cov
Istanbul creates a
./reports/coverage directory. To access an HTML version of the report,
$ make view-cov
This repository uses Testling for browser testing. To run the tests in a (headless) local web browser, execute the following command in the top-level application directory:
$ make test-browsers
To view the tests in a local web browser,
$ make view-browser-tests
Copyright © 2016. The Compute.io Authors..