diff --git a/lib/node_modules/@stdlib/math/base/special/sincos/README.md b/lib/node_modules/@stdlib/math/base/special/sincos/README.md index 5bd005b7ba55..6463c58b40b6 100644 --- a/lib/node_modules/@stdlib/math/base/special/sincos/README.md +++ b/lib/node_modules/@stdlib/math/base/special/sincos/README.md @@ -88,6 +88,96 @@ 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/sincos.h" +``` + +#### stdlib_base_sincos( x, &sine, &cosine ) + +Simultaneously computes the [sine][@stdlib/math/base/special/sin] and [cosine][@stdlib/math/base/special/cos] of a `number` (in radians). + +```c +double cosine; +double sine; + +stdlib_base_sincos( 4.0, &sine, &cosine ); +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. +- **sine**: `[out] double*` destination for the sine. +- **cosine**: `[out] double*` destination for the cosine. + +```c +void stdlib_base_sincos( const double x, double *sine, double *cosine ); +``` + +</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/sincos.h" +#include <stdio.h> + +int main( void ) { + const double x[] = { 0.0, 1.57, 3.14, 6.28 }; + + double cosine; + double sine; + int i; + for ( i = 0; i < 4; i++ ) { + stdlib_base_sincos( x[ i ], &sine, &cosine ); + printf( "x: %lf => sine: %lf, cosine: %lf\n", x[ i ], sine, cosine ); + } +} +``` + +</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/sincos/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/sincos/benchmark/benchmark.native.js new file mode 100644 index 000000000000..b8f6bd11373c --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sincos/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 sincos = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( sincos 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 = sincos( x ); + if ( isnan( y[ 0 ] ) || isnan( y[ 1 ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y[ 0 ] ) || isnan( y[ 1 ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/sincos/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/sincos/benchmark/c/native/Makefile new file mode 100644 index 000000000000..f69e9da2b4d3 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sincos/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/sincos/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/sincos/benchmark/c/native/benchmark.c new file mode 100644 index 000000000000..a4e08da57b89 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sincos/benchmark/c/native/benchmark.c @@ -0,0 +1,137 @@ +/** +* @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 `sincos`. +*/ +#include "stdlib/math/base/special/sincos.h" +#include <stdlib.h> +#include <stdio.h> +#include <math.h> +#include <time.h> +#include <sys/time.h> + +#define NAME "sincos" +#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 cosine; + double sine; + double x; + double t; + int i; + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + x = ( 20.0 * rand_double() ) - 10.0; + stdlib_base_sincos( x, &sine, &cosine ); + if ( cosine != cosine || sine != sine) { + printf( "unexpected results\n" ); + break; + } + } + elapsed = tic() - t; + if ( cosine != cosine || sine != sine) { + printf( "unexpected results\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/sincos/binding.gyp b/lib/node_modules/@stdlib/math/base/special/sincos/binding.gyp new file mode 100644 index 000000000000..ec3992233442 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sincos/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/sincos/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/sincos/examples/c/Makefile new file mode 100644 index 000000000000..6aed70daf167 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sincos/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/sincos/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/sincos/examples/c/example.c new file mode 100644 index 000000000000..c76ed0f88949 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sincos/examples/c/example.c @@ -0,0 +1,32 @@ +/** +* @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/sincos.h" +#include <stdio.h> + +int main( void ) { + const double x[] = { 0.0, 1.57, 3.14, 6.28 }; + + double cosine; + double sine; + int i; + for ( i = 0; i < 4; i++ ) { + stdlib_base_sincos( x[ i ], &sine, &cosine ); + printf( "x: %lf => sine: %lf, cosine: %lf\n", x[ i ], sine, cosine ); + } +} diff --git a/lib/node_modules/@stdlib/math/base/special/sincos/include.gypi b/lib/node_modules/@stdlib/math/base/special/sincos/include.gypi new file mode 100644 index 000000000000..575cb043c0bf --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sincos/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/sincos/include/stdlib/math/base/special/sincos.h b/lib/node_modules/@stdlib/math/base/special/sincos/include/stdlib/math/base/special/sincos.h new file mode 100644 index 000000000000..97228ca31d56 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sincos/include/stdlib/math/base/special/sincos.h @@ -0,0 +1,38 @@ +/** +* @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. +*/ + +#ifndef STDLIB_MATH_BASE_SPECIAL_SINCOS_H +#define STDLIB_MATH_BASE_SPECIAL_SINCOS_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 + +/** +* Simultaneously computes the sine and cosine of a number. +*/ +void stdlib_base_sincos( const double x, double *sine, double *cosine ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_MATH_BASE_SPECIAL_SINCOS_H diff --git a/lib/node_modules/@stdlib/math/base/special/sincos/lib/assign.js b/lib/node_modules/@stdlib/math/base/special/sincos/lib/assign.js index 39170a106688..412b19af212e 100644 --- a/lib/node_modules/@stdlib/math/base/special/sincos/lib/assign.js +++ b/lib/node_modules/@stdlib/math/base/special/sincos/lib/assign.js @@ -97,6 +97,7 @@ var Y = [ 0.0, 0.0 ]; * // returns [ NaN, NaN ] */ function sincos( x, out, stride, offset ) { + var tmp; var ix; var n; @@ -128,9 +129,9 @@ function sincos( x, out, stride, offset ) { switch ( n & 3 ) { case 1: - ix = out[ offset + stride ]; + tmp = out[ offset + stride ]; out[ offset + stride ] = -out[ offset ]; - out[ offset ] = ix; + out[ offset ] = tmp; return out; case 2: out[ offset ] *= -1; @@ -138,9 +139,9 @@ function sincos( x, out, stride, offset ) { return out; case 3: // Passing - ix = -out[ offset + stride ]; + tmp = -out[ offset + stride ]; out[ offset + stride ] = out[ offset ]; - out[ offset ] = ix; + out[ offset ] = tmp; return out; default: return out; diff --git a/lib/node_modules/@stdlib/math/base/special/sincos/lib/native.js b/lib/node_modules/@stdlib/math/base/special/sincos/lib/native.js new file mode 100644 index 000000000000..aaebc7e5c2f8 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sincos/lib/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 Float64Array = require( '@stdlib/array/float64' ); +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Simultaneously computes the sine and cosine of a number. +* +* @param {number} x - input value (in radians) +* @returns {Array<number>} sine and cosine +* +* @example +* var v = sincos( 0.0 ); +* // returns <Float64Array>[ ~0.0, ~1.0 ] +* +* @example +* var v = sincos( 3.141592653589793 / 2.0 ); +* // returns <Float64Array>[ ~1.0, ~0.0 ] +* +* @example +* var v = sincos( -3.141592653589793 / 6.0 ); +* // returns <Float64Array>[ ~-0.5, ~0.866 ] +* +* @example +* var v = sincos( NaN ); +* // returns <Float64Array>[ NaN, NaN ] +*/ +function sincos( x ) { + var out = new Float64Array( 2 ); + addon( x, out ); + return out; +} + + +// EXPORTS // + +module.exports = sincos; diff --git a/lib/node_modules/@stdlib/math/base/special/sincos/manifest.json b/lib/node_modules/@stdlib/math/base/special/sincos/manifest.json new file mode 100644 index 000000000000..45918c065001 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sincos/manifest.json @@ -0,0 +1,84 @@ +{ + "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/napi/argv", + "@stdlib/napi/argv-double", + "@stdlib/napi/argv-float64array", + "@stdlib/napi/export", + "@stdlib/math/base/special/rempio2", + "@stdlib/number/float64/base/get-high-word", + "@stdlib/constants/float64/high-word-exponent-mask", + "@stdlib/constants/float64/high-word-abs-mask" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/special/rempio2", + "@stdlib/number/float64/base/get-high-word", + "@stdlib/constants/float64/high-word-exponent-mask", + "@stdlib/constants/float64/high-word-abs-mask" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/special/rempio2", + "@stdlib/number/float64/base/get-high-word", + "@stdlib/constants/float64/high-word-exponent-mask", + "@stdlib/constants/float64/high-word-abs-mask" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/sincos/src/Makefile b/lib/node_modules/@stdlib/math/base/special/sincos/src/Makefile new file mode 100644 index 000000000000..bcf18aa46655 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sincos/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/sincos/src/addon.c b/lib/node_modules/@stdlib/math/base/special/sincos/src/addon.c new file mode 100644 index 000000000000..f676ac66b087 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sincos/src/addon.c @@ -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. +*/ + +#include "stdlib/math/base/special/sincos.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_double.h" +#include "stdlib/napi/argv_float64array.h" +#include "stdlib/napi/export.h" +#include <node_api.h> + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 2 ); + STDLIB_NAPI_ARGV_DOUBLE( env, x, argv, 0 ); + STDLIB_NAPI_ARGV_FLOAT64ARRAY( env, y, ylen, argv, 1 ); + stdlib_base_sincos( x, &y[ 0 ], &y[ 1 ] ); + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/math/base/special/sincos/src/main.c b/lib/node_modules/@stdlib/math/base/special/sincos/src/main.c new file mode 100644 index 000000000000..f5bf17ad1595 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sincos/src/main.c @@ -0,0 +1,163 @@ +/** +* @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/sincos.h" +#include "stdlib/constants/float64/high_word_abs_mask.h" +#include "stdlib/constants/float64/high_word_exponent_mask.h" +#include "stdlib/number/float64/base/get_high_word.h" +#include "stdlib/math/base/special/rempio2.h" +#include <stdint.h> + +static const double S1 = -1.66666666666666324348e-01; // 0xBFC55555, 0x55555549 +static const double S2 = 8.33333333332248946124e-03; // 0x3F811111, 0x1110F8A6 +static const double S3 = -1.98412698298579493134e-04; // 0xBF2A01A0, 0x19C161D5 +static const double S4 = 2.75573137070700676789e-06; // 0x3EC71DE3, 0x57B1FE7D +static const double S5 = -2.50507602534068634195e-08; // 0xBE5AE5E6, 0x8A2B9CEB +static const double S6 = 1.58969099521155010221e-10; // 0x3DE5D93A, 0x5ACFD57C +static const double C1 = 4.16666666666666019037e-02; // 0x3FA55555, 0x5555554C +static const double C2 = -1.38888888888741095749e-03; // 0xBF56C16C, 0x16C15177 +static const double C3 = 2.48015872894767294178e-05; // 0x3EFA01A0, 0x19CB1590 +static const double C4 = -2.75573143513906633035e-07; // 0xBE927E4F, 0x809C52AD +static const double C5 = 2.08757232129817482790e-09; // 0x3E21EE9E, 0xBDB4B1C4 +static const double C6 = -1.13596475577881948265e-11; // 0xBDA8FAE9, 0xBE8838D4 + +// High word for PI/4: 0x3fe921fb = 1072243195 => 00111111111010010010000111111011 +static const int32_t PIO4_HIGH_WORD = 0x3fe921fb; + +// The smaller of the two cutoffs for the sine and cosine kernels: 2^-27 = 0x3e400000 => 00111110010000000000000000000000 +static const int32_t SMALL_HIGH_WORD = 0x3e400000; + +/** +* Computes the sine and cosine on \\( \approx \[-\pi/4, \pi/4\] \\) (except for \\(-0\\)), where \\( \pi/4 \approx 0.7854 \\). +* +* @private +* @param x input value (in radians, assumed to be bounded by `~π/4` in magnitude) +* @param y tail of `x` +* @param sine destination to store the sine +* @param cosine destination to store the cosine +*/ +static void kernelSincos( const double x, const double y, double* sine, double* cosine ) { + double hz; + double r; + double v; + double w; + double z; + + z = x * x; + w = z * z; + r = S2 + ( z * ( S3 + ( z * S4 ) ) ) + ( z * w * ( S5 + ( z * S6 ) ) ); + v = z * x; + if ( y == 0.0 ) { + *sine = x + ( v * ( S1 + ( z * r ) ) ); + } else { + *sine = x - ( ( ( z * ( ( 0.5 * y ) - ( v * r ) ) ) - y ) - ( v * S1 ) ); + } + r = z * ( C1 + ( z * ( C2 + ( z * C3 ) ) ) ); + r += w * w * ( C4 + ( z * ( C5 + ( z * C6 ) ) ) ); + hz = 0.5 * z; + w = 1.0 - hz; + *cosine = w + ( ( ( 1.0 - w ) - hz ) + ( ( z * r ) - ( x * y ) ) ); + return; +} + +/** +* Simultaneously computes the sine and cosine of a number. +* +* ## Method +* +* - Let \\(S\\), \\(C\\), and \\(T\\) denote the \\(\sin\\), \\(\cos\\) and \\(\tan\\), respectively, on \\(\[-\pi/4, +\pi/4\]\\). +* +* - Reduce the argument \\(x\\) to \\(y1+y2 = x-k\pi/2\\) in \\(\[-\pi/4, +\pi/4\]\\), and let \\(n = k \mod 4\\). +* +* - We have +* +* | n | sin(x) | cos(x) | tan(x) | +* | - | ------ | ------ | ------ | +* | 0 | S | C | T | +* | 1 | C | -S | -1/T | +* | 2 | -S | -C | T | +* | 3 | -C | S | -1/T | +* +* @param x input value +* @param sine destination to store the sine +* @param cosine destination to store the cosine +* +* @example +* double x = 0.0; +* +* double cosine; +* double sine; +* stdlib_base_sincos( x, &sine, &cosine ); +*/ +void stdlib_base_sincos( const double x, double* sine, double* cosine ) { + uint32_t uix; + double rem1; + double rem2; + double tmp; + int32_t ix; + int32_t n; + + stdlib_base_float64_get_high_word( x, &uix ); + ix = (int32_t)uix; + + // Case: |x| ~< π/4 + ix &= STDLIB_CONSTANT_FLOAT64_HIGH_WORD_ABS_MASK; + if ( ix <= PIO4_HIGH_WORD ) { + // Case: |x| ~< 2^-26 + if ( ix < SMALL_HIGH_WORD ) { + if ( (int32_t)x == 0 ) { + *sine = x; + *cosine = 0.0; + } + } + return kernelSincos( x, 0.0, sine, cosine ); + } + + // Case: x is NaN or infinity + if ( ix >= STDLIB_CONSTANT_FLOAT64_HIGH_WORD_EXPONENT_MASK ) { + *sine = 0.0 / 0.0; // NaN + *cosine = 0.0 / 0.0; // NaN + return; + } + + // Argument reduction... + n = stdlib_base_rempio2( x, &rem1, &rem2 ); + + // Compute the sine and cosine together: + kernelSincos( rem1, rem2, sine, cosine ); + + switch ( n & 3 ) { + case 1: + tmp = *cosine; + *cosine = -*sine; + *sine = tmp; + return; + case 2: + *sine *= -1; + *cosine *= -1; + return; + case 3: + // Passing + tmp = -*cosine; + *cosine = *sine; + *sine = tmp; + return; + default: + return; + } +} diff --git a/lib/node_modules/@stdlib/math/base/special/sincos/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/sincos/test/test.native.js new file mode 100644 index 000000000000..5fb4604d0f19 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sincos/test/test.native.js @@ -0,0 +1,276 @@ +/** +* @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 tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var sincos = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( sincos instanceof Error ) +}; + + +// FIXTURES // + +var mediumNegative = require( './fixtures/julia/medium_negative.json' ); +var mediumPositive = require( './fixtures/julia/medium_positive.json' ); +var largeNegative = require( './fixtures/julia/large_negative.json' ); +var largePositive = require( './fixtures/julia/large_positive.json' ); +var hugeNegative = require( './fixtures/julia/huge_negative.json' ); +var hugePositive = require( './fixtures/julia/huge_positive.json' ); + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sincos, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function computes the sine and cosine (for -256*pi < x < 0)', opts, function test( t ) { + var cosine; + var delta; + var sine; + var tol; + var x; + var y; + var i; + + x = mediumNegative.x; + sine = mediumNegative.sine; + cosine = mediumNegative.cosine; + + for ( i = 0; i < x.length; i++ ) { + y = sincos( x[i] ); + if ( y[0] === sine[ i ] ) { + t.equal( y[0], sine[ i ], 'x: '+x[i]+'. Expected: '+sine[i] ); + } else { + delta = abs( y[0] - sine[i] ); + tol = EPS * abs( sine[i] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y[0]+'. Expected: '+sine[i]+'. tol: '+tol+'. delta: '+delta+'.' ); + } + if ( y[1] === cosine[ i ] ) { + t.equal( y[1], cosine[ i ], 'x: '+x[i]+'. Expected: '+cosine[i] ); + } else { + delta = abs( y[1] - cosine[i] ); + tol = EPS * abs( cosine[i] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y[1]+'. Expected: '+cosine[i]+'. tol: '+tol+'. delta: '+delta+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes the sine and cosine (for 0 < x < 256*pi)', opts, function test( t ) { + var cosine; + var delta; + var sine; + var tol; + var x; + var y; + var i; + + x = mediumPositive.x; + sine = mediumPositive.sine; + cosine = mediumPositive.cosine; + + for ( i = 0; i < x.length; i++ ) { + y = sincos( x[i] ); + if ( y[0] === sine[ i ] ) { + t.equal( y[0], sine[ i ], 'x: '+x[i]+'. Expected: '+sine[i] ); + } else { + delta = abs( y[0] - sine[i] ); + tol = EPS * abs( sine[i] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y[0]+'. Expected: '+sine[i]+'. tol: '+tol+'. delta: '+delta+'.' ); + } + if ( y[1] === cosine[ i ] ) { + t.equal( y[1], cosine[ i ], 'x: '+x[i]+'. Expected: '+cosine[i] ); + } else { + delta = abs( y[1] - cosine[i] ); + tol = EPS * abs( cosine[i] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y[1]+'. Expected: '+cosine[i]+'. tol: '+tol+'. delta: '+delta+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes the sine and cosine (for -2**60 (pi/2) < x < -2**20 (pi/2))', opts, function test( t ) { + var cosine; + var delta; + var sine; + var tol; + var x; + var y; + var i; + + x = largeNegative.x; + sine = largeNegative.sine; + cosine = largeNegative.cosine; + + for ( i = 0; i < x.length; i++ ) { + y = sincos( x[i] ); + if ( y[0] === sine[ i ] ) { + t.equal( y[0], sine[ i ], 'x: '+x[i]+'. Expected: '+sine[i] ); + } else { + delta = abs( y[0] - sine[i] ); + tol = EPS * abs( sine[i] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y[0]+'. Expected: '+sine[i]+'. tol: '+tol+'. delta: '+delta+'.' ); + } + if ( y[1] === cosine[ i ] ) { + t.equal( y[1], cosine[ i ], 'x: '+x[i]+'. Expected: '+cosine[i] ); + } else { + delta = abs( y[1] - cosine[i] ); + tol = EPS * abs( cosine[i] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y[1]+'. Expected: '+cosine[i]+'. tol: '+tol+'. delta: '+delta+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes the sine and cosine (for 2**20 (pi/2) < x < 2**60 (pi/2))', opts, function test( t ) { + var cosine; + var delta; + var sine; + var tol; + var x; + var y; + var i; + + x = largePositive.x; + sine = largePositive.sine; + cosine = largePositive.cosine; + + for ( i = 0; i < x.length; i++ ) { + y = sincos( x[i] ); + if ( y[0] === sine[ i ] ) { + t.equal( y[0], sine[ i ], 'x: '+x[i]+'. Expected: '+sine[i] ); + } else { + delta = abs( y[0] - sine[i] ); + tol = EPS * abs( sine[i] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y[0]+'. Expected: '+sine[i]+'. tol: '+tol+'. delta: '+delta+'.' ); + } + if ( y[1] === cosine[ i ] ) { + t.equal( y[1], cosine[ i ], 'x: '+x[i]+'. Expected: '+cosine[i] ); + } else { + delta = abs( y[1] - cosine[i] ); + tol = EPS * abs( cosine[i] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y[1]+'. Expected: '+cosine[i]+'. tol: '+tol+'. delta: '+delta+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes the sine and cosine (for x <= -2**60 (PI/2))', opts, function test( t ) { + var cosine; + var delta; + var sine; + var tol; + var x; + var y; + var i; + + x = hugeNegative.x; + sine = hugeNegative.sine; + cosine = hugeNegative.cosine; + + for ( i = 0; i < x.length; i++ ) { + y = sincos( x[i] ); + if ( y[0] === sine[ i ] ) { + t.equal( y[0], sine[ i ], 'x: '+x[i]+'. Expected: '+sine[i] ); + } else { + delta = abs( y[0] - sine[i] ); + tol = EPS * abs( sine[i] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y[0]+'. Expected: '+sine[i]+'. tol: '+tol+'. delta: '+delta+'.' ); + } + if ( y[1] === cosine[ i ] ) { + t.equal( y[1], cosine[ i ], 'x: '+x[i]+'. Expected: '+cosine[i] ); + } else { + delta = abs( y[1] - cosine[i] ); + tol = EPS * abs( cosine[i] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y[1]+'. Expected: '+cosine[i]+'. tol: '+tol+'. delta: '+delta+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes the sine and cosine (for x >= 2**60 (PI/2))', opts, function test( t ) { + var cosine; + var delta; + var sine; + var tol; + var x; + var y; + var i; + + x = hugePositive.x; + sine = hugePositive.sine; + cosine = hugePositive.cosine; + + for ( i = 0; i < x.length; i++ ) { + y = sincos( x[i] ); + if ( y[0] === sine[ i ] ) { + t.equal( y[0], sine[ i ], 'x: '+x[i]+'. Expected: '+sine[i] ); + } else { + delta = abs( y[0] - sine[i] ); + tol = EPS * abs( sine[i] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y[0]+'. Expected: '+sine[i]+'. tol: '+tol+'. delta: '+delta+'.' ); + } + if ( y[1] === cosine[ i ] ) { + t.equal( y[1], cosine[ i ], 'x: '+x[i]+'. Expected: '+cosine[i] ); + } else { + delta = abs( y[1] - cosine[i] ); + tol = EPS * abs( cosine[i] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y[1]+'. Expected: '+cosine[i]+'. tol: '+tol+'. delta: '+delta+'.' ); + } + } + t.end(); +}); + +tape( 'the function returns `NaN` if provided a `NaN`', opts, function test( t ) { + var v = sincos( NaN ); + t.equal( isnan( v[0] ), true, 'returns expected value' ); + t.equal( isnan( v[1] ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `NaN` if provided `+infinity`', opts, function test( t ) { + var v = sincos( PINF ); + t.equal( isnan( v[0] ), true, 'returns expected value' ); + t.equal( isnan( v[1] ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `NaN` if provided `-infinity`', opts, function test( t ) { + var v = sincos( NINF ); + t.equal( isnan( v[0] ), true, 'returns expected value' ); + t.equal( isnan( v[1] ), true, 'returns expected value' ); + t.end(); +});