diff --git a/lib/node_modules/@stdlib/math/base/special/rempio2f/LICENSE b/lib/node_modules/@stdlib/math/base/special/rempio2f/LICENSE new file mode 100644 index 000000000000..a7566ad6f2c3 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/LICENSE @@ -0,0 +1,192 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + +DEPENDENCIES & ATTRIBUTION + +The library links against the following external libraries or contains +implementations from the following external libraries, which have their own +licenses: + +* FreeBSD <https://svnweb.freebsd.org/> + +Copyright (C) 1993-2004 by Sun Microsystems, Inc. All rights reserved. + +Developed at SunPro, a Sun Microsystems, Inc. business. +Permission to use, copy, modify, and distribute this +software is freely granted, provided that this notice +is preserved. diff --git a/lib/node_modules/@stdlib/math/base/special/rempio2f/README.md b/lib/node_modules/@stdlib/math/base/special/rempio2f/README.md new file mode 100644 index 000000000000..3930f2d9b80a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/README.md @@ -0,0 +1,212 @@ +<!-- + +@license Apache-2.0 + +Copyright (c) 2025 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. + +--> + +# rempio2f + +> Compute `x - nπ/2 = r` (single-precision). + +<section class="usage"> + +## Usage + +```javascript +var rempio2f = require( '@stdlib/math/base/special/rempio2f' ); +``` + +#### rempio2f( x, y ) + +Computes `x - nπ/2 = r`. + +```javascript +var y = [ 0.0 ]; +var n = rempio2f( 128.0, y ); +// returns 81 + +var y1 = y[ 0 ]; +// returns ~0.765 +``` + +When `x` is `NaN` or infinite, the function returns `0` and sets `y[0]` to `NaN`. + +```javascript +var y = [ 0.0 ]; +var n = rempio2f( NaN, y ); +// returns 0 + +var y1 = y[ 0 ]; +// returns NaN + +y = [ 0.0 ]; +n = rempio2f( Infinity, y ); +// returns 0 + +y1 = y[ 0 ]; +// returns NaN +``` + +</section> + +<!-- /.usage --> + +<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> + +<section class="notes"> + +## Notes + +- The function returns `n` and stores the remainder `r` as `y[0]`. +- For input values larger than `2^28*π/2` in magnitude, the function **only** returns the last three binary digits of `n` and not the full result. + +</section> + +<!-- /.notes --> + +<section class="examples"> + +## Examples + +<!-- eslint no-undef: "error" --> + +```javascript +var linspace = require( '@stdlib/array/base/linspace' ); +var rempio2f = require( '@stdlib/math/base/special/rempio2f' ); + +var x = linspace( 0.0, 100.0, 100 ); +var y = [ 0.0 ]; +var n; +var i; + +for ( i = 0; i < x.length; i++ ) { + n = rempio2f( x[ i ], y ); + console.log( '%d - %dπ/2 = %d', x[ i ], n, y[ 0 ] ); +} +``` + +</section> + +<!-- /.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/rempio2f.h" +``` + +#### stdlib_base_rempio2f( x, &rem ) + +Computes `x - nπ/2 = r` (single-precision). + +```c +#include <stdint.h> + +double rem; + +int32_t n = stdlib_base_rempio2f( 4.0f, &rem ); +``` + +The function accepts the following arguments: + +- **x**: `[in] float` input value. +- **rem**: `[out] double*` destination for the remainder. + +```c +int32_t stdlib_base_rempio2f( const float x, double *rem ); +``` + +</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/rempio2f.h" +#include <stdio.h> +#include <stdint.h> +#include <inttypes.h> + +int main( void ) { + const double x[] = { 0.0f, 1.0f, 4.0f, 128.0f }; + + double rem; + int32_t n; + int i; + for ( i = 0; i < 4; i++ ) { + n = stdlib_base_rempio2f( x[ i ], &rem ); + printf( "%lf - %"PRId32"π/2 = %lf\n", x[ i ], n, rem ); + } +} +``` + +</section> + +<!-- /.examples --> + +</section> + +<!-- /.c --> + +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> + +<section class="related"> + +</section> + +<!-- /.related --> + +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> + +<section class="links"> + +</section> + +<!-- /.links --> diff --git a/lib/node_modules/@stdlib/math/base/special/rempio2f/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/rempio2f/benchmark/benchmark.js new file mode 100644 index 000000000000..30c551e3f1d6 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/benchmark/benchmark.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pkg = require( './../package.json' ).name; +var rempio2f = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var x; + var y; + var n; + var i; + + y = [ 0.0 ]; + x = uniform( 100, -100.0, 100.0, { + 'dtype': 'float32' + }); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + n = rempio2f( x[ i % x.length ], y ); + if ( isnanf( n ) || isnanf( y[0] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( n ) || isnanf( y[0] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/rempio2f/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/rempio2f/benchmark/benchmark.native.js new file mode 100644 index 000000000000..b1dbe21ad639 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/benchmark/benchmark.native.js @@ -0,0 +1,66 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 uniform = require( '@stdlib/random/array/uniform' ); +var Float64Array = require( '@stdlib/array/float64' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var rempio2f = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( rempio2f instanceof Error ) +}; + + +// MAIN // + +bench( pkg+'::native', opts, function benchmark( b ) { + var x; + var y; + var n; + var i; + + y = new Float64Array( [ 0.0 ] ); + x = uniform( 100, -100.0, 100.0, { + 'dtype': 'float32' + }); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + n = rempio2f( x[ i % x.length ], y ); + if ( isnanf( n ) || isnanf( y[0] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( n ) || isnanf( y[0] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/rempio2f/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/rempio2f/benchmark/c/native/Makefile new file mode 100644 index 000000000000..a4bd7b38fd74 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/benchmark/c/native/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 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/rempio2f/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/rempio2f/benchmark/c/native/benchmark.c new file mode 100644 index 000000000000..a93cbc3a6659 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/benchmark/c/native/benchmark.c @@ -0,0 +1,137 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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/rempio2f.h" +#include <stdlib.h> +#include <stdio.h> +#include <math.h> +#include <time.h> +#include <sys/time.h> + +#define NAME "rempio2f" +#define ITERATIONS 1000000 +#define REPEATS 3 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // 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 +*/ +static void print_results( double elapsed ) { + double rate = (double)ITERATIONS / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [0,1). +* +* @return random number +*/ +static float rand_float( void ) { + int r = rand(); + return (float)r / ( (float)RAND_MAX + 1.0f ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + float x[ 100 ]; + double elapsed; + double rem; + double y; + double t; + int i; + + for ( i = 0; i < 100; i++ ) { + x[ i ] = ( rand_float() * 200.0f ) - 100.0f; + } + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + y = stdlib_base_rempio2f( x[ i%100 ], &rem ); + if ( y != y && rem != rem ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( y != y && rem != rem ) { + 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/rempio2f/binding.gyp b/lib/node_modules/@stdlib/math/base/special/rempio2f/binding.gyp new file mode 100644 index 000000000000..68a1ca11d160 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2025 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/rempio2f/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/rempio2f/docs/repl.txt new file mode 100644 index 000000000000..d538e68333da --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/docs/repl.txt @@ -0,0 +1,34 @@ + +{{alias}}( x, y ) + Computes `x - nπ/2 = r` (single-precision). + + The function returns `n` and stores the remainder `r` as `y[0]`. + + For input values larger than `2^28 * π/2` in magnitude, the function only + returns the last three binary digits of `n` and not the full result. + + Parameters + ---------- + x: number + Input value. + + y: Array|TypedArray|Object + Remainder element. + + Returns + ------- + n: integer + Factor of `π/2`. + + Examples + -------- + > var y = [ 0.0 ]; + > var n = {{alias}}( 128.0, y ) + 81 + > var y1 = y[ 0 ] + ~0.765 + + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/math/base/special/rempio2f/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/rempio2f/docs/types/index.d.ts new file mode 100644 index 000000000000..0c7f7e923d83 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/docs/types/index.d.ts @@ -0,0 +1,58 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// <reference types="@stdlib/types"/> + +import { Collection } from '@stdlib/types/array'; + +/** +* Computes `x - nπ/2 = r` (single-precision). +* +* ## Notes +* +* - The function returns `n` and stores the remainder `r` as `y[0]`. +* - For input values larger than `2^28 * π/2` in magnitude, the function only returns the last three binary digits of `n` and not the full result. +* +* @param x - input value +* @param y - remainder element +* @returns factor of `π/2` +* +* @example +* var y = [ 0.0 ]; +* var n = rempio2f( 128.0, y ); +* // returns 81 +* +* var y1 = y[ 0 ]; +* // returns ~0.765 +* +* @example +* var y = [ 0.0 ]; +* var n = rempio2f( NaN, y ); +* // returns 0 +* +* var y1 = y[ 0 ]; +* // returns NaN +*/ +declare function rempio2f( x: number, y: Collection<number> ): number; + + +// EXPORTS // + +export = rempio2f; diff --git a/lib/node_modules/@stdlib/math/base/special/rempio2f/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/rempio2f/docs/types/test.ts new file mode 100644 index 000000000000..a69b1b3bfded --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/docs/types/test.ts @@ -0,0 +1,56 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/// <reference types="@stdlib/types"/> + +import { Collection } from '@stdlib/types/array'; +import rempio2f = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const y: Collection<number> = [ 0.0 ]; + rempio2f( 128, y ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a value other than a number as its first argument... +{ + const y: Collection<number> = [ 0.0 ]; + rempio2f( true, y ); // $ExpectError + rempio2f( false, y ); // $ExpectError + rempio2f( '5', y ); // $ExpectError + rempio2f( [], y ); // $ExpectError + rempio2f( {}, y ); // $ExpectError + rempio2f( ( x: number ): number => x, y ); // $ExpectError +} + +// The compiler throws an error if the function is provided a value other than a collection as its second argument... +{ + rempio2f( 128, true ); // $ExpectError + rempio2f( 128, false ); // $ExpectError + rempio2f( 128, 3 ); // $ExpectError + rempio2f( 128, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + rempio2f(); // $ExpectError + rempio2f( 3 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/math/base/special/rempio2f/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/rempio2f/examples/c/Makefile new file mode 100644 index 000000000000..25ced822f96a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 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/rempio2f/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/rempio2f/examples/c/example.c new file mode 100644 index 000000000000..dbf59c311e59 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/examples/c/example.c @@ -0,0 +1,34 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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/rempio2f.h" +#include <stdio.h> +#include <stdint.h> +#include <inttypes.h> + +int main( void ) { + const double x[] = { 0.0f, 1.0f, 4.0f, 128.0f }; + + double rem; + int32_t n; + int i; + for ( i = 0; i < 4; i++ ) { + n = stdlib_base_rempio2f( x[ i ], &rem ); + printf( "%lf - %"PRId32"π/2 = %lf\n", x[ i ], n, rem ); + } +} diff --git a/lib/node_modules/@stdlib/math/base/special/rempio2f/examples/index.js b/lib/node_modules/@stdlib/math/base/special/rempio2f/examples/index.js new file mode 100644 index 000000000000..4923ed319205 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/examples/index.js @@ -0,0 +1,32 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var linspace = require( '@stdlib/array/base/linspace' ); +var rempio2f = require( './../lib' ); + +var x = linspace( 0.0, 100.0, 100 ); +var y = [ 0.0 ]; +var n; +var i; + +for ( i = 0; i < x.length; i++ ) { + n = rempio2f( x[ i ], y ); + console.log( '%d - %dπ/2 = %d', x[ i ], n, y[ 0 ] ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/rempio2f/include.gypi b/lib/node_modules/@stdlib/math/base/special/rempio2f/include.gypi new file mode 100644 index 000000000000..ecfaf82a3279 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2025 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/rempio2f/include/stdlib/math/base/special/rempio2f.h b/lib/node_modules/@stdlib/math/base/special/rempio2f/include/stdlib/math/base/special/rempio2f.h new file mode 100644 index 000000000000..130efc25faf5 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/include/stdlib/math/base/special/rempio2f.h @@ -0,0 +1,40 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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_REMPIO2F_H +#define STDLIB_MATH_BASE_SPECIAL_REMPIO2F_H + +#include <stdint.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 `x - nπ/2 = r` (single-precision). +*/ +int32_t stdlib_base_rempio2f( const float x, double *rem ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_MATH_BASE_SPECIAL_REMPIO2F_H diff --git a/lib/node_modules/@stdlib/math/base/special/rempio2f/lib/index.js b/lib/node_modules/@stdlib/math/base/special/rempio2f/lib/index.js new file mode 100644 index 000000000000..bfeb6f7ef601 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/lib/index.js @@ -0,0 +1,44 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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'; + +/** +* Compute `x - nπ/2 = r` (single precision). +* +* @module @stdlib/math/base/special/rempio2f +* +* @example +* var rempio2f = require( '@stdlib/math/base/special/rempio2f' ); +* +* var y = [ 0.0 ]; +* var n = rempio2f( 128.0, y ); +* // returns 81 +* +* var y1 = y[ 0 ]; +* // returns ~0.765 +*/ + +// MODULES // + +var rempio2f = require( './main.js' ); + + +// EXPORTS // + +module.exports = rempio2f; diff --git a/lib/node_modules/@stdlib/math/base/special/rempio2f/lib/kernel_rempio2f.js b/lib/node_modules/@stdlib/math/base/special/rempio2f/lib/kernel_rempio2f.js new file mode 100644 index 000000000000..c7e9dbb7c7ba --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/lib/kernel_rempio2f.js @@ -0,0 +1,410 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 following copyright and license were part of the original implementation available as part of [FreeBSD]{@link https://svnweb.freebsd.org/base/release/9.3.0/lib/msun/src/k_rem_pio2.c}. The implementation follows the original, but has been modified for JavaScript. +* +* ```text +* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. +* +* Developed at SunPro, a Sun Microsystems, Inc. business. +* Permission to use, copy, modify, and distribute this +* software is freely granted, provided that this notice +* is preserved. +* ``` +*/ + +/* eslint-disable array-element-newline */ + +'use strict'; + +// MODULES // + +var floor = require( '@stdlib/math/base/special/floor' ); +var ldexp = require( '@stdlib/math/base/special/ldexp' ); +var zeros = require( '@stdlib/array/base/zeros' ); + + +// VARIABLES // + +/* +* Table of constants for `2/π` (`396` hex digits, `476` decimal). +* +* Integer array which contains the (`24*i`)-th to (`24*i+23`)-th bit of `2/π` after binary point. The corresponding floating value is +* +* ```tex +* \operatorname{ipio2}[i] \cdot 2^{-24(i+1)} +* ``` +* +* This table must have at least `(e0-3)/24 + jk` terms. For single precision (`e0 <= 127`, `jk = 3`), this is `9`. +*/ +var IPIO2 = [ + 0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62, + 0x95993C, 0x439041, 0xFE5163 +]; + +// Double precision array, obtained by cutting `π/2` into `24` bits chunks... +var PIO2 = [ + 1.57079625129699707031e+00, // 0x3FF921FB, 0x40000000 + 7.54978941586159635335e-08, // 0x3E74442D, 0x00000000 + 5.39030252995776476554e-15, // 0x3CF84698, 0x80000000 + 3.28200341580791294123e-22, // 0x3B78CC51, 0x60000000 + 1.27065575308067607349e-29, // 0x39F01B83, 0x80000000 + 1.22933308981111328932e-36, // 0x387A2520, 0x40000000 + 2.73370053816464559624e-44, // 0x36E38222, 0x80000000 + 2.16741683877804819444e-51 // 0x3569F31D, 0x00000000 +]; +var TWO24 = 1.67772160000000000000e+07; // 0x41700000, 0x00000000 +var TWON24 = 5.96046447753906250000e-08; // 0x3E700000, 0x00000000 + +// Arrays for storing temporary values (note that, in C, this is not thread safe): +var F = zeros( 20 ); +var Q = zeros( 20 ); +var FQ = zeros( 20 ); +var IQ = zeros( 20 ); + + +// FUNCTIONS // + +/** +* Performs the computation for `kernelRempio2f()`. +* +* @private +* @param {PositiveNumber} x - input value +* @param {(Array|TypedArray|Object)} y - output object for storing double precision numbers +* @param {integer} jz - number of terms of `ipio2[]` used +* @param {Array<integer>} q - array with integral values, representing the 24-bits chunk of the product of `x` and `2/π` +* @param {integer} q0 - the corresponding exponent of `q[0]` (the exponent for `q[i]` would be `q0-24*i`) +* @param {integer} jk - `jk+1` is the initial number of terms of `IPIO2[]` needed in the computation +* @param {integer} jv - index for pointing to the suitable `ipio2[]` for the computation +* @param {integer} jx - `nx - 1` +* @param {Array<number>} f - `IPIO2[]` in floating point +* @returns {number} last three binary digits of `N` +*/ +function compute( x, y, jz, q, q0, jk, jv, jx, f ) { + var carry; + var fw; + var ih; + var jp; + var i; + var k; + var n; + var j; + var z; + + // `jp+1` is the number of terms in `PIO2[]` needed: + jp = jk; + + // Distill `q[]` into `IQ[]` in reverse order... + z = q[ jz ]; + j = jz; + for ( i = 0; j > 0; i++ ) { + fw = ( TWON24 * z )|0; + IQ[ i ] = ( z - (TWO24*fw) )|0; + z = q[ j-1 ] + fw; + j -= 1; + } + // Compute `n`... + z = ldexp( z, q0 ); + z -= 8.0 * floor( z*0.125 ); // Trim off integer >= 8 + n = z|0; + z -= n; + ih = 0; + if ( q0 > 0 ) { + // Need `IQ[jz-1]` to determine `n`... + i = ( IQ[ jz-1 ] >> (24-q0) ); + n += i; + IQ[ jz-1 ] -= ( i << (24-q0) ); + ih = ( IQ[ jz-1 ] >> (23-q0) ); + } + else if ( q0 === 0 ) { + ih = ( IQ[ jz-1 ] >> 23 ); + } + else if ( z >= 0.5 ) { + ih = 2; + } + // Case: q > 0.5 + if ( ih > 0 ) { + n += 1; + carry = 0; + + // Compute `1-q`: + for ( i = 0; i < jz; i++ ) { + j = IQ[ i ]; + if ( carry === 0 ) { + if ( j !== 0 ) { + carry = 1; + IQ[ i ] = 0x1000000 - j; + } + } else { + IQ[ i ] = 0xffffff - j; + } + } + if ( q0 > 0 ) { + // Rare case: chance is 1 in 12... + switch ( q0 ) { // eslint-disable-line default-case + case 1: + IQ[ jz-1 ] &= 0x7fffff; + break; + case 2: + IQ[ jz-1 ] &= 0x3fffff; + break; + } + } + if ( ih === 2 ) { + z = 1.0 - z; + if ( carry !== 0 ) { + z -= ldexp( 1.0, q0 ); + } + } + } + // Check if re-computation is needed... + if ( z === 0.0 ) { + j = 0; + for ( i = jz-1; i >= jk; i-- ) { + j |= IQ[ i ]; + } + if ( j === 0 ) { + // Need re-computation... + for ( k = 1; IQ[ jk-k ] === 0; k++ ) { + // `k` is the number of terms needed... + } + for ( i = jz+1; i <= jz+k; i++ ) { + // Add `q[jz+1]` to `q[jz+k]`... + f[ jx+i ] = IPIO2[ jv+i ]; + fw = 0.0; + for ( j = 0; j <= jx; j++ ) { + fw += x[ j ] * f[ jx + (i-j) ]; + } + q[ i ] = fw; + } + jz += k; + return compute( x, y, jz, q, q0, jk, jv, jx, f ); + } + // Chop off zero terms... + jz -= 1; + q0 -= 24; + while ( IQ[ jz ] === 0 ) { + jz -= 1; + q0 -= 24; + } + } else { + // Break `z` into 24-bit if necessary... + z = ldexp( z, -q0 ); + if ( z >= TWO24 ) { + fw = (TWON24*z)|0; + IQ[ jz ] = ( z - (TWO24*fw) )|0; + jz += 1; + q0 += 24; + IQ[ jz ] = fw; + } else { + IQ[ jz ] = z|0; + } + } + // Convert integer "bit" chunk to floating-point value... + fw = ldexp( 1.0, q0 ); + for ( i = jz; i >= 0; i-- ) { + q[ i ] = fw * IQ[i]; + fw *= TWON24; + } + // Compute `PIO2[0,...,jp]*q[jz,...,0]`... + for ( i = jz; i >= 0; i-- ) { + fw = 0.0; + for ( k = 0; k <= jp && k <= jz-i; k++ ) { + fw += PIO2[ k ] * q[ i+k ]; + } + FQ[ jz-i ] = fw; + } + // Compress `FQ[]` into `y[]`... + fw = 0.0; + for ( i = jz; i >= 0; i-- ) { + fw += FQ[ i ]; + } + if ( ih === 0 ) { + y[ 0 ] = fw; + } else { + y[ 0 ] = -fw; + } + return ( n & 7 ); +} + + +// MAIN // + +/** +* Returns the last three binary digits of `N` with `y = x - Nπ/2` so that `|y| < π/2` (single precision). +* +* ## Method +* +* - The method is to compute the integer (mod 8) and fraction parts of (2/π) * x without doing the full multiplication. In general, we skip the part of the product that are known to be a huge integer (more accurately, = 0 mod 8 ). Thus the number of operations are independent of the exponent of the input. +* +* - (2/π) is represented by an array of 24-bit integers in `ipio2[]`. +* +* - Input parameters: +* +* - `x[]` The input value (must be positive) is broken into `nx` pieces of 24-bit integers in double precision format. `x[i]` will be the i-th 24 bit of x. The scaled exponent of `x[0]` is given in input parameter `e0` (i.e., `x[0]*2^e0` match x's up to 24 bits). +* +* Example of breaking a double positive `z` into `x[0]+x[1]+x[2]`: +* +* ```tex +* e0 = \mathrm{ilogb}(z) - 23 +* z = \mathrm{scalbn}(z, -e0) +* ``` +* +* for `i = 0,1,2` +* +* ```tex +* x[i] = \lfloor z \rfloor +* z = (z - x[i]) \times 2^{24} +* ``` +* +* - `y[]` output result in an array of double precision numbers. +* +* The dimension of `y[]` is: +* 24-bit precision 1 +* 53-bit precision 2 +* 64-bit precision 2 +* 113-bit precision 3 +* +* The actual value is the sum of them. Thus, for 113-bit precision, one may have to do something like: +* +* ```tex +* \mathrm{long\ double} \: t, w, r_{\text{head}}, r_{\text{tail}}; \\ +* t &= (\mathrm{long\ double}) y[2] + (\mathrm{long\ double}) y[1]; \\ +* w &= (\mathrm{long\ double}) y[0]; \\ +* r_{\text{head}} &= t + w; \\ +* r_{\text{tail}} &= w - (r_{\text{head}} - t); +* ``` +* +* - `e0` The exponent of `x[0]`. Must be <= 16360 or you need to expand the `ipio2` table. +* +* - `nx` dimension of `x[]` +* +* - `prec` an integer indicating the precision: +* 0 24 bits (single) +* 1 53 bits (double) +* 2 64 bits (extended) +* 3 113 bits (quad) +* +* - External function: +* +* - double `scalbn()`, `floor()`; +* +* - Here is the description of some local variables: +* +* - `jk` `jk+1` is the initial number of terms of `ipio2[]` needed in the computation. The minimum and recommended value for `jk` is 3,4,4,6 for single, double, extended, and quad. `jk+1` must be 2 larger than you might expect so that our recomputation test works. (Up to 24 bits in the integer part (the 24 bits of it that we compute) and 23 bits in the fraction part may be lost to cancellation before we recompute.) +* +* - `jz` local integer variable indicating the number of terms of `ipio2[]` used. +* +* - `jx` `nx - 1` +* +* - `jv` index for pointing to the suitable `ipio2[]` for the computation. In general, we want +* +* ```tex +* \frac{{2^{e0} \cdot x[0] \cdot \mathrm{ipio2}[jv-1] \cdot 2^{-24jv}}}{{8}} +* ``` +* +* to be an integer. Thus +* +* ```tex +* e0 - 3 - 24 \cdot jv \geq 0 \quad \text{or} \quad \frac{{e0 - 3}}{{24}} \geq jv +* ``` +* +* Hence +* +* ```tex +* jv = \max(0, \frac{{e0 - 3}}{{24}}) +* ``` +* +* - `jp` `jp+1` is the number of terms in `PIo2[]` needed, `jp = jk`. +* +* - `q[]` double array with integral value, representing the 24-bits chunk of the product of `x` and `2/π`. +* +* - `q0` the corresponding exponent of `q[0]`. Note that the exponent for `q[i]` would be `q0-24*i`. +* +* - `PIo2[]` double precision array, obtained by cutting `π/2` into 24 bits chunks. +* +* - `f[]` `ipso2[]` in floating point +* +* - `iq[]` integer array by breaking up `q[]` in 24-bits chunk. +* +* - `fq[]` final product of `x*(2/π)` in `fq[0],..,fq[jk]` +* +* - `ih` integer. If >0 it indicates `q[]` is >= 0.5, hence it also indicates the _sign_ of the result. +* +* - Constants: +* +* - The hexadecimal values are the intended ones for the following constants. The decimal values may be used, provided that the compiler will convert from decimal to binary accurately enough to produce the hexadecimal values shown. +* +* @private +* @param {PositiveNumber} x - input value +* @param {(Array|TypedArray|Object)} y - remainder element +* @param {PositiveInteger} e0 - the exponent of `x[0]` (must be <= 127) +* @param {PositiveInteger} nx - dimension of `x[]` +* @returns {number} last three binary digits of `N` +*/ +function kernelRempio2f( x, y, e0, nx ) { + var fw; + var jk; + var jv; + var jx; + var jz; + var q0; + var i; + var j; + var m; + + // Initialize `jk` for single-precision floating-point numbers: + jk = 3; + + // Determine `jx`, `jv`, `q0` (note that `q0 < 3`): + jx = nx - 1; + jv = ( (e0 - 3) / 24 )|0; + if ( jv < 0 ) { + jv = 0; + } + q0 = e0 - (24 * (jv + 1)); + + // Set up `F[0]` to `F[jx+jk]` where `F[jx+jk] = IPIO2[jv+jk]`: + j = jv - jx; + m = jx + jk; + for ( i = 0; i <= m; i++ ) { + if ( j < 0 ) { + F[ i ] = 0.0; + } else { + F[ i ] = IPIO2[ j ]; + } + j += 1; + } + // Compute `Q[0],Q[1],...,Q[jk]`: + for ( i = 0; i <= jk; i++ ) { + fw = 0.0; + for ( j = 0; j <= jx; j++ ) { + fw += x[ j ] * F[ jx + (i-j) ]; + } + Q[ i ] = fw; + } + jz = jk; + return compute( x, y, jz, Q, q0, jk, jv, jx, F ); +} + + +// EXPORTS // + +module.exports = kernelRempio2f; diff --git a/lib/node_modules/@stdlib/math/base/special/rempio2f/lib/main.js b/lib/node_modules/@stdlib/math/base/special/rempio2f/lib/main.js new file mode 100644 index 000000000000..68e565116c53 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/lib/main.js @@ -0,0 +1,138 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 following copyright and license were part of the original implementation available as part of [FreeBSD]{@link https://svnweb.freebsd.org/base/release/12.2.0/lib/msun/src/e_rem_pio2f.c}. The implementation follows the original, but has been modified for JavaScript. +* +* ```text +* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. +* +* Developed at SunPro, a Sun Microsystems, Inc. business. +* Permission to use, copy, modify, and distribute this +* software is freely granted, provided that this notice +* is preserved. +* +* Optimized by Bruce D. Evans. +* ``` +*/ + +'use strict'; + +// MODULES // + +var ABS_MASK = require( '@stdlib/constants/float32/abs-mask' ); +var EXPONENT_MASK = require( '@stdlib/constants/float32/exponent-mask' ); +var roundf = require( '@stdlib/math/base/special/roundf' ); +var fromWordf = require( '@stdlib/number/float32/base/from-word' ); +var toWordf = require( '@stdlib/number/float32/base/to-word' ); +var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var rempio2Kernelf = require( './kernel_rempio2f.js' ); + + +// VARIABLES // + +// 53 bits of 2/π: +var INVPIO2 = 6.36619772367581382433e-01; // 0x3FE45F30, 0x6DC9C883 + +// First 25 bits of π/2: +var PIO2_1 = 1.57079631090164184570e+00; // 0x3FF921FB, 0x50000000 + +// PIO2_1T = π/2 - PIO2_1: +var PIO2_1T = 1.58932547735281966916e-08; // 0x3E5110b4, 0x611A6263 + +// 2^28*π/2 = 421657428.2663131 => 0100000110111001001000011111101101010100010001000010110100011000 => high word => 0x4dc90fdb = 1102651899 => 01000001101110010010000111111011 +var MEDIUM = 0x4dc90fdb|0; // asm type annotation + +// Arrays for storing temporary values: +var TX = [ 0.0 ]; +var TY = [ 0.0 ]; + + +// MAIN // + +/** +* Computes `x - nπ/2 = r` (single precision). +* +* ## Notes +* +* - Returns `n` and stores the remainder `r` as `y[0]`. +* +* @param {number} x - input value +* @param {(Array|TypedArray|Object)} y - remainder element +* @returns {integer} factor of `π/2` +* +* @example +* var y = [ 0.0 ]; +* var n = rempio2f( 128.0, y ); +* // returns 81 +* +* var y1 = y[ 0 ]; +* // returns ~0.765 +* +* @example +* var y = [ 0.0 ]; +* var n = rempio2f( NaN, y ); +* // returns 0 +* +* var y1 = y[ 0 ]; +* // returns NaN +*/ +function rempio2f( x, y ) { + var e0; + var hx; + var ix; + var n; + var r; + var w; + var z; + + x = float64ToFloat32( x ); + hx = toWordf( x ); + ix = (hx & ABS_MASK)|0; // asm type annotation + + // Case: |x| ~< 2^28*π/2 (medium size) + if ( ix < MEDIUM ) { + n = roundf( float64ToFloat32( x * INVPIO2 ) ); + r = x - ( n * PIO2_1 ); + w = n * PIO2_1T; + y[ 0 ] = r - w; + return n; + } + // Case: x is NaN or infinity + if ( ix >= EXPONENT_MASK ) { + y[ 0 ] = NaN; + return 0; + } + // Set z = scalbn(|x|, ilogb(|x|)-23)... + e0 = (ix >> 23) - 150; // `e0 = ilogb(|x|) - 23` => unbiased exponent minus 23 + z = fromWordf( ix - ((e0 << 23)|0) ); + TX[ 0 ] = z; + n = rempio2Kernelf( TX, TY, e0, 1 ); + if ( hx < 0 ) { + y[ 0 ] = -TY[ 0 ]; + return -n; + } + y[ 0 ] = TY[ 0 ]; + return n; +} + + +// EXPORTS // + +module.exports = rempio2f; diff --git a/lib/node_modules/@stdlib/math/base/special/rempio2f/lib/native.js b/lib/node_modules/@stdlib/math/base/special/rempio2f/lib/native.js new file mode 100644 index 000000000000..7657084f4b54 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/lib/native.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 `x - nπ/2 = r` (single precision). +* +* @private +* @param {number} x - input value +* @param {Float64Array} y - remainder element +* @returns {integer} factor of `π/2` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var y = new Float64Array( [ 0.0 ] ); +* var n = rempio2f( 128.0, y ); +* // returns 81 +* +* var y1 = y[ 0 ]; +* // returns ~0.765 +*/ +function rempio2f( x, y ) { + return addon( x, y ); +} + + +// EXPORTS // + +module.exports = rempio2f; diff --git a/lib/node_modules/@stdlib/math/base/special/rempio2f/manifest.json b/lib/node_modules/@stdlib/math/base/special/rempio2f/manifest.json new file mode 100644 index 000000000000..c9316fb43303 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/manifest.json @@ -0,0 +1,94 @@ +{ + "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-float", + "@stdlib/napi/argv-float64array", + "@stdlib/napi/create-double", + "@stdlib/napi/export", + "@stdlib/math/base/special/roundf", + "@stdlib/math/base/special/floor", + "@stdlib/math/base/special/ldexp", + "@stdlib/number/float32/base/from-word", + "@stdlib/number/float32/base/to-word", + "@stdlib/constants/float32/abs-mask", + "@stdlib/constants/float32/exponent-mask" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/special/roundf", + "@stdlib/math/base/special/floor", + "@stdlib/math/base/special/ldexp", + "@stdlib/number/float32/base/from-word", + "@stdlib/number/float32/base/to-word", + "@stdlib/constants/float32/abs-mask", + "@stdlib/constants/float32/exponent-mask" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/special/roundf", + "@stdlib/math/base/special/floor", + "@stdlib/math/base/special/ldexp", + "@stdlib/number/float32/base/from-word", + "@stdlib/number/float32/base/to-word", + "@stdlib/constants/float32/abs-mask", + "@stdlib/constants/float32/exponent-mask" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/rempio2f/package.json b/lib/node_modules/@stdlib/math/base/special/rempio2f/package.json new file mode 100644 index 000000000000..f93396d27ede --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/math/base/special/rempio2f", + "version": "0.0.0", + "description": "Compute `x - nπ/2 = r`.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "gypfile": true, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "src": "./src", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "remainder", + "division", + "pi", + "pio2", + "pio2f", + "precision" + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/rempio2f/src/Makefile b/lib/node_modules/@stdlib/math/base/special/rempio2f/src/Makefile new file mode 100644 index 000000000000..7733b6180cb4 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 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/rempio2f/src/addon.c b/lib/node_modules/@stdlib/math/base/special/rempio2f/src/addon.c new file mode 100644 index 000000000000..580898e38dbb --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/src/addon.c @@ -0,0 +1,42 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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/rempio2f.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_float.h" +#include "stdlib/napi/argv_float64array.h" +#include "stdlib/napi/create_double.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_FLOAT( env, x, argv, 0 ); + STDLIB_NAPI_ARGV_FLOAT64ARRAY( env, y, ylen, argv, 1 ); + STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_base_rempio2f( x, &y[0] ), n ); + return n; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/math/base/special/rempio2f/src/main.c b/lib/node_modules/@stdlib/math/base/special/rempio2f/src/main.c new file mode 100644 index 000000000000..6291b52a4b7a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/src/main.c @@ -0,0 +1,439 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 following copyright, license, and long comment were part of the original implementation available as part of [FreeBSD]{@link https://svnweb.freebsd.org/base/release/12.2.0/lib/msun/src/e_rem_pio2f.c}. The implementation follows the original, but has been modified according to project conventions. +* +* ```text +* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. +* +* Developed at SunPro, a Sun Microsystems, Inc. business. +* Permission to use, copy, modify, and distribute this +* software is freely granted, provided that this notice +* is preserved. +* ``` +*/ + +#include "stdlib/math/base/special/rempio2f.h" +#include "stdlib/math/base/special/roundf.h" +#include "stdlib/math/base/special/floor.h" +#include "stdlib/math/base/special/ldexp.h" +#include "stdlib/number/float32/base/from_word.h" +#include "stdlib/number/float32/base/to_word.h" +#include "stdlib/constants/float32/abs_mask.h" +#include "stdlib/constants/float32/exponent_mask.h" +#include <stdint.h> + +static const double ZERO = 0.00000000000000000000e+00; // 0x00000000, 0x00000000 +static const double TWO24 = 1.67772160000000000000e+07; // 0x41700000, 0x00000000 +static const double TWON24 = 5.96046447753906250000e-08; // 0x3E700000, 0x00000000 +static const double INVPIO2 = 6.36619772367581382433e-01; // 0x3FE45F30, 0x6DC9C883 +static const double PIO2_1 = 1.57079631090164184570e+00; // 0x3FF921FB, 0x50000000 +static const double PIO2_1T = 1.58932547735281966916e-08; // 0x3E5110b4, 0x611A6263 + +// 2^28*π/2 = 421657428.2663131 => 0100000110111001001000011111101101010100010001000010110100011000 => high word => 0x4dc90fdb = 1102651899 => 01000001101110010010000111111011 +static const int32_t MEDIUM = 0x4dc90fdb; + + +/* +* Table of constants for `2/π` (`396` hex digits, `476` decimal). +* +* Integer array which contains the (`24*i`)-th to (`24*i+23`)-th bit of `2/π` after binary point. The corresponding floating value is +* +* ```tex +* \operatorname{ipio2}[i] \cdot 2^{-24(i+1)} +* ``` +* +* This table must have at least `(e0-3)/24 + jk` terms. For single precision (`e0 <= 127`, `jk = 3`), this is `9`. +*/ +static const int32_t IPIO2[] = { + 0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62, + 0x95993C, 0x439041, 0xFE5163 +}; + +// Double precision array, obtained by cutting `π/2` into `24` bits chunks... +static const double PIO2[] = { + 1.57079625129699707031e+00, // 0x3FF921FB, 0x40000000 + 7.54978941586159635335e-08, // 0x3E74442D, 0x00000000 + 5.39030252995776476554e-15, // 0x3CF84698, 0x80000000 + 3.28200341580791294123e-22, // 0x3B78CC51, 0x60000000 + 1.27065575308067607349e-29, // 0x39F01B83, 0x80000000 + 1.22933308981111328932e-36, // 0x387A2520, 0x40000000 + 2.73370053816464559624e-44, // 0x36E38222, 0x80000000 + 2.16741683877804819444e-51 // 0x3569F31D, 0x00000000 +}; + +/** +* Returns the last three binary digits of `N` with `y = x - Nπ/2` so that `|y| < π/2` (single-precision). +* +* ## Method +* +* - The method is to compute the integer (mod 8) and fraction parts of (2/π) * x without doing the full multiplication. In general, we skip the part of the product that are known to be a huge integer (more accurately, = 0 mod 8 ). Thus the number of operations are independent of the exponent of the input. +* +* - (2/π) is represented by an array of 24-bit integers in `ipio2[]`. +* +* - Input parameters: +* +* - `x[]` The input value (must be positive) is broken into `nx` pieces of 24-bit integers in double precision format. `x[i]` will be the i-th 24 bit of x. The scaled exponent of `x[0]` is given in input parameter `e0` (i.e., `x[0]*2^e0` match x's up to 24 bits). +* +* Example of breaking a double positive `z` into `x[0]+x[1]+x[2]`: +* +* ```tex +* e0 = \mathrm{ilogb}(z) - 23 +* z = \mathrm{scalbn}(z, -e0) +* ``` +* +* for `i = 0,1,2` +* +* ```tex +* x[i] = \lfloor z \rfloor +* z = (z - x[i]) \times 2^{24} +* ``` +* +* - `y[]` output result in an array of double precision numbers. +* +* The dimension of `y[]` is: +* 24-bit precision 1 +* 53-bit precision 2 +* 64-bit precision 2 +* 113-bit precision 3 +* +* The actual value is the sum of them. Thus, for 113-bit precision, one may have to do something like: +* +* ```tex +* \mathrm{long\ double} \: t, w, r_{\text{head}}, r_{\text{tail}}; \\ +* t &= (\mathrm{long\ double}) y[2] + (\mathrm{long\ double}) y[1]; \\ +* w &= (\mathrm{long\ double}) y[0]; \\ +* r_{\text{head}} &= t + w; \\ +* r_{\text{tail}} &= w - (r_{\text{head}} - t); +* ``` +* +* - `e0` The exponent of `x[0]`. Must be <= 16360 or you need to expand the `ipio2` table. +* +* - `nx` dimension of `x[]` +* +* - `prec` an integer indicating the precision: +* 0 24 bits (single) +* 1 53 bits (double) +* 2 64 bits (extended) +* 3 113 bits (quad) +* +* - External function: +* +* - double `scalbn()`, `floor()`; +* +* - Here is the description of some local variables: +* +* - `jk` `jk+1` is the initial number of terms of `ipio2[]` needed in the computation. The minimum and recommended value for `jk` is 3,4,4,6 for single, double, extended, and quad. `jk+1` must be 2 larger than you might expect so that our recomputation test works. (Up to 24 bits in the integer part (the 24 bits of it that we compute) and 23 bits in the fraction part may be lost to cancellation before we recompute.) +* +* - `jz` local integer variable indicating the number of terms of `ipio2[]` used. +* +* - `jx` `nx - 1` +* +* - `jv` index for pointing to the suitable `ipio2[]` for the computation. In general, we want +* +* ```tex +* \frac{{2^{e0} \cdot x[0] \cdot \mathrm{ipio2}[jv-1] \cdot 2^{-24jv}}}{{8}} +* ``` +* +* to be an integer. Thus +* +* ```tex +* e0 - 3 - 24 \cdot jv \geq 0 \quad \text{or} \quad \frac{{e0 - 3}}{{24}} \geq jv +* ``` +* +* Hence +* +* ```tex +* jv = \max(0, \frac{{e0 - 3}}{{24}}) +* ``` +* +* - `jp` `jp+1` is the number of terms in `PIo2[]` needed, `jp = jk`. +* +* - `q[]` double array with integral value, representing the 24-bits chunk of the product of `x` and `2/π`. +* +* - `q0` the corresponding exponent of `q[0]`. Note that the exponent for `q[i]` would be `q0-24*i`. +* +* - `PIo2[]` double precision array, obtained by cutting `π/2` into 24 bits chunks. +* +* - `f[]` `ipso2[]` in floating point +* +* - `iq[]` integer array by breaking up `q[]` in 24-bits chunk. +* +* - `fq[]` final product of `x*(2/π)` in `fq[0],..,fq[jk]` +* +* - `ih` integer. If >0 it indicates `q[]` is >= 0.5, hence it also indicates the _sign_ of the result. +* +* - Constants: +* +* - The hexadecimal values are the intended ones for the following constants. The decimal values may be used, provided that the compiler will convert from decimal to binary accurately enough to produce the hexadecimal values shown. +* +* @param x input value +* @param y output array to store the remainder +* @param e0 the exponent of `x[0]` (must be <= 127) +* @param nx dimension of `x[]` +* @return last 3 binary digits +*/ +int32_t rempio2fKernel( const double* x, double *y, int32_t e0, int32_t nx ) { + double F[ 20 ] = { 0.0 }; + double Q[ 20 ] = { 0.0 }; + int32_t IQ[ 20 ]; + double FQ[ 20 ]; + int32_t carry; + int32_t jz; + int32_t jx; + int32_t jv; + int32_t jp; + int32_t jk; + int32_t q0; + int32_t ih; + int32_t n; + int32_t i; + int32_t j; + int32_t k; + int32_t m; + double fw; + double z; + + // Initialize `jk` for single-precision floating-point numbers: + jk = 3; + jp = jk; + + // Determine `jx`, `jv`, `q0` (note that `q0 < 3`): + jx = nx - 1; + jv = ( e0 - 3 ) / 24; + if ( jv < 0 ) { + jv = 0; + } + q0 = e0 - ( 24 * ( jv + 1 ) ); + + // Set up `F[0]` to `F[jx+jk]` where `F[jx+jk] = IPIO2[jv+jk]`: + j = jv - jx; + m = jx + jk; + for ( i = 0; i <= m; i++ ) { + if ( j < 0 ) { + F[ i ] = ZERO; + } else { + F[ i ] = ( double )IPIO2[ j ]; + } + j++; + } + + // Compute `Q[0],Q[1],...,Q[jk]`: + for ( i = 0; i <= jk; i++ ) { + fw = 0.0; + for ( j = 0; j <= jx; j++ ) { + fw += x[ j ] * F[ jx + ( i - j ) ]; + } + Q[ i ] = fw; + } + + jz = jk; +recompute: + // Distill `q[]` into `IQ[]` in reverse order... + z = Q[ jz ]; + j = jz; + for ( i = 0; j > 0; i++ ) { + fw = ( double )( ( int32_t )( TWON24 * z ) ); + IQ[ i ] = (int32_t)( z - ( TWO24 * fw ) ); + z = Q[ j - 1 ] + fw; + j--; + } + // Compute `n`... + z = stdlib_base_ldexp( z, q0 ); + z -= 8.0 * stdlib_base_floor( z * 0.125 ); // Trim off integer >= 8 + n = ( int32_t )z; + z -= ( double )n; + ih = 0; + if ( q0 > 0 ) { + // Need `IQ[jz-1]` to determine `n`... + i = ( IQ[ jz - 1 ] >> ( 24 - q0 ) ); + n += i; + IQ[ jz - 1 ] -= ( i << ( 24 - q0 ) ); + ih = ( IQ[ jz - 1 ] >> ( 23 - q0 ) ); + } else if ( q0 == 0 ) { + ih = ( IQ[ jz - 1 ] >> 23 ); + } else if ( z >= 0.5 ) { + ih = 2; + } + + // Case: q > 0.5 + if ( ih > 0 ) { + n += 1; + carry = 0; + // Compute `1-q`: + for ( i = 0; i < jz; i++ ) { + j = IQ[ i ]; + if ( carry == 0 ) { + if ( j != 0 ) { + carry = 1; + IQ[ i ] = 0x1000000 - j; + } + } else { + IQ[ i ] = 0xffffff - j; + } + } + if ( q0 > 0 ) { + // Rare case: chance is 1 in 12... + switch ( q0 ) { + case 1: + IQ[ jz - 1 ] &= 0x7fffff; + break; + case 2: + IQ[ jz - 1 ] &= 0x3fffff; + break; + } + } + if ( ih == 2 ) { + z = 1.0 - z; + if ( carry != 0 ) { + z -= stdlib_base_ldexp( 1.0, q0 ); + } + } + } + + // Check if re-computation is needed... + if ( z == ZERO ) { + j = 0; + for ( i = jz - 1; i >= jk; i-- ) { + j |= IQ[ i ]; + } + if ( j == 0 ) { + // Need re-computation... + for ( k = 1; IQ[ jk - k ] == 0; k++ ) { + // `k` is the number of terms needed... + } + + for ( i = jz + 1; i <= jz + k; i++ ) { + // Add `q[jz+1]` to `q[jz+k]`... + F[ jx + i ] = ( double )IPIO2[ jv + i ]; + fw = 0.0; + for ( j = 0; j <= jx; j++ ) { + fw += x[ j ] * F[ jx + ( i - j ) ]; + } + Q[ i ] = fw; + } + jz += k; + goto recompute; + } + // Chop off zero terms... + jz -= 1; + q0 -= 24; + while ( IQ[ jz ] == 0 ) { + jz--; + q0 -= 24; + } + } else { + // Break `z` into 24-bit if necessary... + z = stdlib_base_ldexp( z, -q0 ); + if ( z >= TWO24 ) { + fw = ( double )( ( int32_t )( TWON24 * z ) ); + IQ[ jz ] = ( int32_t )( z - ( TWO24 * fw ) ); + jz += 1; + q0 += 24; + IQ[ jz ] = ( int32_t )fw; + } else { + IQ[ jz ] = ( int32_t )z; + } + } + + // Convert integer "bit" chunk to floating-point value... + fw = stdlib_base_ldexp( 1.0, q0 ); + for ( i = jz; i >= 0; i-- ) { + Q[ i ] = fw * ( double )IQ[ i ]; + fw *= TWON24; + } + + // Compute `PIO2[0,...,jp]*q[jz,...,0]`... + for ( i = jz; i >= 0; i-- ) { + fw = 0.0; + for ( k = 0; k <= jp && k <= jz - i; k++ ) { + fw += PIO2[ k ] * Q[ i + k ]; + } + FQ[ jz - i ] = fw; + } + // Compress `FQ[]` into `y[]`... + fw = 0.0; + for ( i = jz; i >= 0; i-- ) { + fw += FQ[ i ]; + } + if ( ih == 0 ) { + y[ 0 ] = fw; + } else { + y[ 0 ] = -fw; + } + return n & 7; +} + + +/** +* Computes `x - nπ/2 = r` (single-precision). +* +* @param x input value +* @param rem remainder element +* @return factor of `π/2` +* +* @example +* #include <stdint.h> +* +* double rem; +* int32_t n = stdlib_base_rempio2f( 128.0f, &rem ); +*/ +int32_t stdlib_base_rempio2f( const float x, double *rem ) { + double TX[ 1 ]; + double TY[ 1 ]; + uint32_t uhx; + int32_t ix; + int32_t hx; + int32_t e0; + int32_t n; + double w; + double r; + float z; + + // high word of x + stdlib_base_float32_to_word( x, &uhx ); + hx = ( int32_t )uhx; + ix = hx & STDLIB_CONSTANT_FLOAT32_ABS_MASK; + + // Case: |x| ~< 2^28*π/2 (medium size) + if ( ix < MEDIUM ) { + n = stdlib_base_roundf( x * INVPIO2 ); + r = x - ( n * PIO2_1 ); + w = n * PIO2_1T; + *rem = r - w; + return n; + } + // Case: x is NaN or infinity + if( ix >= STDLIB_CONSTANT_FLOAT32_EXPONENT_MASK ) { + *rem = 0.0 / 0.0; // NaN + return 0; + } + // Set z = scalbn(|x|, ilogb(|x|)-23)... + e0 = ( ix >> 23 ) - 150; // `e0 = ilogb(|x|) - 23` => unbiased exponent minus 23 + stdlib_base_float32_from_word( ix - ( int32_t ) ( e0 << 23 ), &z ); + TX[ 0 ] = z; + n = rempio2fKernel( TX, TY, e0, 1 ); + if ( hx < 0 ) { + *rem = -TY[ 0 ]; + return -n; + } + *rem = TY[ 0 ]; + return n; +} diff --git a/lib/node_modules/@stdlib/math/base/special/rempio2f/test/test.js b/lib/node_modules/@stdlib/math/base/special/rempio2f/test/test.js new file mode 100644 index 000000000000..afd61fce3234 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/test/test.js @@ -0,0 +1,266 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isInteger = require( '@stdlib/assert/is-integer' ); +var isNumber = require( '@stdlib/assert/is-number' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var incrspace = require( '@stdlib/array/base/incrspace' ); +var linspace = require( '@stdlib/array/base/linspace' ); +var randu = require( '@stdlib/random/base/randu' ); +var absf = require( '@stdlib/math/base/special/absf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var PIO2 = require( '@stdlib/constants/float32/half-pi' ); +var PIO4 = require( '@stdlib/constants/float32/fourth-pi' ); +var rempio2f = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof rempio2f, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `0` and sets `y[0]` to `NaN` if provided `NaN`', function test( t ) { + var y = [ 0.0 ]; + var n = rempio2f( NaN, y ); + t.strictEqual( n, 0.0, 'returns expected value' ); + t.strictEqual( isnanf( y[0] ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `0` and sets `y[0]` to `NaN` if provided positive or negative infinity', function test( t ) { + var y = [ 0.0 ]; + var n = rempio2f( PINF, y ); + t.strictEqual( n, 0.0, 'returns expected value' ); + t.strictEqual( isnanf( y[0] ), true, 'returns expected value' ); + + y = [ 0.0 ]; + n = rempio2f( NINF, y ); + t.strictEqual( n, 0.0, 'returns expected value' ); + t.strictEqual( isnanf( y[0] ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `n` and stores `r` as a double-precision floating point number in `y` such that `x - nπ/2 = r` (positive)', function test( t ) { + var delta; + var tol; + var x; + var y; + var z; + var n; + var i; + + y = [ 0.0 ]; + for ( i = 0; i < 200; i++ ) { + x = float64ToFloat32( randu()*100.0 ); + n = rempio2f( x, y ); + + t.strictEqual( isInteger( n ), true, 'returns expected value' ); + t.strictEqual( isNumber( y[ 0 ] ), true, 'returns expected value' ); + + z = float64ToFloat32( ( PIO2*n ) + ( y[0] ) ); + delta = absf( z - x ); + tol = EPS * absf( x ); + t.ok( delta <= tol, 'within tolerance. x: '+x+'. n: '+n+'. y: '+y+'. z: '+z+'. delta: '+delta+'. tol: '+tol+'.' ); + } + t.end(); +}); + +tape( 'the function returns `n` and stores `r` as a double-precision floating point number in `y` such that `x - nπ/2 = r` (tiny positive)', function test( t ) { + var delta; + var tol; + var x; + var y; + var z; + var n; + var i; + + y = [ 0.0 ]; + for ( i = 0; i < 200; i++ ) { + x = float64ToFloat32( randu()*1.0e-100 ); + n = rempio2f( x, y ); + + t.strictEqual( isInteger( n ), true, 'returns expected value' ); + t.strictEqual( isNumber( y[0] ), true, 'returns expected value' ); + + z = float64ToFloat32( ( PIO2*n ) + ( y[0] ) ); + delta = absf( z - x ); + tol = EPS * absf( x ); + t.ok( delta <= tol, 'within tolerance. x: '+x+'. n: '+n+'. y: '+y+'. z: '+z+'. delta: '+delta+'. tol: '+tol+'.' ); + } + t.end(); +}); + +tape( 'the function returns `n` and stores `r` as a double-precision floating point number in `y` such that `x - nπ/2 = r` (negative)', function test( t ) { + var delta; + var tol; + var x; + var y; + var z; + var n; + var i; + + y = [ 0.0 ]; + for ( i = 0; i < 200; i++ ) { + x = float64ToFloat32( -100.0 * randu() ); + n = rempio2f( x, y ); + + t.strictEqual( isInteger( n ), true, 'returns expected value' ); + t.strictEqual( isNumber( y[0] ), true, 'returns expected value' ); + + z = float64ToFloat32( ( PIO2*n ) + ( y[0] ) ); + delta = absf( z - x ); + tol = EPS * absf( x ); + t.ok( delta <= tol, 'within tolerance. x: '+x+'. n: '+n+'. y: '+y+'. z: '+z+'. delta: '+delta+'. tol: '+tol+'.' ); + } + t.end(); +}); + +tape( 'the function returns `n` and stores `r` as a double-precision floating point number in `y` such that `x - nπ/2 = r` (tiny negative)', function test( t ) { + var delta; + var tol; + var x; + var y; + var z; + var n; + var i; + + y = [ 0.0 ]; + for ( i = 0; i < 200; i++ ) { + x = float64ToFloat32( -1.0e-100 * randu() ); + n = rempio2f( x, y ); + + t.strictEqual( isInteger( n ), true, 'returns expected value' ); + t.strictEqual( isNumber( y[0] ), true, 'returns expected value' ); + + z = float64ToFloat32( ( PIO2*n ) + ( y[0] ) ); + delta = absf( z - x ); + tol = EPS * absf( x ); + t.ok( delta <= tol, 'within tolerance. x: '+x+'. n: '+n+'. y: '+y+'. z: '+z+'. delta: '+delta+'. tol: '+tol+'.' ); + } + t.end(); +}); + +tape( 'the function returns `n` and stores `r` as a double-precision floating point number in `y` such that `x - nπ/2 = r` (multiples of π/4)', function test( t ) { + var delta; + var tol; + var x; + var y; + var z; + var n; + var i; + + x = incrspace( -10.0*PIO4, 10.0*PIO4, PIO4 ); + y = [ 0.0 ]; + for ( i = 0; i < x.length; i++ ) { + x[i] = float64ToFloat32( x[i] ); + n = rempio2f( x[i], y ); + + t.strictEqual( isInteger( n ), true, 'returns expected value' ); + t.strictEqual( isNumber( y[0] ), true, 'returns expected value' ); + + z = float64ToFloat32( ( PIO2*n ) + ( y[0] ) ); + delta = absf( z - x[i] ); + tol = EPS * absf( x[i] ); + t.ok( delta <= tol, 'within tolerance. x: '+x+'. n: '+n+'. y: '+y+'. z: '+z+'. delta: '+delta+'. tol: '+tol+'.' ); + } + t.end(); +}); + +tape( 'for large positive input values, the function returns the last three binary digits of `n` and stores `r` as a double-precision floating point number in `y`', function test( t ) { + var x; + var y; + var n; + var i; + + x = linspace( pow( 2.0, 28 )*PIO2, pow( 2.0, 60 )*PIO2, 4000 ); + y = [ 0.0 ]; + for ( i = 0; i < x.length; i++ ) { + x[i] = float64ToFloat32( x[i] ); + n = rempio2f( x[i], y ); + t.strictEqual( isInteger( n ), true, 'returns expected value' ); + t.strictEqual( isNumber( y[0] ), true, 'returns expected value' ); + t.strictEqual( n < 8, true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'for large negative input values, the function returns the last three binary digits of `n` and stores `r` as a double-precision floating point number in `y`', function test( t ) { + var x; + var y; + var n; + var i; + + x = linspace( -pow( 2.0, 28 )*PIO2, -pow( 2.0, 60 )*PIO2, 4000 ); + y = [ 0.0 ]; + for ( i = 0; i < x.length; i++ ) { + x[i] = float64ToFloat32( x[i] ); + n = rempio2f( x[i], y ); + t.strictEqual( isInteger( n ), true, 'returns expected value' ); + t.strictEqual( isNumber( y[0] ), true, 'returns expected value' ); + t.strictEqual( n < 8, true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'for huge positive input values, the function returns the last three binary digits of `n` and stores `r` as a double-precision floating point number in `y`', function test( t ) { + var x; + var y; + var n; + var i; + + x = linspace( pow( 2.0, 60 )*PIO2, pow( 2.0, 125 )*PIO2, 6000 ); + y = [ 0.0 ]; + for ( i = 0; i < x.length; i++ ) { + x[i] = float64ToFloat32( x[i] ); + n = rempio2f( x[i], y ); + t.strictEqual( isInteger( n ), true, 'returns expected value' ); + t.strictEqual( isNumber( y[0] ), true, 'returns expected value' ); + t.strictEqual( n < 8, true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'for huge negative input values, the function returns the last three binary digits of `n` and stores `r` as a double-precision floating point number in `y`', function test( t ) { + var x; + var y; + var n; + var i; + + x = linspace( -pow( 2.0, 60 )*PIO2, -pow( 2.0, 125 )*PIO2, 6000 ); + y = [ 0.0 ]; + for ( i = 0; i < x.length; i++ ) { + x[i] = float64ToFloat32( x[i] ); + n = rempio2f( x[i], y ); + t.strictEqual( isInteger( n ), true, 'returns expected value' ); + t.strictEqual( isNumber( y[0] ), true, 'returns expected value' ); + t.strictEqual( n < 8, true, 'returns expected value' ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/rempio2f/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/rempio2f/test/test.native.js new file mode 100644 index 000000000000..3e935a0bf446 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/test/test.native.js @@ -0,0 +1,276 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 isInteger = require( '@stdlib/assert/is-integer' ); +var isNumber = require( '@stdlib/assert/is-number' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var incrspace = require( '@stdlib/array/base/incrspace' ); +var linspace = require( '@stdlib/array/base/linspace' ); +var randu = require( '@stdlib/random/base/randu' ); +var absf = require( '@stdlib/math/base/special/absf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var PIO2 = require( '@stdlib/constants/float32/half-pi' ); +var PIO4 = require( '@stdlib/constants/float32/fourth-pi' ); +var Float64Array = require( '@stdlib/array/float64' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var rempio2f = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( rempio2f instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof rempio2f, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `0` and sets `y[0]` to `NaN` if provided `NaN`', opts, function test( t ) { + var y = new Float64Array( [ 0.0 ] ); + var n = rempio2f( NaN, y ); + t.strictEqual( n, 0.0, 'returns expected value' ); + t.strictEqual( isnanf( y[0] ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `0` and sets `y[0]` to `NaN` if provided positive or negative infinity', opts, function test( t ) { + var y = new Float64Array( [ 0.0 ] ); + var n = rempio2f( PINF, y ); + t.strictEqual( n, 0.0, 'returns expected value' ); + t.strictEqual( isnanf( y[0] ), true, 'returns expected value' ); + + y = new Float64Array( [ 0.0 ] ); + n = rempio2f( NINF, y ); + t.strictEqual( n, 0.0, 'returns expected value' ); + t.strictEqual( isnanf( y[0] ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `n` and stores `r` as a double-precision floating point number in `y` such that `x - nπ/2 = r` (positive)', opts, function test( t ) { + var delta; + var tol; + var x; + var y; + var z; + var n; + var i; + + y = new Float64Array( [ 0.0 ] ); + for ( i = 0; i < 200; i++ ) { + x = float64ToFloat32( randu()*100.0 ); + n = rempio2f( x, y ); + + t.strictEqual( isInteger( n ), true, 'returns expected value' ); + t.strictEqual( isNumber( y[ 0 ] ), true, 'returns expected value' ); + + z = float64ToFloat32( ( PIO2*n ) + ( y[0] ) ); + delta = absf( z - x ); + tol = EPS * absf( x ); + t.ok( delta <= tol, 'within tolerance. x: '+x+'. n: '+n+'. y: '+y+'. z: '+z+'. delta: '+delta+'. tol: '+tol+'.' ); + } + t.end(); +}); + +tape( 'the function returns `n` and stores `r` as a double-precision floating point number in `y` such that `x - nπ/2 = r` (tiny positive)', opts, function test( t ) { + var delta; + var tol; + var x; + var y; + var z; + var n; + var i; + + y = new Float64Array( [ 0.0 ] ); + for ( i = 0; i < 200; i++ ) { + x = float64ToFloat32( randu()*1.0e-100 ); + n = rempio2f( x, y ); + + t.strictEqual( isInteger( n ), true, 'returns expected value' ); + t.strictEqual( isNumber( y[0] ), true, 'returns expected value' ); + + z = float64ToFloat32( ( PIO2*n ) + ( y[0] ) ); + delta = absf( z - x ); + tol = EPS * absf( x ); + t.ok( delta <= tol, 'within tolerance. x: '+x+'. n: '+n+'. y: '+y+'. z: '+z+'. delta: '+delta+'. tol: '+tol+'.' ); + } + t.end(); +}); + +tape( 'the function returns `n` and stores `r` as a double-precision floating point number in `y` such that `x - nπ/2 = r` (negative)', opts, function test( t ) { + var delta; + var tol; + var x; + var y; + var z; + var n; + var i; + + y = new Float64Array( [ 0.0 ] ); + for ( i = 0; i < 200; i++ ) { + x = float64ToFloat32( -100.0 * randu() ); + n = rempio2f( x, y ); + + t.strictEqual( isInteger( n ), true, 'returns expected value' ); + t.strictEqual( isNumber( y[0] ), true, 'returns expected value' ); + + z = float64ToFloat32( ( PIO2*n ) + ( y[0] ) ); + delta = absf( z - x ); + tol = EPS * absf( x ); + t.ok( delta <= tol, 'within tolerance. x: '+x+'. n: '+n+'. y: '+y+'. z: '+z+'. delta: '+delta+'. tol: '+tol+'.' ); + } + t.end(); +}); + +tape( 'the function returns `n` and stores `r` as a double-precision floating point number in `y` such that `x - nπ/2 = r` (tiny negative)', opts, function test( t ) { + var delta; + var tol; + var x; + var y; + var z; + var n; + var i; + + y = new Float64Array( [ 0.0 ] ); + for ( i = 0; i < 200; i++ ) { + x = float64ToFloat32( -1.0e-100 * randu() ); + n = rempio2f( x, y ); + + t.strictEqual( isInteger( n ), true, 'returns expected value' ); + t.strictEqual( isNumber( y[0] ), true, 'returns expected value' ); + + z = float64ToFloat32( ( PIO2*n ) + ( y[0] ) ); + delta = absf( z - x ); + tol = EPS * absf( x ); + t.ok( delta <= tol, 'within tolerance. x: '+x+'. n: '+n+'. y: '+y+'. z: '+z+'. delta: '+delta+'. tol: '+tol+'.' ); + } + t.end(); +}); + +tape( 'the function returns `n` and stores `r` as a double-precision floating point number in `y` such that `x - nπ/2 = r` (multiples of π/4)', opts, function test( t ) { + var delta; + var tol; + var x; + var y; + var z; + var n; + var i; + + x = incrspace( -10.0*PIO4, 10.0*PIO4, PIO4 ); + y = new Float64Array( [ 0.0 ] ); + for ( i = 0; i < x.length; i++ ) { + x[i] = float64ToFloat32( x[i] ); + n = rempio2f( x[i], y ); + + t.strictEqual( isInteger( n ), true, 'returns expected value' ); + t.strictEqual( isNumber( y[0] ), true, 'returns expected value' ); + + z = float64ToFloat32( ( PIO2*n ) + ( y[0] ) ); + delta = absf( z - x[i] ); + tol = EPS * absf( x[i] ); + t.ok( delta <= tol, 'within tolerance. x: '+x+'. n: '+n+'. y: '+y+'. z: '+z+'. delta: '+delta+'. tol: '+tol+'.' ); + } + t.end(); +}); + +tape( 'for large positive input values, the function returns the last three binary digits of `n` and stores `r` as a double-precision floating point number in `y`', opts, function test( t ) { + var x; + var y; + var n; + var i; + + x = linspace( pow( 2.0, 28 )*PIO2, pow( 2.0, 60 )*PIO2, 4000 ); + y = new Float64Array( [ 0.0 ] ); + for ( i = 0; i < x.length; i++ ) { + x[i] = float64ToFloat32( x[i] ); + n = rempio2f( x[i], y ); + t.strictEqual( isInteger( n ), true, 'returns expected value' ); + t.strictEqual( isNumber( y[0] ), true, 'returns expected value' ); + t.strictEqual( n < 8, true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'for large negative input values, the function returns the last three binary digits of `n` and stores `r` as a double-precision floating point number in `y`', opts, function test( t ) { + var x; + var y; + var n; + var i; + + x = linspace( -pow( 2.0, 28 )*PIO2, -pow( 2.0, 60 )*PIO2, 4000 ); + y = new Float64Array( [ 0.0 ] ); + for ( i = 0; i < x.length; i++ ) { + x[i] = float64ToFloat32( x[i] ); + n = rempio2f( x[i], y ); + t.strictEqual( isInteger( n ), true, 'returns expected value' ); + t.strictEqual( isNumber( y[0] ), true, 'returns expected value' ); + t.strictEqual( n < 8, true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'for huge positive input values, the function returns the last three binary digits of `n` and stores `r` as a double-precision floating point number in `y`', opts, function test( t ) { + var x; + var y; + var n; + var i; + + x = linspace( pow( 2.0, 60 )*PIO2, pow( 2.0, 125 )*PIO2, 6000 ); + y = new Float64Array( [ 0.0 ] ); + for ( i = 0; i < x.length; i++ ) { + x[i] = float64ToFloat32( x[i] ); + n = rempio2f( x[i], y ); + t.strictEqual( isInteger( n ), true, 'returns expected value' ); + t.strictEqual( isNumber( y[0] ), true, 'returns expected value' ); + t.strictEqual( n < 8, true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'for huge negative input values, the function returns the last three binary digits of `n` and stores `r` as a double-precision floating point number in `y`', opts, function test( t ) { + var x; + var y; + var n; + var i; + + x = linspace( -pow( 2.0, 60 )*PIO2, -pow( 2.0, 125 )*PIO2, 6000 ); + y = new Float64Array( [ 0.0 ] ); + for ( i = 0; i < x.length; i++ ) { + x[i] = float64ToFloat32( x[i] ); + n = rempio2f( x[i], y ); + t.strictEqual( isInteger( n ), true, 'returns expected value' ); + t.strictEqual( isNumber( y[0] ), true, 'returns expected value' ); + t.strictEqual( n < 8, true, 'returns expected value' ); + } + t.end(); +});