diff --git a/lib/node_modules/@stdlib/math/base/special/polevl/README.md b/lib/node_modules/@stdlib/math/base/special/polevl/README.md new file mode 100644 index 000000000000..0e904b024e5b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/polevl/README.md @@ -0,0 +1,191 @@ + + +# polevl + +> Evaluate a polynomial using Horner's rule. + +
+ +## Usage + +```javascript +var polevl = require( '@stdlib/math/base/special/polevl' ); +``` + +#### polevl( x, coef, N ) + +Evaluates a polynomial using Horner's rule. + +The function accepts the following arguments: + +- **x**: `number` - input value. +- **coef**: `Collection` - polynomial coefficients. +- **N**: `number` - degree of the polynomial. + +```javascript +var coef = [ 1.0, 2.0, 3.0 ]; // Represents 1 + 2x + 3x^2 +var v = polevl( 2.0, coef, 2 ); +// returns 17.0 ( 1 + 2 * ( 2 ) + 3 * ( 2^2 ) = 1 + 4 + 12 = 17 ) + +v = polevl( 0.0, [ 5.0, -2.0 ], 1 ); +// returns 5.0 ( 5 - 2*0 = 5 ) + +v = polevl( 1.0, [ 1.0, 1.0, 1.0, 1.0 ], 3 ); +// returns 4.0 ( 1 + 1 + 1 + 1 = 4 ) + +v = polevl( NaN, coef, 2 ); +// returns NaN +``` + +
+ + + +
+ +

Examples

+ + + +```javascript +var polevl = require( '@stdlib/math/base/special/polevl' ); + +var coef = [ 1.0, 2.0, 3.0, 4.0 ]; // 1 + 2x + 3x^2 + 4x^3 +var x = 2.0; +var v = polevl( x, coef, 3 ); +console.log( 'polevl(%d, [ %s ], %d) = %d', x, coef.join( ', ' ), 3, v ); +// => 'polevl(2, [ 1, 2, 3, 4 ], 3) = 49' +``` + +
+ + + + + +* * * + +
+ +

C APIs

+ + + +
+ +
+ + + + + +
+ +

Usage

+ +```c +#include "stdlib/math/base/special/polevl.h" +``` + +#### stdlib_base_polevl( x, coef, N ) + +Evaluates a polynomial using Horner's rule. + +```c +#include // For printf +#include "stdlib/math/base/special/polevl.h" + +double coef[] = { 1.0, 2.0, 3.0 }; // Represents 1 + 2x + 3x^2 +double v = stdlib_base_polevl( 2.0, coef, 2 ); +// returns 17.0 + +printf( "polevl( %lf, [ %lf, %lf, %lf ], %d ) = %lf\n", 2.0, coef[0], coef[1], coef[2], 2, v ); +// => polevl( 2.000000, [ 1.000000, 2.000000, 3.000000 ], 2 ) = 17.000000 +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. +- **coef**: `[in] const double*` polynomial coefficients. +- **N**: `[in] int` degree of the polynomial. + +```c +double stdlib_base_polevl( const double x, const double coef[], const int N ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +

Examples

