Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stdlib-js/math-base-tools-evalpoly-compile-c
Compile a C function for evaluating a polynomial.
https://github.com/stdlib-js/math-base-tools-evalpoly-compile-c
c compile eval evalpoly evaluate horner javascript math mathematics native node node-js nodejs poly polynomial polyval stdlib
Last synced: 3 months ago
JSON representation
Compile a C function for evaluating a polynomial.
- Host: GitHub
- URL: https://github.com/stdlib-js/math-base-tools-evalpoly-compile-c
- Owner: stdlib-js
- License: apache-2.0
- Created: 2022-12-11T02:08:15.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-01T03:14:10.000Z (3 months ago)
- Last Synced: 2024-11-11T06:44:56.834Z (3 months ago)
- Topics: c, compile, eval, evalpoly, evaluate, horner, javascript, math, mathematics, native, node, node-js, nodejs, poly, polynomial, polyval, stdlib
- Language: JavaScript
- Homepage: https://github.com/stdlib-js/stdlib
- Size: 179 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Citation: CITATION.cff
- Security: SECURITY.md
Awesome Lists containing this project
README
About stdlib...
We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.
The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.
When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.
To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!
# evalpoly
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url]
> Compile a C function for evaluating a [polynomial][@stdlib/math/base/tools/evalpoly].
## Installation
```bash
npm install @stdlib/math-base-tools-evalpoly-compile-c
```## Usage
```javascript
var compile = require( '@stdlib/math-base-tools-evalpoly-compile-c' );
```#### compile( c\[, options] )
Compiles a C function for evaluating a [polynomial][@stdlib/math/base/tools/evalpoly] having coefficients `c`.
```javascript
var str = compile( [ 3.0, 2.0, 1.0 ] );
// returns
```The function supports the following `options`:
- **dtype**: input argument floating-point data type (e.g., `double` or `float`). Default: `'double'`.
- **name**: function name. Default: `'evalpoly'`.In the example above, the output string would correspond to the following function:
```c
/**
* Evaluates a polynomial.
*
* ## Notes
*
* - The implementation uses [Horner's rule][horners-method] for efficient computation.
*
* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method
*
* @param x value at which to evaluate the polynomial
* @return evaluated polynomial
*/
static double evalpoly( const double x ) {
return 3.0 + (x * (2.0 + (x * 1.0)));
}
```To generate a function having a custom name and supporting single-precision floating-point numbers, provide the corresponding options.
```javascript
var opts = {
'dtype': 'float',
'name': 'polyval123'
};
var str = compile( [ 3.0, 2.0, 1.0 ], opts );
// returns
```For the previous example, the output string would correspond to the following function:
```c
/**
* Evaluates a polynomial.
*
* ## Notes
*
* - The implementation uses [Horner's rule][horners-method] for efficient computation.
*
* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method
*
* @param x value at which to evaluate the polynomial
* @return evaluated polynomial
*/
static float polyval123( const float x ) {
return 3.0f + (x * (2.0f + (x * 1.0f)));
}
```## Notes
- The coefficients should be ordered in **ascending** degree, thus matching summation notation.
- The function is intended for **non-browser** environments for the purpose of generating functions for inclusion in source files.## Examples
```javascript
var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
var compile = require( '@stdlib/math-base-tools-evalpoly-compile-c' );// Create an array of random coefficients:
var coef = discreteUniform( 10, -100, 100 );// Compile a function for evaluating a polynomial:
var str = compile( coef );
console.log( str );
```* * *
## Notice
This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib].
#### Community
[![Chat][chat-image]][chat-url]
---
## Copyright
Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
[npm-image]: http://img.shields.io/npm/v/@stdlib/math-base-tools-evalpoly-compile-c.svg
[npm-url]: https://npmjs.org/package/@stdlib/math-base-tools-evalpoly-compile-c[test-image]: https://github.com/stdlib-js/math-base-tools-evalpoly-compile-c/actions/workflows/test.yml/badge.svg?branch=main
[test-url]: https://github.com/stdlib-js/math-base-tools-evalpoly-compile-c/actions/workflows/test.yml?query=branch:main[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/math-base-tools-evalpoly-compile-c/main.svg
[coverage-url]: https://codecov.io/github/stdlib-js/math-base-tools-evalpoly-compile-c?branch=main[chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
[chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im[stdlib]: https://github.com/stdlib-js/stdlib
[stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
[@stdlib/math/base/tools/evalpoly]: https://github.com/stdlib-js/math-base-tools-evalpoly