From 757ef291540979e13f0a619752de52a4da4da834 Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI <gunjjoshi8372@gmail.com> Date: Sat, 27 Jul 2024 23:32:34 +0530 Subject: [PATCH] feat: add C implementation for math/base/special/fresnelc --- .../math/base/special/fresnelc/README.md | 88 +++++++ .../fresnelc/benchmark/benchmark.native.js | 60 +++++ .../fresnelc/benchmark/c/native/Makefile | 146 +++++++++++ .../fresnelc/benchmark/c/native/benchmark.c | 136 +++++++++++ .../math/base/special/fresnelc/binding.gyp | 170 +++++++++++++ .../base/special/fresnelc/examples/c/Makefile | 146 +++++++++++ .../special/fresnelc/examples/c/example.c | 31 +++ .../math/base/special/fresnelc/include.gypi | 53 ++++ .../stdlib/math/base/special/fresnelc.h | 41 ++++ .../math/base/special/fresnelc/lib/native.js | 62 +++++ .../special/fresnelc/lib/rational_pcqc.js | 4 +- .../special/fresnelc/lib/rational_pfqf.js | 4 +- .../special/fresnelc/lib/rational_pgqg.js | 4 +- .../math/base/special/fresnelc/manifest.json | 81 ++++++ .../special/fresnelc/scripts/evalrational.js | 56 +++++ .../math/base/special/fresnelc/src/Makefile | 70 ++++++ .../math/base/special/fresnelc/src/addon.c | 23 ++ .../math/base/special/fresnelc/src/main.c | 231 ++++++++++++++++++ .../base/special/fresnelc/test/test.native.js | 186 ++++++++++++++ 19 files changed, 1586 insertions(+), 6 deletions(-) create mode 100644 lib/node_modules/@stdlib/math/base/special/fresnelc/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/fresnelc/benchmark/c/native/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/fresnelc/benchmark/c/native/benchmark.c create mode 100644 lib/node_modules/@stdlib/math/base/special/fresnelc/binding.gyp create mode 100644 lib/node_modules/@stdlib/math/base/special/fresnelc/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/fresnelc/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/math/base/special/fresnelc/include.gypi create mode 100644 lib/node_modules/@stdlib/math/base/special/fresnelc/include/stdlib/math/base/special/fresnelc.h create mode 100644 lib/node_modules/@stdlib/math/base/special/fresnelc/lib/native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/fresnelc/manifest.json create mode 100644 lib/node_modules/@stdlib/math/base/special/fresnelc/src/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/fresnelc/src/addon.c create mode 100644 lib/node_modules/@stdlib/math/base/special/fresnelc/src/main.c create mode 100644 lib/node_modules/@stdlib/math/base/special/fresnelc/test/test.native.js diff --git a/lib/node_modules/@stdlib/math/base/special/fresnelc/README.md b/lib/node_modules/@stdlib/math/base/special/fresnelc/README.md index 2663384a3d39..f5f4093eb674 100644 --- a/lib/node_modules/@stdlib/math/base/special/fresnelc/README.md +++ b/lib/node_modules/@stdlib/math/base/special/fresnelc/README.md @@ -100,6 +100,94 @@ for ( i = 0; i < x.length; i++ ) { <!-- /.examples --> +<!-- C interface documentation. --> + +* * * + +<section class="c"> + +## C APIs + +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> + +<section class="intro"> + +</section> + +<!-- /.intro --> + +<!-- C usage documentation. --> + +<section class="usage"> + +### Usage + +```c +#include "stdlib/math/base/special/fresnelc.h" +``` + +#### stdlib_base_fresnelc( x ) + +Computes the [Fresnel integral][fresnel-integral] C(x). + +```c +double out = stdlib_base_fresnelc( 0.0 ); +// returns ~0.0 + +out = stdlib_base_fresnelc( 1.0 ); +// returns ~0.780 +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. + +```c +double stdlib_base_fresnelc( const double x ); +``` + +</section> + +<!-- /.usage --> + +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> + +<section class="notes"> + +</section> + +<!-- /.notes --> + +<!-- C API usage examples. --> + +<section class="examples"> + +### Examples + +```c +#include "stdlib/math/base/special/fresnelc.h" +#include <stdio.h> + +int main( void ) { + const double x[] = { 0.0, 3.14, 5.55, 10.0 }; + + double y; + int i; + for ( i = 0; i < 4; i++ ) { + y = stdlib_base_fresnelc( x[ i ] ); + printf( "fresnelc(%lf) = %lf\n", x[ i ], y ); + } +} +``` + +</section> + +<!-- /.examples --> + +</section> + +<!-- /.c --> + <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> <section class="related"> diff --git a/lib/node_modules/@stdlib/math/base/special/fresnelc/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/fresnelc/benchmark/benchmark.native.js new file mode 100644 index 000000000000..45993819952f --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fresnelc/benchmark/benchmark.native.js @@ -0,0 +1,60 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var fresnelc = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( fresnelc instanceof Error ) +}; + + +// MAIN // + +bench( pkg+'::native', opts, function benchmark( b ) { + var x; + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = ( randu() * 20.0 ) - 10.0; + y = fresnelc( x ); + 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/fresnelc/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/fresnelc/benchmark/c/native/Makefile new file mode 100644 index 000000000000..f69e9da2b4d3 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fresnelc/benchmark/c/native/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 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/fresnelc/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/fresnelc/benchmark/c/native/benchmark.c new file mode 100644 index 000000000000..5c2b01d64064 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fresnelc/benchmark/c/native/benchmark.c @@ -0,0 +1,136 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +/** +* Benchmark `fresnelc`. +*/ +#include "stdlib/math/base/special/fresnelc.h" +#include <stdlib.h> +#include <stdio.h> +#include <math.h> +#include <time.h> +#include <sys/time.h> + +#define NAME "fresnelc" +#define ITERATIONS 1000000 +#define REPEATS 3 + +/** +* Prints the TAP version. +*/ +void print_version() { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param elapsed elapsed time in seconds +*/ +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 +*/ +double tic() { + 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 +*/ +double rand_double() { + int r = rand(); + return (double)r / ( (double)RAND_MAX + 1.0 ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +double benchmark() { + double elapsed; + double x; + double y; + double t; + int i; + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + x = ( 20.0 * rand_double() ) - 10.0; + y = stdlib_base_fresnelc( x ); + 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; + + // Use the current time to seed the random number generator: + 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/fresnelc/binding.gyp b/lib/node_modules/@stdlib/math/base/special/fresnelc/binding.gyp new file mode 100644 index 000000000000..ec3992233442 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fresnelc/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2024 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/fresnelc/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/fresnelc/examples/c/Makefile new file mode 100644 index 000000000000..6aed70daf167 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fresnelc/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 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/fresnelc/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/fresnelc/examples/c/example.c new file mode 100644 index 000000000000..150cbd5738e8 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fresnelc/examples/c/example.c @@ -0,0 +1,31 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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/fresnelc.h" +#include <stdio.h> + +int main( void ) { + const double x[] = { 0.0, 3.14, 5.55, 10.0 }; + + double y; + int i; + for ( i = 0; i < 4; i++ ) { + y = stdlib_base_fresnelc( x[ i ] ); + printf( "fresnelc(%lf) = %lf\n", x[ i ], y ); + } +} diff --git a/lib/node_modules/@stdlib/math/base/special/fresnelc/include.gypi b/lib/node_modules/@stdlib/math/base/special/fresnelc/include.gypi new file mode 100644 index 000000000000..575cb043c0bf --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fresnelc/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2024 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': [ + '<!@(node -e "var arr = require(\'@stdlib/utils/library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).include; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")', + ], + + # Add-on destination directory: + 'addon_output_dir': './src', + + # Source files: + 'src_files': [ + '<(src_dir)/addon.c', + '<!@(node -e "var arr = require(\'@stdlib/utils/library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).src; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")', + ], + + # Library dependencies: + 'libraries': [ + '<!@(node -e "var arr = require(\'@stdlib/utils/library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).libraries; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")', + ], + + # Library directories: + 'library_dirs': [ + '<!@(node -e "var arr = require(\'@stdlib/utils/library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).libpath; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")', + ], + }, # end variables +} diff --git a/lib/node_modules/@stdlib/math/base/special/fresnelc/include/stdlib/math/base/special/fresnelc.h b/lib/node_modules/@stdlib/math/base/special/fresnelc/include/stdlib/math/base/special/fresnelc.h new file mode 100644 index 000000000000..4d394d569a0a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fresnelc/include/stdlib/math/base/special/fresnelc.h @@ -0,0 +1,41 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +/** +* Header file containing function declarations. +*/ +#ifndef STDLIB_MATH_BASE_SPECIAL_FRESNELC_H +#define STDLIB_MATH_BASE_SPECIAL_FRESNELC_H + +/* +* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. +*/ +#ifdef __cplusplus +extern "C" { +#endif + +/** +* Computes the Fresnel integral C(x). +*/ +double stdlib_base_fresnelc( const double x ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_MATH_BASE_SPECIAL_FRESNELC_H diff --git a/lib/node_modules/@stdlib/math/base/special/fresnelc/lib/native.js b/lib/node_modules/@stdlib/math/base/special/fresnelc/lib/native.js new file mode 100644 index 000000000000..e8bec1db58fc --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fresnelc/lib/native.js @@ -0,0 +1,62 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 // + +/** +* Computes the Fresnel integral C(x). +* +* @private +* @param {number} x - input value +* @returns {number} C(x) +* +* @example +* var v = fresnelc( 0.0 ); +* // returns 0.0 +* +* @example +* var v = fresnelc( 1.0 ); +* // returns ~0.780 +* +* @example +* var v = fresnelc( Infinity ); +* // returns ~0.5 +* +* @example +* var v = fresnelc( -Infinity ); +* // returns ~-0.5 +* +* @example +* var v = fresnelc( NaN ); +* // returns NaN +*/ +function fresnelc( x ) { + return addon( x ); +} + + +// EXPORTS // + +module.exports = fresnelc; diff --git a/lib/node_modules/@stdlib/math/base/special/fresnelc/lib/rational_pcqc.js b/lib/node_modules/@stdlib/math/base/special/fresnelc/lib/rational_pcqc.js index 2db23f3c52f3..214173bccb3c 100644 --- a/lib/node_modules/@stdlib/math/base/special/fresnelc/lib/rational_pcqc.js +++ b/lib/node_modules/@stdlib/math/base/special/fresnelc/lib/rational_pcqc.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2022 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -22,7 +22,7 @@ // MAIN // /** -* Evaluates a rational function, i.e., the ratio of two polynomials described by the coefficients stored in \\(P\\) and \\(Q\\). +* Evaluates a rational function (i.e., the ratio of two polynomials described by the coefficients stored in \\(P\\) and \\(Q\\)). * * ## Notes * diff --git a/lib/node_modules/@stdlib/math/base/special/fresnelc/lib/rational_pfqf.js b/lib/node_modules/@stdlib/math/base/special/fresnelc/lib/rational_pfqf.js index d27b41e21a99..5049776dc1e6 100644 --- a/lib/node_modules/@stdlib/math/base/special/fresnelc/lib/rational_pfqf.js +++ b/lib/node_modules/@stdlib/math/base/special/fresnelc/lib/rational_pfqf.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2022 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -22,7 +22,7 @@ // MAIN // /** -* Evaluates a rational function, i.e., the ratio of two polynomials described by the coefficients stored in \\(P\\) and \\(Q\\). +* Evaluates a rational function (i.e., the ratio of two polynomials described by the coefficients stored in \\(P\\) and \\(Q\\)). * * ## Notes * diff --git a/lib/node_modules/@stdlib/math/base/special/fresnelc/lib/rational_pgqg.js b/lib/node_modules/@stdlib/math/base/special/fresnelc/lib/rational_pgqg.js index 74c14eb8ce57..aa1a708b6fe5 100644 --- a/lib/node_modules/@stdlib/math/base/special/fresnelc/lib/rational_pgqg.js +++ b/lib/node_modules/@stdlib/math/base/special/fresnelc/lib/rational_pgqg.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2022 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -22,7 +22,7 @@ // MAIN // /** -* Evaluates a rational function, i.e., the ratio of two polynomials described by the coefficients stored in \\(P\\) and \\(Q\\). +* Evaluates a rational function (i.e., the ratio of two polynomials described by the coefficients stored in \\(P\\) and \\(Q\\)). * * ## Notes * diff --git a/lib/node_modules/@stdlib/math/base/special/fresnelc/manifest.json b/lib/node_modules/@stdlib/math/base/special/fresnelc/manifest.json new file mode 100644 index 000000000000..cf30e3fbc204 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fresnelc/manifest.json @@ -0,0 +1,81 @@ +{ + "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/napi/unary", + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/sincos", + "@stdlib/constants/float64/pi", + "@stdlib/constants/float64/half-pi" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/sincos", + "@stdlib/constants/float64/pi", + "@stdlib/constants/float64/half-pi" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/sincos", + "@stdlib/constants/float64/pi", + "@stdlib/constants/float64/half-pi" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/fresnelc/scripts/evalrational.js b/lib/node_modules/@stdlib/math/base/special/fresnelc/scripts/evalrational.js index 17a970cc1639..884103f5a938 100644 --- a/lib/node_modules/@stdlib/math/base/special/fresnelc/scripts/evalrational.js +++ b/lib/node_modules/@stdlib/math/base/special/fresnelc/scripts/evalrational.js @@ -24,10 +24,15 @@ // MODULES // var resolve = require( 'path' ).resolve; +var readFileSync = require( '@stdlib/fs/read-file' ).sync; var writeFileSync = require( '@stdlib/fs/write-file' ).sync; var currentYear = require( '@stdlib/time/current-year' ); var licenseHeader = require( '@stdlib/_tools/licenses/header' ); var compile = require( '@stdlib/math/base/tools/evalrational-compile' ); +var compileC = require( '@stdlib/math/base/tools/evalrational-compile-c' ); +var substringBefore = require( '@stdlib/string/substring-before' ); +var substringAfter = require( '@stdlib/string/substring-after' ); +var format = require( '@stdlib/string/format' ); // VARIABLES // @@ -123,6 +128,33 @@ var header = licenseHeader( 'Apache-2.0', 'js', { header += '\n/* This is a generated file. Do not edit directly. */\n'; +// FUNCTIONS // + +/** +* Inserts a compiled function into file content. +* +* @private +* @param {string} text - source content +* @param {string} id - function identifier +* @param {string} str - function string +* @returns {string} updated content +*/ +function insert( text, id, str ) { + var before; + var after; + var begin; + var end; + + begin = '// BEGIN: '+id; + end = '// END: '+id; + + before = substringBefore( text, begin ); + after = substringAfter( text, end ); + + return format( '%s// BEGIN: %s\n\n%s\n%s%s', before, id, str, end, after ); +} + + // MAIN // /** @@ -132,7 +164,9 @@ header += '\n/* This is a generated file. Do not edit directly. */\n'; */ function main() { var fpath; + var copts; var opts; + var file; var str; opts = { @@ -150,6 +184,28 @@ function main() { fpath = resolve( __dirname, '..', 'lib', 'rational_pgqg.js' ); str = header + compile( PG, QG ); writeFileSync( fpath, str, opts ); + + copts = { + 'dtype': 'double', + 'name': '' + }; + + fpath = resolve( __dirname, '..', 'src', 'main.c' ); + file = readFileSync( fpath, opts ); + + copts.name = 'rational_pcqc'; + str = compileC( PC, QC, copts ); + file = insert( file, copts.name, str ); + + copts.name = 'rational_pfqf'; + str = compileC( PF, QF, copts ); + file = insert( file, copts.name, str ); + + copts.name = 'rational_pgqg'; + str = compileC( PG, QG, copts ); + file = insert( file, copts.name, str ); + + writeFileSync( fpath, file, opts ); } main(); diff --git a/lib/node_modules/@stdlib/math/base/special/fresnelc/src/Makefile b/lib/node_modules/@stdlib/math/base/special/fresnelc/src/Makefile new file mode 100644 index 000000000000..bcf18aa46655 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fresnelc/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 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/fresnelc/src/addon.c b/lib/node_modules/@stdlib/math/base/special/fresnelc/src/addon.c new file mode 100644 index 000000000000..82caf74008e2 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fresnelc/src/addon.c @@ -0,0 +1,23 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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/fresnelc.h" +#include "stdlib/math/base/napi/unary.h" + +// cppcheck-suppress shadowFunction +STDLIB_MATH_BASE_NAPI_MODULE_D_D( stdlib_base_fresnelc ) diff --git a/lib/node_modules/@stdlib/math/base/special/fresnelc/src/main.c b/lib/node_modules/@stdlib/math/base/special/fresnelc/src/main.c new file mode 100644 index 000000000000..bd562eda9f26 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fresnelc/src/main.c @@ -0,0 +1,231 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +* +* +* ## Notice +* +* The original C code, long comment, copyright, license, and constants are from [Cephes]{@link http://www.netlib.org/cephes}. The implementation follows the original, but has been modified for JavaScript. +* +* ```text +* Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier +* +* Some software in this archive may be from the book _Methods and Programs for Mathematical Functions_ (Prentice-Hall or Simon & Schuster International, 1989) or from the Cephes Mathematical Library, a commercial product. In either event, it is copyrighted by the author. What you see here may be used freely but it comes with no support or guarantee. +* +* Stephen L. Moshier +* moshier@na-net.ornl.gov +* ``` +*/ + +#include "stdlib/math/base/special/fresnelc.h" +#include "stdlib/math/base/special/abs.h" +#include "stdlib/math/base/special/sincos.h" +#include "stdlib/constants/float64/pi.h" +#include "stdlib/constants/float64/half_pi.h" + +/* Begin auto-generated functions. The following functions are auto-generated. Do not edit directly. */ + +// BEGIN: rational_pcqc + +/** +* Evaluates a rational function (i.e., the ratio of two polynomials described by the coefficients stored in \\(P\\) and \\(Q\\)). +* +* ## Notes +* +* - Coefficients should be sorted in ascending degree. +* - 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 rational function +* @return evaluated rational function +*/ +static double rational_pcqc( const double x ) { + double ax; + double ix; + double s1; + double s2; + if ( x == 0.0 ) { + return 1.0; + } + if ( x < 0.0 ) { + ax = -x; + } else { + ax = x; + } + if ( ax <= 1.0 ) { + s1 = 1.0 + (x * (-0.20552590095501388 + (x * (0.018884331939670384 + (x * (-0.0006451914356839651 + (x * (0.000009504280628298596 + (x * (-4.9884311457357354e-8 + (x * 0.0))))))))))); + s2 = 1.0 + (x * (0.04121420907221998 + (x * (0.0008680295429417843 + (x * (0.000012226278902417902 + (x * (1.2500186247959882e-7 + (x * (9.154392157746574e-10 + (x * 3.99982968972496e-12))))))))))); + } else { + ix = 1.0 / x; + s1 = 0.0 + (ix * (-4.9884311457357354e-8 + (ix * (0.000009504280628298596 + (ix * (-0.0006451914356839651 + (ix * (0.018884331939670384 + (ix * (-0.20552590095501388 + (ix * 1.0))))))))))); + s2 = 3.99982968972496e-12 + (ix * (9.154392157746574e-10 + (ix * (1.2500186247959882e-7 + (ix * (0.000012226278902417902 + (ix * (0.0008680295429417843 + (ix * (0.04121420907221998 + (ix * 1.0))))))))))); + } + return s1 / s2; +} + +// END: rational_pcqc + +// BEGIN: rational_pfqf + +/** +* Evaluates a rational function (i.e., the ratio of two polynomials described by the coefficients stored in \\(P\\) and \\(Q\\)). +* +* ## Notes +* +* - Coefficients should be sorted in ascending degree. +* - 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 rational function +* @return evaluated rational function +*/ +static double rational_pfqf( const double x ) { + double ax; + double ix; + double s1; + double s2; + if ( x == 0.0 ) { + return 2.999999999999634; + } + if ( x < 0.0 ) { + ax = -x; + } else { + ax = x; + } + if ( ax <= 1.0 ) { + s1 = 3.763297112699879e-20 + (x * (1.3428327623306275e-16 + (x * (1.7201074326816183e-13 + (x * (1.0230451416490724e-10 + (x * (3.055689837902576e-8 + (x * (0.0000046361374928786735 + (x * (0.000345017939782574 + (x * (0.011522095507358577 + (x * (0.1434079197807589 + (x * (0.4215435550436775 + (x * 0.0))))))))))))))))))); + s2 = 1.2544323709001127e-20 + (x * (4.5200143407412973e-17 + (x * (5.887545336215784e-14 + (x * (3.6014002958937136e-11 + (x * (1.1269922476399903e-8 + (x * (0.0000018462756734893055 + (x * (0.00015593440916415301 + (x * (0.0064405152650885865 + (x * (0.11688892585919138 + (x * (0.7515863983533789 + (x * 1.0))))))))))))))))))); + } else { + ix = 1.0 / x; + s1 = 0.0 + (ix * (0.4215435550436775 + (ix * (0.1434079197807589 + (ix * (0.011522095507358577 + (ix * (0.000345017939782574 + (ix * (0.0000046361374928786735 + (ix * (3.055689837902576e-8 + (ix * (1.0230451416490724e-10 + (ix * (1.7201074326816183e-13 + (ix * (1.3428327623306275e-16 + (ix * 3.763297112699879e-20))))))))))))))))))); + s2 = 1.0 + (ix * (0.7515863983533789 + (ix * (0.11688892585919138 + (ix * (0.0064405152650885865 + (ix * (0.00015593440916415301 + (ix * (0.0000018462756734893055 + (ix * (1.1269922476399903e-8 + (ix * (3.6014002958937136e-11 + (ix * (5.887545336215784e-14 + (ix * (4.5200143407412973e-17 + (ix * 1.2544323709001127e-20))))))))))))))))))); + } + return s1 / s2; +} + +// END: rational_pfqf + +// BEGIN: rational_pgqg + +/** +* Evaluates a rational function (i.e., the ratio of two polynomials described by the coefficients stored in \\(P\\) and \\(Q\\)). +* +* ## Notes +* +* - Coefficients should be sorted in ascending degree. +* - 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 rational function +* @return evaluated rational function +*/ +static double rational_pgqg( const double x ) { + double ax; + double ix; + double s1; + double s2; + if ( x == 0.0 ) { + return 1.0; + } + if ( x < 0.0 ) { + ax = -x; + } else { + ax = x; + } + if ( ax <= 1.0 ) { + s1 = 1.8695871016278324e-22 + (x * (8.363544356306774e-19 + (x * (1.375554606332618e-15 + (x * (1.0826804113902088e-12 + (x * (4.4534441586175015e-10 + (x * (9.828524436884223e-8 + (x * (0.000011513882611188428 + (x * (0.0006840793809153931 + (x * (0.018764858409257526 + (x * (0.1971028335255234 + (x * (0.5044420736433832 + (x * 0.0))))))))))))))))))))); + s2 = 1.8695871016278324e-22 + (x * (8.391588162831187e-19 + (x * (1.3879653125957886e-15 + (x * (1.1027321506624028e-12 + (x * (4.6068072814652043e-10 + (x * (1.0431458965757199e-7 + (x * (0.000012754507566772912 + (x * (0.0008146791071843061 + (x * (0.02536037414203388 + (x * (0.33774898912002 + (x * (1.4749575992512833 + (x * 1.0))))))))))))))))))))); + } else { + ix = 1.0 / x; + s1 = 0.0 + (ix * (0.5044420736433832 + (ix * (0.1971028335255234 + (ix * (0.018764858409257526 + (ix * (0.0006840793809153931 + (ix * (0.000011513882611188428 + (ix * (9.828524436884223e-8 + (ix * (4.4534441586175015e-10 + (ix * (1.0826804113902088e-12 + (ix * (1.375554606332618e-15 + (ix * (8.363544356306774e-19 + (ix * 1.8695871016278324e-22))))))))))))))))))))); + s2 = 1.0 + (ix * (1.4749575992512833 + (ix * (0.33774898912002 + (ix * (0.02536037414203388 + (ix * (0.0008146791071843061 + (ix * (0.000012754507566772912 + (ix * (1.0431458965757199e-7 + (ix * (4.6068072814652043e-10 + (ix * (1.1027321506624028e-12 + (ix * (1.3879653125957886e-15 + (ix * (8.391588162831187e-19 + (ix * 1.8695871016278324e-22))))))))))))))))))))); + } + return s1 / s2; +} + +// END: rational_pgqg + +/* End auto-generated functions. */ + +/** +* Computes the Fresnel integral C(x). +* +* ## Method +* +* Evaluates the Fresnel integral +* +* ```tex +* \operatorname{C}(x) = \int_0^x \cos\left(\frac{\pi}{2} t^2\right)\,\mathrm{d}t. +* ``` +* +* The integral is evaluated by a power series for \\( x < 1 \\). For \\( x >= 1 \\) auxiliary functions \\( f(x) \\) and \\( g(x) \\) are employed such that +* +* ```tex +* \operatorname{C}(x) = \frac{1}{2} + f(x) \sin\left( \frac{\pi}{2} x^2 \right) - g(x) \cos\left( \frac{\pi}{2} x^2 \right). +* ``` +* +* ## Notes +* +* - Relative error on test interval \\( \[0,10\] \\): +* +* | arithmetic | function | # trials | peak | rms | +* |:----------:|:--------:|:--------:|:-------:|:-------:| +* | IEEE | C(x) | 10000 | 1.8e-15 | 3.3e-16 | +* +* @example +* double v = stdlib_base_fresnelc( 1.0 ); +* // returns ~0.780 +*/ +double stdlib_base_fresnelc( const double x ) { + double x2; + double xa; + double C; + double f; + double g; + double t; + double u; + double s; + double c; + + xa = stdlib_base_abs( x ); + x2 = xa * xa; + if ( x2 < 2.5625 ) { + t = x2 * x2; + C = xa * rational_pcqc( t ); + } else if ( xa > 36974.0 ) { + C = 0.5; + } else { + // Asymptotic power series auxiliary functions for large arguments... + x2 = xa * xa; + t = STDLIB_CONSTANT_FLOAT64_PI * x2; + u = 1.0 / ( t * t ); + t = 1.0 / t; + f = 1.0 - ( u * rational_pfqf( u ) ); + g = t * rational_pgqg( u ); + t = STDLIB_CONSTANT_FLOAT64_HALF_PI * x2; + stdlib_base_sincos( t, &s, &c ); + t = STDLIB_CONSTANT_FLOAT64_PI * xa; + C = 0.5 + ( ( ( f * s ) - ( g * c ) ) / t ); + } + if ( x < 0.0 ) { + C = -C; + } + return C; +} + diff --git a/lib/node_modules/@stdlib/math/base/special/fresnelc/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/fresnelc/test/test.native.js new file mode 100644 index 000000000000..d17700c06dc4 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fresnelc/test/test.native.js @@ -0,0 +1,186 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var randu = require( '@stdlib/random/base/randu' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var fresnelc = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( fresnelc instanceof Error ) +}; + + +// FIXTURES // + +var smallPositive = require( './fixtures/c/cephes/small.json' ); +var mediumPositive = require( './fixtures/c/cephes/medium.json' ); +var largePositive = require( './fixtures/c/cephes/large.json' ); +var hugePositive = require( './fixtures/c/cephes/huge.json' ); + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof fresnelc, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function computes the Fresnel integral C(x) (small positive values)', opts, function test( t ) { + var delta; + var tol; + var C; + var x; + var y; + var i; + + x = smallPositive.x; + C = smallPositive.C; + + for ( i = 0; i < x.length; i++ ) { + y = fresnelc( x[i] ); + if ( y === C[ i ] ) { + t.equal( y, C[ i ], 'x: '+x[i]+'. Expected: '+C[i] ); + } else { + delta = abs( y - C[i] ); + tol = 4.0 * EPS * abs( C[i] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. Expected: '+C[i]+'. tol: '+tol+'. delta: '+delta+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes the Fresnel integral C(x) (medium positive values)', opts, function test( t ) { + var delta; + var tol; + var C; + var x; + var y; + var i; + + x = mediumPositive.x; + C = mediumPositive.C; + + for ( i = 0; i < x.length; i++ ) { + y = fresnelc( x[i] ); + if ( y === C[ i ] ) { + t.equal( y, C[ i ], 'x: '+x[i]+'. Expected: '+C[i] ); + } else { + delta = abs( y - C[i] ); + tol = 1.5 * EPS * abs( C[i] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. Expected: '+C[i]+'. tol: '+tol+'. delta: '+delta+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes the Fresnel integral C(x) (large positive values)', opts, function test( t ) { + var delta; + var tol; + var C; + var x; + var y; + var i; + + x = largePositive.x; + C = largePositive.C; + + for ( i = 0; i < x.length; i++ ) { + y = fresnelc( x[i] ); + if ( y === C[ i ] ) { + t.equal( y, C[ i ], 'x: '+x[i]+'. Expected: '+C[i] ); + } else { + delta = abs( y - C[i] ); + tol = 1.5 * EPS * abs( C[i] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. Expected: '+C[i]+'. tol: '+tol+'. delta: '+delta+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes the Fresnel integral C(x) (very large positive values)', opts, function test( t ) { + var delta; + var tol; + var C; + var x; + var y; + var i; + + x = hugePositive.x; + C = hugePositive.C; + + for ( i = 0; i < x.length; i++ ) { + y = fresnelc( x[i] ); + if ( y === C[ i ] ) { + t.equal( y, C[ i ], 'x: '+x[i]+'. Expected: '+C[i] ); + } else { + delta = abs( y - C[i] ); + tol = 1.5 * EPS * abs( C[i] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. Expected: '+C[i]+'. tol: '+tol+'. delta: '+delta+'.' ); + } + } + t.end(); +}); + +tape( 'the function is an odd function of x', opts, function test( t ) { + var yn; + var yp; + var x; + var i; + + for ( i = 0; i < 500; i++ ) { + x = randu() * 10000.0; + yn = fresnelc( -x ); + yp = fresnelc( x ); + + t.equal( yp, -yn, 'C(x) = -C(-x)' ); + } + t.end(); +}); + +tape( 'the function returns `0.5` if provided `+infinity`', opts, function test( t ) { + var v = fresnelc( PINF ); + t.equal( v, 0.5, 'returns 0.5' ); + t.end(); +}); + +tape( 'the function returns `-0.5` if provided `-infinity`', opts, function test( t ) { + var v = fresnelc( NINF ); + t.equal( v, -0.5, 'returns -0.5' ); + t.end(); +}); + +tape( 'the function returns `NaN` if provided a `NaN`', opts, function test( t ) { + var v = fresnelc( NaN ); + t.equal( isnan( v ), true, 'returns expected value' ); + t.end(); +});