+ +```c +#include "stdlib/math/base/special/polevl.h" +#include // For printf + +int main( void ) { + double x[] = { 1.0, 2.0, 3.0 }; + double coef[] = { 1.0, 2.0, 3.0, 4.0 }; // 1 + 2x + 3x^2 + 4x^3 + double v; + int i; + + for ( i = 0; i < 3; i++ ) { + v = stdlib_base_polevl( x[ i ], coef, 3 ); + printf( "polevl(%lf, [ %lf, %lf, %lf, %lf ], %d) = %lf\n", x[ i ], coef[0], coef[1], coef[2], coef[3], 3, v ); + } +} +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/math/base/special/polevl/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/polevl/benchmark/benchmark.js new file mode 100644 index 000000000000..18e54bdb5a63 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/polevl/benchmark/benchmark.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pkg = require( './../package.json' ).name; +var polevl = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var coef = [ 1.0, 2.0, 3.0 ]; + var x; + var y; + var i; + var N = 2; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = ( randu() * 4.0 ) - 2.0; // x in [-2, 2] + y = polevl( x, coef, N ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/polevl/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/polevl/benchmark/benchmark.native.js new file mode 100644 index 000000000000..3188c9d799fd --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/polevl/benchmark/benchmark.native.js @@ -0,0 +1,65 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +// Try to load native implementation: +var polevl = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( polevl instanceof Error ) +}; + + +// MAIN // + +bench( format( '%s::native', pkg ), opts, function benchmark( b ) { + var coef = [ 1.0, 2.0, 3.0 ]; + var x; + var y; + var i; + var N = 2; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = ( randu() * 4.0 ) - 2.0; // x in [-2, 2] + y = polevl( x, coef, N ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/polevl/benchmark/c/Makefile b/lib/node_modules/@stdlib/math/base/special/polevl/benchmark/c/Makefile new file mode 100644 index 000000000000..979768abbcec --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/polevl/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/polevl/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/special/polevl/benchmark/c/benchmark.c new file mode 100644 index 000000000000..0a30dbf6d5e1 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/polevl/benchmark/c/benchmark.c @@ -0,0 +1,137 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/polevl.h" +#include +#include +#include +#include + +#define NAME "polevl" +#define ITERATIONS 1000000 +#define REPEATS 3 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmark results. +* +* @param elapsed elapsed time in seconds +*/ +static void print_results( double elapsed ) { + double rate = (double)ITERATIONS / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec / 1.0e6; +} + +/** +* Generates a random number on the interval [0,1). +* +* @return random number +*/ +static double rand_double( void ) { + int r = rand(); + return (double)r / ( (double)RAND_MAX + 1.0 ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + double elapsed; + double x; + double y; + double t; + int i; + + /* Example polynomial: 1 + 2x + 3x^2 + 4x^3 */ + const double coef[] = { 1.0, 2.0, 3.0, 4.0 }; + const int N = 3; + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + x = ( 2.0 * rand_double() ) - 1.0; + y = stdlib_base_polevl( x, coef, N ); + if ( y != y ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + + if ( y != y ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int i; + + /* Seed RNG */ + srand( time( NULL ) ); + + print_version(); + for ( i = 0; i < REPEATS; i++ ) { + printf( "# c::native::%s\n", NAME ); + elapsed = benchmark(); + print_results( elapsed ); + printf( "ok %d benchmark finished\n", i+1 ); + } + print_summary( REPEATS, REPEATS ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/polevl/binding.gyp b/lib/node_modules/@stdlib/math/base/special/polevl/binding.gyp new file mode 100644 index 000000000000..0d6508a12e99 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/polevl/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/math/base/special/polevl/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/polevl/docs/repl.txt new file mode 100644 index 000000000000..b98c1bea6b54 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/polevl/docs/repl.txt @@ -0,0 +1,39 @@ +{{alias}}( x, coef, N ) + Evaluates a polynomial using Horner's rule. + + The polynomial is defined by the coefficients `coef` such that + + p(x) = coef[0] + coef[1]·x + coef[2]·x² + … + coef[N]·xᴺ + + For best performance, coefficients should be provided as a + `Float64Array`. + + Parameters + ---------- + x: number + Input value. + coef: Collection + Polynomial coefficients in ascending order of degree. + N: nonnegative integer + Degree of the polynomial. Must satisfy `N < coef.length`. + + Returns + ------- + y: number + Polynomial value. + + Examples + -------- + > var coef = [ 1.0, 2.0, 3.0 ]; + > var y = {{alias}}( 2.0, coef, 2 ) + 17.0 + + > var coef = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + > y = {{alias}}( 0.5, coef, 2 ) + 2.75 + + > y = {{alias}}( NaN, coef, 2 ) + NaN + + See Also + -------- diff --git a/lib/node_modules/@stdlib/math/base/special/polevl/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/polevl/docs/types/index.d.ts new file mode 100644 index 000000000000..57430c031374 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/polevl/docs/types/index.d.ts @@ -0,0 +1,59 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/** +* Evaluates a polynomial using Horner's rule. +* +* The polynomial is defined by the coefficients `coef` such that +* +* p(x) = coef[0] + coef[1]·x + ... + coef[N]·x^N +* +* For best performance, coefficients should be provided as a +* `Float64Array`. +* +* @param x - input value +* @param coef - polynomial coefficients in ascending order of degree +* @param N - degree of the polynomial +* @returns polynomial value +* +* @example +* var coef = [ 1.0, 2.0, 3.0 ]; +* var y = polevl( 2.0, coef, 2 ); +* // returns 17.0 +* +* @example +* var coef = new Float64Array( [ 1.0, 2.0, 3.0 ] ); +* var y = polevl( 0.5, coef, 2 ); +* // returns 2.75 +* +* @example +* var y = polevl( NaN, coef, 2 ); +* // returns NaN +*/ +declare function polevl( + x: number, + coef: ArrayLike, + N: number +): number; + + +// EXPORTS // + +export = polevl; diff --git a/lib/node_modules/@stdlib/math/base/special/polevl/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/polevl/docs/types/test.ts new file mode 100644 index 000000000000..cd3a15168535 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/polevl/docs/types/test.ts @@ -0,0 +1,65 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import polevl = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const coef = [ 1.0, 2.0, 3.0 ]; + polevl( 2.0, coef, 2 ); // $ExpectType number +} + +{ + const coef = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + polevl( 0.5, coef, 2 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided invalid arguments... +{ + polevl( true, [ 1, 2 ], 1 ); // $ExpectError + polevl( false, [ 1, 2 ], 1 ); // $ExpectError + polevl( null, [ 1, 2 ], 1 ); // $ExpectError + polevl( undefined, [ 1, 2 ], 1 ); // $ExpectError + polevl( '5', [ 1, 2 ], 1 ); // $ExpectError +} + +{ + polevl( 1.0, true, 1 ); // $ExpectError + polevl( 1.0, false, 1 ); // $ExpectError + polevl( 1.0, null, 1 ); // $ExpectError + polevl( 1.0, undefined, 1 ); // $ExpectError + polevl( 1.0, {}, 1 ); // $ExpectError +} + +{ + polevl( 1.0, [ 1, 2 ], true ); // $ExpectError + polevl( 1.0, [ 1, 2 ], false ); // $ExpectError + polevl( 1.0, [ 1, 2 ], null ); // $ExpectError + polevl( 1.0, [ 1, 2 ], undefined ); // $ExpectError + polevl( 1.0, [ 1, 2 ], '2' ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + polevl(); // $ExpectError + polevl( 1.0 ); // $ExpectError + polevl( 1.0, [ 1, 2 ] ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/math/base/special/polevl/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/polevl/examples/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/polevl/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/polevl/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/polevl/examples/c/example.c new file mode 100644 index 000000000000..d6a4e99dff85 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/polevl/examples/c/example.c @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/polevl.h" +#include + +int main( void ) { + /* Polynomial coefficients: + * p(x) = 1 + 2x + 3x^2 + */ + const double coef[] = { 1.0, 2.0, 3.0 }; + const int N = 2; + + const double x[] = { + -1.5, -1.0, -0.5, 0.0, 0.5, + 1.0, 1.5, 2.0, -2.0, 0.25 + }; + + double v; + int i; + + for ( i = 0; i < 10; i++ ) { + v = stdlib_base_polevl( x[ i ], coef, N ); + printf( "polevl(%lf) = %lf\n", x[ i ], v ); + } + + return 0; +} diff --git a/lib/node_modules/@stdlib/math/base/special/polevl/examples/index.js b/lib/node_modules/@stdlib/math/base/special/polevl/examples/index.js new file mode 100644 index 000000000000..c092b3dfd4a1 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/polevl/examples/index.js @@ -0,0 +1,40 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var polevl = require( './../lib' ); + +// Polynomial coefficients (constant-first order): + +// p(x) = 1 + 2x + 3x^2 + +var coef = [ 1.0, 2.0, 3.0 ]; +var N = 2; + +var x = uniform( 100, -2.0, 2.0, { + 'dtype': 'float64' +}); + +function map( v ) { + return polevl( v, coef, N ); +} + +logEachMap( 'polevl(%lf) = %lf', x, map ); diff --git a/lib/node_modules/@stdlib/math/base/special/polevl/include.gypi b/lib/node_modules/@stdlib/math/base/special/polevl/include.gypi new file mode 100644 index 000000000000..bee8d41a2caf --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/polevl/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A GYP include file for building a Node.js native add-on. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + '} coef - polynomial coefficients +* @param {number} N - degree of the polynomial +* +* @throws {TypeError} if the first argument is not a number +* @throws {TypeError} if the second argument is not a collection +* @throws {TypeError} if the third argument is not a non-negative integer +* @throws {RangeError} if the degree is greater than or equal to the number of coefficients +* +* @returns {number} polynomial value +* +* @example +* var coef = [ 1.0, 2.0, 3.0 ]; +* var v = polevl( 2.0, coef, 2 ); +* // returns 17.0 ( 1 + 2 * ( 2 ) + 3 * ( 2^2 ) ) +*/ +function polevl( x, coef, N ) { + var ans; + var i; + if ( !isNumber( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a number. Value: `%s`.', x ) ); + } + if ( isNaN( x ) ) { + return NaN; + } + if ( !isCollection( coef ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', coef ) ); + } + if ( !isNonNegativeInteger( N ) ) { + throw new TypeError( format( 'invalid argument. Third argument must be a non-negative integer. Value: `%s`.', N ) ); + } + if ( N >= coef.length ) { + throw new RangeError( format( 'invalid argument. Third argument must be less than the number of coefficients. Value: `%s`.', N ) ); + } + + ans = coef[ N ]; + for ( i = N-1; i >= 0; i-- ) { + ans = ( ans * x ) + coef[ i ]; + } + return ans; +} + + +// EXPORTS // + +module.exports = polevl; diff --git a/lib/node_modules/@stdlib/math/base/special/polevl/lib/native.js b/lib/node_modules/@stdlib/math/base/special/polevl/lib/native.js new file mode 100644 index 000000000000..7f8a79662bda --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/polevl/lib/native.js @@ -0,0 +1,44 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Evaluates a polynomial using Horner's rule. +* +* @private +* @param {number} x - input value +* @param {Collection} coef - polynomial coefficients +* @param {number} N - degree of the polynomial +* @returns {number} polynomial value +*/ +function polevl( x, coef, N ) { + return addon( x, coef, N ); +} + + +// EXPORTS // + +module.exports = polevl; diff --git a/lib/node_modules/@stdlib/math/base/special/polevl/manifest.json b/lib/node_modules/@stdlib/math/base/special/polevl/manifest.json new file mode 100644 index 000000000000..d9a42575a2fc --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/polevl/manifest.json @@ -0,0 +1,72 @@ +{ + "options": { + "task": "build" + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "task": "build", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nan" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nan" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nan" + ] + } + ] +} + diff --git a/lib/node_modules/@stdlib/math/base/special/polevl/package.json b/lib/node_modules/@stdlib/math/base/special/polevl/package.json new file mode 100644 index 000000000000..c485fe47e802 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/polevl/package.json @@ -0,0 +1,135 @@ +{ + "name": "@stdlib/math/base/special/polevl", + "version": "0.0.0", + "description": "Evaluate a polynomial using Horner's rule.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "gypfile": true, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "src": "./src", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "polynomial", + "horner", + "evaluation", + "poly", + "approximation", + "numerical" + ], + "__stdlib__": { + "scaffold": { + "$schema": "math/base@v1.0", + "base_alias": "polevl", + "alias": "polevl", + "pkg_desc": "evaluate a polynomial using Horner's rule", + "desc": "evaluates a polynomial using Horner's rule", + "short_desc": "polynomial evaluation", + "parameters": [ + { + "name": "x", + "desc": "input value", + "type": { + "javascript": "number", + "jsdoc": "number", + "c": "double", + "dtype": "float64" + }, + "rand": { + "prng": "random/base/normal", + "parameters": [ + 0, + 1 + ] + } + }, + { + "name": "coef", + "desc": "polynomial coefficients in ascending order of degree", + "type": { + "javascript": "Collection", + "jsdoc": "Collection", + "c": "double*", + "dtype": "float64" + } + }, + { + "name": "N", + "desc": "degree of the polynomial", + "type": { + "javascript": "number", + "jsdoc": "number", + "c": "int", + "dtype": "int32" + } + } + ], + "output_policy": "real_floating_point_and_generic", + "returns": { + "desc": "polynomial value", + "type": { + "javascript": "number", + "jsdoc": "number", + "c": "double", + "dtype": "float64" + } + }, + "keywords": [ + "polynomial", + "horner", + "evaluation" + ], + "extra_keywords": [ + "poly", + "approximation", + "numerical" + ] + } + } +} diff --git a/lib/node_modules/@stdlib/math/base/special/polevl/src/Makefile b/lib/node_modules/@stdlib/math/base/special/polevl/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/polevl/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/polevl/src/addon.c b/lib/node_modules/@stdlib/math/base/special/polevl/src/addon.c new file mode 100644 index 000000000000..8cf49384f1b9 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/polevl/src/addon.c @@ -0,0 +1,184 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include +#include +#include "stdlib/math/base/special/polevl.h" + +/** +* Evaluates a polynomial using Horner's rule. +* +* @param env environment +* @param info callback info +* @return result +*/ +static napi_value polevl_wrapper( napi_env env, napi_callback_info info ) { + napi_status status; + size_t argc = 3; + napi_value argv[3]; + + status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL ); + if ( status != napi_ok || argc < 3 ) { + napi_throw_error( env, NULL, "Expected three arguments." ); + return NULL; + } + + /* x */ + double x; + status = napi_get_value_double( env, argv[0], &x ); + if ( status != napi_ok ) { + napi_throw_type_error( env, NULL, "First argument must be a number." ); + return NULL; + } + + /* N */ + double Nd; + status = napi_get_value_double( env, argv[2], &Nd ); + if ( status != napi_ok ) { + napi_throw_type_error( + env, + NULL, + "Third argument must be a non-negative integer." + ); + return NULL; + } + + if ( Nd < 0 || Nd != (int32_t)Nd ) { + napi_throw_type_error( + env, + NULL, + "Third argument must be a non-negative integer." + ); + return NULL; + } + + int32_t N = (int32_t)Nd; + + + /* coef: prefer typed arrays */ + bool is_typedarray; + status = napi_is_typedarray( env, argv[1], &is_typedarray ); + if ( status == napi_ok && is_typedarray ) { + napi_typedarray_type type; + size_t length; + void *data; + napi_value buffer; + size_t offset; + + status = napi_get_typedarray_info( + env, + argv[1], + &type, + &length, + &data, + &buffer, + &offset + ); + if ( status != napi_ok || type != napi_float64_array ) { + napi_throw_type_error( env, NULL, "Coefficients must be a Float64Array." ); + return NULL; + } + if ( (size_t)N >= length ) { + napi_throw_range_error( + env, + NULL, + "Polynomial degree exceeds number of coefficients." + ); + return NULL; + } + + double result = stdlib_base_polevl( x, (double *)data, N ); + + napi_value out; + napi_create_double( env, result, &out ); + return out; + } + + /* Fallback: regular JS array */ + bool is_array; + status = napi_is_array( env, argv[1], &is_array ); + if ( status != napi_ok || !is_array ) { + napi_throw_type_error( + env, + NULL, + "Second argument must be an array or Float64Array." + ); + return NULL; + } + + uint32_t len; + status = napi_get_array_length( env, argv[1], &len ); + if ( status != napi_ok || (uint32_t)N >= len ) { + napi_throw_range_error( + env, + NULL, + "Polynomial degree exceeds number of coefficients." + ); + return NULL; + } + + double *coef = (double *)malloc( len * sizeof( double ) ); + if ( coef == NULL ) { + napi_throw_error( env, NULL, "Memory allocation failed." ); + return NULL; + } + + for ( uint32_t i = 0; i < len; i++ ) { + napi_value el; + double v; + + napi_get_element( env, argv[1], i, &el ); + if ( napi_get_value_double( env, el, &v ) != napi_ok ) { + free( coef ); + napi_throw_type_error( + env, + NULL, + "Coefficient array must contain only numbers." + ); + return NULL; + } + coef[i] = v; + } + + double result = stdlib_base_polevl( x, coef, N ); + free( coef ); + + napi_value out; + napi_create_double( env, result, &out ); + return out; +} + +/** +* Initialize module. +*/ +static napi_value napi_init( napi_env env, napi_value exports ) { + napi_status status; + napi_value fn; + + status = napi_create_function( env, NULL, 0, polevl_wrapper, NULL, &fn ); + if ( status != napi_ok ) { + napi_throw_error( env, NULL, "Failed to create function." ); + return NULL; + } + + /* Export the function itself */ + return fn; +} + + +NAPI_MODULE( NODE_GYP_MODULE_NAME, napi_init ) diff --git a/lib/node_modules/@stdlib/math/base/special/polevl/src/main.c b/lib/node_modules/@stdlib/math/base/special/polevl/src/main.c new file mode 100644 index 000000000000..6b8baff544d6 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/polevl/src/main.c @@ -0,0 +1,49 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/polevl.h" +#include "stdlib/math/base/assert/is_nan.h" + +/** +* Evaluates a polynomial using Horner's rule. +* +* @param x input value +* @param coef polynomial coefficients +* @param N degree of the polynomial +* @return polynomial value +* +* @example +* double coef[] = { 1.0, 2.0, 3.0 }; +* double v = stdlib_base_polevl( 2.0, coef, 2 ); +* // returns 17.0 +*/ +double stdlib_base_polevl( const double x, const double coef[], const int N ) { + double ans; + int i; + + // Check for NaN input for x + if ( stdlib_base_is_nan( x ) ) { + return 0.0 / 0.0; // NaN + } + + ans = coef[ N ]; + for ( i = N-1; i >= 0 ; i-- ) { + ans = ( ans * x ) + coef[ i ]; + } + return ans; +} diff --git a/lib/node_modules/@stdlib/math/base/special/polevl/test/fixtures/julia/REQUIRE b/lib/node_modules/@stdlib/math/base/special/polevl/test/fixtures/julia/REQUIRE new file mode 100644 index 000000000000..308c3be89c85 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/polevl/test/fixtures/julia/REQUIRE @@ -0,0 +1,2 @@ +julia 1.5 +JSON 0.21 diff --git a/lib/node_modules/@stdlib/math/base/special/polevl/test/fixtures/julia/data.json b/lib/node_modules/@stdlib/math/base/special/polevl/test/fixtures/julia/data.json new file mode 100644 index 000000000000..7fca609ace29 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/polevl/test/fixtures/julia/data.json @@ -0,0 +1 @@ +{"expected":[2620.2984289713886,20.98845328148904,-3.5183571248811045,-2.9602135142939994,-3.154939402786495,-1.5841814082938241,333.6851221329879,6201.8721215489295,90145.79841307453,106.28549311498297,2.467724710020524,2.0662996373617437,1.9133408707728625,2.428695622590063,458.42337461607724,42983.6125886691,-2633.4722266722692,-28.4377738221701,-0.6391158114650867,-1.4839225577969584,-1.5236353872867936,0.3743222738253571,70.92321311777242,1134.6079180775605,-8.700322892356236e6,-659.5069123876277,0.8007238149904692,0.487257638906559,0.8512177016501852,-2.879580571059152,-40796.693483486146,-1.0623399507269766e7,-16.041698281481352,-3.6725290725965207,-0.2758640151048608,0.9104374783539071,2.1629620264764586,3.7812603275902803,9.288852540846161,19.731505939719348],"N":[8,8,8,8,8,8,8,8,10,10,10,10,10,10,10,10,7,7,7,7,7,7,7,7,14,14,14,14,14,14,14,14,4,4,4,4,4,4,4,4],"x":[-3.0,-1.5,-0.5,0.0,0.5,1.0,2.0,3.0,-3.0,-1.5,-0.5,0.0,0.5,1.0,2.0,3.0,-3.0,-1.5,-0.5,0.0,0.5,1.0,2.0,3.0,-3.0,-1.5,-0.5,0.0,0.5,1.0,2.0,3.0,-3.0,-1.5,-0.5,0.0,0.5,1.0,2.0,3.0],"coef":[[-2.9602135142939994,0.5496326834643882,-1.740717249444954,-0.6486043419700135,0.38540910262804595,-0.6084447788667934,2.108998936457157,0.8936910593215357,0.4360666944108091],[-2.9602135142939994,0.5496326834643882,-1.740717249444954,-0.6486043419700135,0.38540910262804595,-0.6084447788667934,2.108998936457157,0.8936910593215357,0.4360666944108091],[-2.9602135142939994,0.5496326834643882,-1.740717249444954,-0.6486043419700135,0.38540910262804595,-0.6084447788667934,2.108998936457157,0.8936910593215357,0.4360666944108091],[-2.9602135142939994,0.5496326834643882,-1.740717249444954,-0.6486043419700135,0.38540910262804595,-0.6084447788667934,2.108998936457157,0.8936910593215357,0.4360666944108091],[-2.9602135142939994,0.5496326834643882,-1.740717249444954,-0.6486043419700135,0.38540910262804595,-0.6084447788667934,2.108998936457157,0.8936910593215357,0.4360666944108091],[-2.9602135142939994,0.5496326834643882,-1.740717249444954,-0.6486043419700135,0.38540910262804595,-0.6084447788667934,2.108998936457157,0.8936910593215357,0.4360666944108091],[-2.9602135142939994,0.5496326834643882,-1.740717249444954,-0.6486043419700135,0.38540910262804595,-0.6084447788667934,2.108998936457157,0.8936910593215357,0.4360666944108091],[-2.9602135142939994,0.5496326834643882,-1.740717249444954,-0.6486043419700135,0.38540910262804595,-0.6084447788667934,2.108998936457157,0.8936910593215357,0.4360666944108091],[2.0662996373617437,-0.7592005926965013,0.43939860057675634,0.8162053131330971,0.11628494138209385,0.14176567308128823,0.5726069599076365,-0.22410107668752574,-0.7701914778448508,-1.1758976201657452,1.2055252645420702],[2.0662996373617437,-0.7592005926965013,0.43939860057675634,0.8162053131330971,0.11628494138209385,0.14176567308128823,0.5726069599076365,-0.22410107668752574,-0.7701914778448508,-1.1758976201657452,1.2055252645420702],[2.0662996373617437,-0.7592005926965013,0.43939860057675634,0.8162053131330971,0.11628494138209385,0.14176567308128823,0.5726069599076365,-0.22410107668752574,-0.7701914778448508,-1.1758976201657452,1.2055252645420702],[2.0662996373617437,-0.7592005926965013,0.43939860057675634,0.8162053131330971,0.11628494138209385,0.14176567308128823,0.5726069599076365,-0.22410107668752574,-0.7701914778448508,-1.1758976201657452,1.2055252645420702],[2.0662996373617437,-0.7592005926965013,0.43939860057675634,0.8162053131330971,0.11628494138209385,0.14176567308128823,0.5726069599076365,-0.22410107668752574,-0.7701914778448508,-1.1758976201657452,1.2055252645420702],[2.0662996373617437,-0.7592005926965013,0.43939860057675634,0.8162053131330971,0.11628494138209385,0.14176567308128823,0.5726069599076365,-0.22410107668752574,-0.7701914778448508,-1.1758976201657452,1.2055252645420702],[2.0662996373617437,-0.7592005926965013,0.43939860057675634,0.8162053131330971,0.11628494138209385,0.14176567308128823,0.5726069599076365,-0.22410107668752574,-0.7701914778448508,-1.1758976201657452,1.2055252645420702],[2.0662996373617437,-0.7592005926965013,0.43939860057675634,0.8162053131330971,0.11628494138209385,0.14176567308128823,0.5726069599076365,-0.22410107668752574,-0.7701914778448508,-1.1758976201657452,1.2055252645420702],[-1.4839225577969584,-0.9856975012205669,1.5805526890539079,0.06905767309269586,0.3907716165457809,1.159326649930976,-1.0889241521004813,0.7331578563200031],[-1.4839225577969584,-0.9856975012205669,1.5805526890539079,0.06905767309269586,0.3907716165457809,1.159326649930976,-1.0889241521004813,0.7331578563200031],[-1.4839225577969584,-0.9856975012205669,1.5805526890539079,0.06905767309269586,0.3907716165457809,1.159326649930976,-1.0889241521004813,0.7331578563200031],[-1.4839225577969584,-0.9856975012205669,1.5805526890539079,0.06905767309269586,0.3907716165457809,1.159326649930976,-1.0889241521004813,0.7331578563200031],[-1.4839225577969584,-0.9856975012205669,1.5805526890539079,0.06905767309269586,0.3907716165457809,1.159326649930976,-1.0889241521004813,0.7331578563200031],[-1.4839225577969584,-0.9856975012205669,1.5805526890539079,0.06905767309269586,0.3907716165457809,1.159326649930976,-1.0889241521004813,0.7331578563200031],[-1.4839225577969584,-0.9856975012205669,1.5805526890539079,0.06905767309269586,0.3907716165457809,1.159326649930976,-1.0889241521004813,0.7331578563200031],[-1.4839225577969584,-0.9856975012205669,1.5805526890539079,0.06905767309269586,0.3907716165457809,1.159326649930976,-1.0889241521004813,0.7331578563200031],[0.487257638906559,0.20211457361752885,1.608982058827721,-0.6397689270694465,-0.60847036545146,0.025833596736764716,-1.617563868381585,0.07086438723157226,0.03721598932355398,1.5217682096429785,0.07752469844181058,-0.20313927978226476,-1.374729135513188,-0.5994082426792753,-1.868061904910422],[0.487257638906559,0.20211457361752885,1.608982058827721,-0.6397689270694465,-0.60847036545146,0.025833596736764716,-1.617563868381585,0.07086438723157226,0.03721598932355398,1.5217682096429785,0.07752469844181058,-0.20313927978226476,-1.374729135513188,-0.5994082426792753,-1.868061904910422],[0.487257638906559,0.20211457361752885,1.608982058827721,-0.6397689270694465,-0.60847036545146,0.025833596736764716,-1.617563868381585,0.07086438723157226,0.03721598932355398,1.5217682096429785,0.07752469844181058,-0.20313927978226476,-1.374729135513188,-0.5994082426792753,-1.868061904910422],[0.487257638906559,0.20211457361752885,1.608982058827721,-0.6397689270694465,-0.60847036545146,0.025833596736764716,-1.617563868381585,0.07086438723157226,0.03721598932355398,1.5217682096429785,0.07752469844181058,-0.20313927978226476,-1.374729135513188,-0.5994082426792753,-1.868061904910422],[0.487257638906559,0.20211457361752885,1.608982058827721,-0.6397689270694465,-0.60847036545146,0.025833596736764716,-1.617563868381585,0.07086438723157226,0.03721598932355398,1.5217682096429785,0.07752469844181058,-0.20313927978226476,-1.374729135513188,-0.5994082426792753,-1.868061904910422],[0.487257638906559,0.20211457361752885,1.608982058827721,-0.6397689270694465,-0.60847036545146,0.025833596736764716,-1.617563868381585,0.07086438723157226,0.03721598932355398,1.5217682096429785,0.07752469844181058,-0.20313927978226476,-1.374729135513188,-0.5994082426792753,-1.868061904910422],[0.487257638906559,0.20211457361752885,1.608982058827721,-0.6397689270694465,-0.60847036545146,0.025833596736764716,-1.617563868381585,0.07086438723157226,0.03721598932355398,1.5217682096429785,0.07752469844181058,-0.20313927978226476,-1.374729135513188,-0.5994082426792753,-1.868061904910422],[0.487257638906559,0.20211457361752885,1.608982058827721,-0.6397689270694465,-0.60847036545146,0.025833596736764716,-1.617563868381585,0.07086438723157226,0.03721598932355398,1.5217682096429785,0.07752469844181058,-0.20313927978226476,-1.374729135513188,-0.5994082426792753,-1.868061904910422],[0.9104374783539071,2.3381581940969727,0.13326372403608402,0.4026713899373864,-0.0032704588340699303],[0.9104374783539071,2.3381581940969727,0.13326372403608402,0.4026713899373864,-0.0032704588340699303],[0.9104374783539071,2.3381581940969727,0.13326372403608402,0.4026713899373864,-0.0032704588340699303],[0.9104374783539071,2.3381581940969727,0.13326372403608402,0.4026713899373864,-0.0032704588340699303],[0.9104374783539071,2.3381581940969727,0.13326372403608402,0.4026713899373864,-0.0032704588340699303],[0.9104374783539071,2.3381581940969727,0.13326372403608402,0.4026713899373864,-0.0032704588340699303],[0.9104374783539071,2.3381581940969727,0.13326372403608402,0.4026713899373864,-0.0032704588340699303],[0.9104374783539071,2.3381581940969727,0.13326372403608402,0.4026713899373864,-0.0032704588340699303]]} diff --git a/lib/node_modules/@stdlib/math/base/special/polevl/test/fixtures/julia/runner.jl b/lib/node_modules/@stdlib/math/base/special/polevl/test/fixtures/julia/runner.jl new file mode 100644 index 000000000000..51840b6466c9 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/polevl/test/fixtures/julia/runner.jl @@ -0,0 +1,69 @@ +#!/usr/bin/env julia +# +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import JSON +using Random +using Polynomials + +""" + gen( filepath ) + +Generate fixture data for `polevl` using Julia's polynomial evaluation. +""" +function gen( filepath ) + # Reproducibility: + Random.seed!( 123456 ) + + # Evaluation points: + xs = [ -3.0, -1.5, -0.5, 0.0, 0.5, 1.0, 2.0, 3.0 ] + + results = Float64[] + inputs_x = Float64[] + inputs_coef = Vector{Vector{Float64}}() + inputs_N = Int[] + + for k in 1:5 + N = rand( 0:20 ) + coef = randn( N+1 ) + p = Polynomial( coef ) + + for x in xs + y = p( x ) + + push!( results, y ) + push!( inputs_x, x ) + push!( inputs_coef, coef ) + push!( inputs_N, N ) + end + end + + data = Dict( + "x" => inputs_x, + "coef" => inputs_coef, + "N" => inputs_N, + "expected" => results + ) + + open( filepath, "w" ) do io + write( io, JSON.json( data ) ) + write( io, "\n" ) + end +end + +dir = dirname( @__FILE__ ) +gen( joinpath( dir, "data.json" ) ) diff --git a/lib/node_modules/@stdlib/math/base/special/polevl/test/test.js b/lib/node_modules/@stdlib/math/base/special/polevl/test/test.js new file mode 100644 index 000000000000..de8c61806517 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/polevl/test/test.js @@ -0,0 +1,113 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); +var polevl = require( './../lib' ); // polevl function from lib/index.js + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof polevl, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function evaluates a polynomial using Horner\'s rule (fixtures)', function test( t ) { + var expected; + var actual; + var coef; + var x; + var N; + var i; + + x = data.x; + coef = data.coef; + N = data.N; + expected = data.expected; + + for ( i = 0; i < x.length; i++ ) { + actual = polevl( x[ i ], coef[ i ], N[ i ] ); + t.ok( isAlmostSameValue( actual, expected[ i ], 100.0 ), 'within tolerance. x: '+x[ i ]+'. coef: '+JSON.stringify( coef[ i ] )+'. N: '+N[ i ]+'. actual: '+actual+'. expected: '+expected[ i ]+'.' ); + } + t.end(); +}); + +tape( 'the function returns `NaN` if provided `NaN` for x', function test( t ) { + var coef = [ 1.0, 2.0, 3.0 ]; + var v = polevl( NaN, coef, 2 ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.end(); +}); + +tape( 'the function throws an error if provided a non-number for x', function test( t ) { + var coef = [ 1.0, 2.0, 3.0 ]; + t.throws(function foo() { + polevl( 'abc', coef, 2 ); + }, TypeError, 'throws TypeError'); + t.throws(function foo() { + polevl( null, coef, 2 ); + }, TypeError, 'throws TypeError'); + t.end(); +}); + +tape( 'the function throws an error if provided a non-collection for coef', function test( t ) { + var x = 2.0; + t.throws(function foo() { + polevl( x, 123, 2 ); + }, TypeError, 'throws TypeError'); + t.throws(function foo() { + polevl( x, {}, 2 ); + }, TypeError, 'throws TypeError'); + t.end(); +}); + +tape( 'the function throws an error if provided a non-non-negative integer for N', function test( t ) { + var coef = [ 1.0, 2.0, 3.0 ]; + var x = 2.0; + t.throws(function foo() { + polevl( x, coef, 2.5 ); + }, TypeError, 'throws TypeError for float'); + t.throws(function foo() { + polevl( x, coef, -1 ); + }, TypeError, 'throws TypeError for negative'); + t.throws(function foo() { + polevl( x, coef, '2' ); + }, TypeError, 'throws TypeError for string'); + t.end(); +}); + +tape( 'the function throws an error if N is out of bounds', function test( t ) { + var coef = [ 1.0, 2.0, 3.0 ]; + var x = 2.0; // N can be 0, 1, 2 + t.throws(function foo() { + polevl( x, coef, 3 ); // N=3 is out of bounds (coef.length-1) + }, RangeError, 'throws RangeError for N >= coef.length'); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/polevl/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/polevl/test/test.native.js new file mode 100644 index 000000000000..f3c92b12a003 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/polevl/test/test.native.js @@ -0,0 +1,122 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var polevl = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( polevl instanceof Error ) +}; + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof polevl, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function evaluates a polynomial using Horner\'s rule (fixtures)', opts, function test( t ) { + var expected; + var actual; + var coef; + var x; + var N; + var i; + + x = data.x; + coef = data.coef; + N = data.N; + expected = data.expected; + + for ( i = 0; i < x.length; i++ ) { + actual = polevl( x[ i ], coef[ i ], N[ i ] ); + t.ok( isAlmostSameValue( actual, expected[ i ], 100.0 ), 'within tolerance. x: '+x[ i ]+'. coef: '+JSON.stringify( coef[ i ] )+'. N: '+N[ i ]+'. actual: '+actual+'. expected: '+expected[ i ]+'.' ); + } + t.end(); +}); + +tape( 'the function returns `NaN` if provided `NaN` for x', opts, function test( t ) { + var coef = [ 1.0, 2.0, 3.0 ]; + var v = polevl( NaN, coef, 2 ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.end(); +}); + +tape( 'the function throws an error if provided a non-number for x', opts, function test( t ) { + var coef = [ 1.0, 2.0, 3.0 ]; + t.throws(function foo() { + polevl( 'abc', coef, 2 ); + }, TypeError, 'throws TypeError'); + t.throws(function foo() { + polevl( null, coef, 2 ); + }, TypeError, 'throws TypeError'); + t.end(); +}); + +tape( 'the function throws an error if provided a non-array for coef', opts, function test( t ) { + var x = 2.0; + t.throws(function foo() { + polevl( x, 123, 2 ); + }, TypeError, 'throws TypeError'); + t.throws(function foo() { + polevl( x, {}, 2 ); + }, TypeError, 'throws TypeError'); + t.end(); +}); + +tape( 'the function throws an error if provided a non-integer for N', opts, function test( t ) { + var coef = [ 1.0, 2.0, 3.0 ]; + var x = 2.0; + t.throws(function foo() { + polevl( x, coef, 2.5 ); + }, TypeError, 'throws TypeError for float'); + t.throws(function foo() { + polevl( x, coef, -1 ); + }, TypeError, 'throws TypeError for negative'); + t.throws(function foo() { + polevl( x, coef, '2' ); + }, TypeError, 'throws TypeError for string'); + t.end(); +}); + +tape( 'the function throws an error if N is out of bounds', opts, function test( t ) { + var coef = [ 1.0, 2.0, 3.0 ]; + var x = 2.0; // N can be 0, 1, 2 + t.throws(function foo() { + polevl( x, coef, 3 ); // N=3 is out of bounds (coef.length-1) + }, RangeError, 'throws RangeError for N >= coef.length'); + t.end(); +});