diff --git a/lib/node_modules/@stdlib/math/base/special/rempio2/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/rempio2/benchmark/benchmark.native.js index d231943ea28c..3c82f68f4c5c 100644 --- a/lib/node_modules/@stdlib/math/base/special/rempio2/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/rempio2/benchmark/benchmark.native.js @@ -25,12 +25,13 @@ var bench = require( '@stdlib/bench' ); var randu = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var tryRequire = require( '@stdlib/utils/try-require' ); +var Float64Array = require( '@stdlib/array/float64' ); var pkg = require( './../package.json' ).name; // VARIABLES // -var rempio2 = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var rempio2 = tryRequire( resolve( __dirname, '../lib/native.js' ) ); var opts = { 'skip': ( rempio2 instanceof Error ) }; @@ -44,7 +45,7 @@ bench( pkg+'::native', opts, function benchmark( b ) { var n; var i; - y = [ 0.0, 0.0 ]; + y = new Float64Array( [ 0.0, 0.0 ] ); x = randu( 100, -100.0, 100.0 ); b.tic(); 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 + +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..a823c6fe2b4a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/README.md @@ -0,0 +1,219 @@ + + +# rempio2f + +> Compute `x - nπ/2 = r` using single precision. + +
+ +## Usage + +```javascript +var rempio2f = require( '@stdlib/math/base/special/rempio2f' ); +``` + +#### rempio2f( x, y ) + +Computes `x - nπ/2 = r` using single-precision arithmetic. + +```javascript +var y = [ 0.0 ]; +var n = rempio2f( 128.0, y ); +// returns 81 + +var y0 = y[ 0 ]; +// returns ~0.765 +``` + +When `x` is `NaN` or infinite, the function returns `0` and sets the element of `y` to `NaN`. + +```javascript +var y = [ 0.0 ]; +var n = rempio2f( NaN, y ); +// returns 0 + +var y0 = y[ 0 ]; +// returns NaN + +y = [ 0.0 ]; +n = rempio2f( Infinity, y ); +// returns 0 + +y0 = y[ 0 ]; +// returns NaN +``` + +
+ + + + + +
+ +## Notes + +- The function returns `n` and stores the remainder `r` as a single number in `y[0]`. +- For input values larger than `2^8*π/2` in magnitude, the function **only** returns the last three binary digits of `n` and not the full result. + +
+ + + +
+ +## Examples + + + +```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 ] ); +} +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ + +### Usage + +```c +#include "stdlib/math/base/special/rempio2f.h" +``` + +#### stdlib_base_rempio2f( x, &rem1 ) + +Computes `x - nπ/2 = r` using single-precision arithmetic. + +```c +#include + +float rem; + +int32_t n = stdlib_base_rempio2f( 4.0f, &rem ); +``` + +The function accepts the following arguments: + +- **x**: `[in] float` input value. +- **rem**: `[out] float*` destination for remainder number. + +```c +int32_t stdlib_base_rempio2f( const float x, float *rem ); +``` + + +
+ + + + + +
+ +### Notes + +- The function returns `n` and stores the remainder `r` in `rem`. + + +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/special/rempio2f.h" +#include +#include +#include + +int main( void ) { + const float x[] = { 0.0f, 1.0f, 4.0f, 128.0f }; + + float rem; + int32_t n; + int i; + for ( i = 0; i < 4; i++ ) { + n = stdlib_base_rempio2f( x[ i ], &rem ); + printf( "%f - %"PRId32"π/2 = %f\n", x[ i ], n, rem ); + } +} +``` + +
+ + + +
+ + + + + + + + + + + + + + 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..d76d937eb21e --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/benchmark/benchmark.js @@ -0,0 +1,54 @@ +/** +* @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 randu = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +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]; // Single-element array for single-precision remainder + x = randu(100, -100.0, 100.0); + + b.tic(); + for (i = 0; i < b.iterations; i++) { + n = rempio2f(x[i % x.length], y); + if (isnan(n)) { + b.fail('should not return NaN'); + } + } + b.toc(); + if (isnan(n) || isnan(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..5c966f90cdb2 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/benchmark/benchmark.native.js @@ -0,0 +1,64 @@ +/** +* @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 randu = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var Float32Array = require( '@stdlib/array/float32' ); +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 Float32Array( 1 ); + x = randu( 100, -100.0, 100.0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + n = rempio2f( x[ i % x.length ], y ); + if ( isnan( n ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( n ) || isnan( 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..e0fca492d5cf --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/benchmark/c/native/benchmark.c @@ -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. +*/ + +#include "stdlib/math/base/special/rempio2f.h" +#include "stdlib/math/base/assert/is_nanf.h" +#include +#include +#include +#include +#include + +#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 double rand_double( void ) { + int r = rand(); + return (double)r / ( (double)RAND_MAX + 1.0 ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + float x[ 100 ]; + double elapsed; + float rem; + double t; + int i; + + for ( i = 0; i < 100; i++ ) { + x[ i ] = (float)(( rand_double() * 200.0 ) - 100.0 ); + } + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + stdlib_base_rempio2f( x[ i % 100 ], &rem ); + if ( isnanf( rem ) ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( isnanf( rem ) ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + + int i; + double elapsed; + + // 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..f134a97ccaec --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/docs/repl.txt @@ -0,0 +1,32 @@ +{{alias}}( x, y ) + Computes `x - nπ/2 = r`. + + The function returns `n` and stores the remainder `r` as a single number + in `y[0]`. + + For input values larger than `2^20 * π/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 (single value). + + 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..35c2b845b0c4 --- /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 + +/// + +import { Collection } from '@stdlib/types/array'; + +/** +* Computes `x - nπ/2 = r`. +* +* ## Notes +* +* - The function returns `n` and stores the remainder `r` as a single number in `y[0]`. +* - For input values larger than `2^20 * π/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 (single value) +* @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; + + +// 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. +*/ + +/// + +import { Collection } from '@stdlib/types/array'; +import rempio2f = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const y: Collection = [ 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 = [ 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..fbdb82d96da2 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/examples/c/example.c @@ -0,0 +1,37 @@ +/** +* @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 +#include +#include + +int main(void) { + const float x[] = { 0.0f, 1.0f, 4.0f, 128.0f }; // Single-precision floats + + float rem; // Single remainder value + int32_t n; + int i; + + for (i = 0; i < 4; i++) { + n = stdlib_base_rempio2f(x[i], &rem); // Single remainder output + printf("%f - %"PRId32"π/2 = %f\n", x[i], n, rem); + } + + return 0; +} 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..fa6617db7d19 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/examples/index.js @@ -0,0 +1,37 @@ +/** +* @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 linspace = require( '@stdlib/array/base/linspace' ); +var rempio2f = require( './../lib' ); + + +// MAIN // + +var x = linspace(0.0, 100.0, 100); +var y = [0.0]; // Single-element array for the remainder +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': [ + ' + +/* +* 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` using single precision. +*/ +int32_t stdlib_base_rempio2f( const float x, float *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..3a0c8fcda5dd --- /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` using 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..766a8349d8bc --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/lib/kernel_rempio2f.js @@ -0,0 +1,241 @@ +/** +* @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. +* ``` +*/ + +'use strict'; + +// MODULES // + +var floorf = require( '@stdlib/math/base/special/floorf' ); +var ldexpf = require( '@stdlib/math/base/special/ldexpf' ); +var zeros = require( '@stdlib/array/base/zeros' ); + + +// VARIABLES // + +// Table of constants for 2/π (first few terms for single precision): +var IPIO2 = [ + 0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62, 0x95993C, 0xD8B3D3, 0x4A9D0D +]; + +// π/2 for single precision (24-bit precision): +var PIO2 = [ + 1.570796251, // 0x3fc90fda + 4.960468e-8, // 0x33522168 + 2.5893025e-8, // 0x32d849ba + 1.9539925e-11 // 0x2f2e71d2 +]; +var TWO24 = 1.6777216e7; // 0x4b800000 +var TWON24 = 5.9604645e-8; // 0x33800000 + +// Temporary arrays (smaller for single precision): +var F = zeros( 10 ); +var Q = zeros( 10 ); +var FQ = zeros( 10 ); +var IQ = zeros( 10 ); + + +// FUNCTIONS // + +/** +* Performs the computation for `kernelRempio2f()`. +* +* @private +* @param {Array} x - input value array +* @param {(Array|TypedArray|Object)} y - output array for single remainder +* @param {integer} jz - number of terms of `ipio2[]` used +* @param {Array} q - array with integral values, representing the 24-bit chunks of the product of `x` and `2/π` +* @param {integer} q0 - the corresponding exponent of `q[0]` (exponent for `q[i]` is `q0-24*i`) +* @param {integer} jk - `jk+1` is the initial number of terms of `IPIO2[]` needed +* @param {integer} jv - index for pointing to the suitable `ipio2[]` +* @param {integer} jx - `nx - 1` +* @param {Array} 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 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 = ldexpf( z, q0 ); + z -= 8.0 * floorf( z * 0.125 ); // Trim off integer >= 8 + n = z|0; + z -= n; + ih = (z >= 0.5) ? 2 : 0; + + // Case: z > 0.5 + if ( ih > 0 ) { + n += 1; + z = 1.0 - z; // No carry needed for single precision + } + + // 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++ ) { + 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 >= 0 ) { + jz -= 1; + q0 -= 24; + } + } else { + // Break `z` into 24-bit chunks if necessary... + z = ldexpf( 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 chunks to floating-point... + fw = ldexpf( 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[]` (single value for single precision)... + fw = 0.0; + for ( i = jz; i >= 0; i-- ) { + fw += FQ[i]; + } + y[0] = (ih === 0) ? fw : -fw; + return (n & 7); +} + +/** +* Returns the last three binary digits of `N` with `y = x - Nπ/2` so that `|y| < π/2` using single precision. +* +* @private +* @param {Array} x - input value array +* @param {(Array|TypedArray|Object)} y - remainder array (single value) +* @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: + jk = 3; + + // Determine `jx`, `jv`, `q0`: + 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]`: + j = jv - jx; + m = jx + jk; + for ( i = 0; i <= m; i++ ) { + F[i] = (j < 0) ? 0.0 : 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..67b37f4e7e70 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/lib/main.js @@ -0,0 +1,214 @@ +/** +* @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 +* +* Adapted from the original implementation available as part of [FreeBSD]{@link https://svnweb.freebsd.org/base/release/9.3.0/lib/msun/src/e_rem_pio2.c}. +* +* ```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' ); // 0x7fffffff +var EXPONENT_MASK = require( '@stdlib/constants/float32/exponent-mask' ); // 0x7f800000 +var SIGNIFICAND_MASK = require( '@stdlib/constants/float32/significand-mask' ); // 0x007fffff +var getWord = require( '@stdlib/number/float32/base/to-word' ); // Single word for 32-bit float +var fromWord = require( '@stdlib/number/float32/base/from-word' ); +var rempio2fKernel = require( './kernel_rempio2f.js' ); // Adjusted kernel for float +var rempio2fMedium = require( './rempio2f_medium.js' ); // Adjusted medium range function + + +// VARIABLES // + +var ZERO = 0.0; // 0x00000000 +var TWO8 = 256.0; // 0x43800000 (2^8 for 32-bit scaling) + +// 24 bits of π/2 (single precision): +var PIO2_1 = 1.57079632679; // 0x3fc90fdb + +// PIO2_1T = π/2 - PIO2_1 (less precision): +var PIO2_1T = 4.960468e-8; // 0x33a22169 +var TWO_PIO2_1T = 2.0 * PIO2_1T; +var THREE_PIO2_1T = 3.0 * PIO2_1T; +var FOUR_PIO2_1T = 4.0 * PIO2_1T; + +// High word significand for π and π/2: 0x490fdb => 0010010010000111111011011 +var PI_HIGH_WORD_SIGNIFICAND = 0x490fdb|0; + +// High word constants (32-bit float representation): +var PIO4_HIGH_WORD = 0x3f490fdb|0; // π/4: 0.785398163 +var THREE_PIO4_HIGH_WORD = 0x4016cbe4|0; // 3π/4: 2.35619449 +var FIVE_PIO4_HIGH_WORD = 0x405497ce|0; // 5π/4: 3.926990817 +var THREE_PIO2_HIGH_WORD = 0x4096cbe4|0; // 3π/2: 4.71238898 +var SEVEN_PIO4_HIGH_WORD = 0x40b78909|0; // 7π/4: 5.497787144 +var TWO_PI_HIGH_WORD = 0x40c90fdb|0; // 2π: 6.283185307 +var NINE_PIO4_HIGH_WORD = 0x40fb53d1|0; // 9π/4: 7.068583471 + +// Medium threshold: 2^8 * π/2 ≈ 402.123859659 +var MEDIUM = 0x43c90fdb|0; + +// Temporary arrays (smaller for single precision): +var TX = [ 0.0, 0.0 ]; +var TY = [ 0.0 ]; + + +// MAIN // + +/** +* Computes `x - nπ/2 = r` for single-precision floating-point values. +* +* ## Notes +* +* - Returns `n` and stores the remainder `r` in `y[0]`. +* +* @param {number} x - input value (single precision) +* @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 y0 = y[ 0 ]; +* // returns ~0.765 +* +* @example +* var y = [ 0.0 ]; +* var n = rempio2f( NaN, y ); +* // returns 0 +* +* var y0 = y[ 0 ]; +* // returns NaN +*/ +function rempio2f( x, y ) { + var e0; + var ix; + var nx; + var w; + var i; + var n; + var z; + + w = getWord( x ); + ix = (w & ABS_MASK)|0; + + // Case: |x| ~<= π/4 + if ( ix <= PIO4_HIGH_WORD ) { + y[ 0 ] = x; + return 0; + } + // Case: |x| ~<= 5π/4 + if ( ix <= FIVE_PIO4_HIGH_WORD ) { + // Case: |x| ~= π/2 or π + if ( (ix & SIGNIFICAND_MASK) === PI_HIGH_WORD_SIGNIFICAND ) { + return rempio2fMedium( x, ix, y ); + } + // Case: |x| ~<= 3π/4 + if ( ix <= THREE_PIO4_HIGH_WORD ) { + if ( x > 0.0 ) { + z = x - PIO2_1; + y[ 0 ] = z - PIO2_1T; + return 1; + } + z = x + PIO2_1; + y[ 0 ] = z + PIO2_1T; + return -1; + } + if ( x > 0.0 ) { + z = x - ( 2.0 * PIO2_1 ); + y[ 0 ] = z - TWO_PIO2_1T; + return 2; + } + z = x + ( 2.0 * PIO2_1 ); + y[ 0 ] = z + TWO_PIO2_1T; + return -2; + } + // Case: |x| ~<= 9π/4 + if ( ix <= NINE_PIO4_HIGH_WORD ) { + // Case: |x| ~<= 7π/4 + if ( ix <= SEVEN_PIO4_HIGH_WORD ) { + if ( ix === THREE_PIO2_HIGH_WORD ) { + return rempio2fMedium( x, ix, y ); + } + if ( x > 0.0 ) { + z = x - ( 3.0 * PIO2_1 ); + y[ 0 ] = z - THREE_PIO2_1T; + return 3; + } + z = x + ( 3.0 * PIO2_1 ); + y[ 0 ] = z + THREE_PIO2_1T; + return -3; + } + if ( ix === TWO_PI_HIGH_WORD ) { + return rempio2fMedium( x, ix, y ); + } + if ( x > 0.0 ) { + z = x - ( 4.0 * PIO2_1 ); + y[ 0 ] = z - FOUR_PIO2_1T; + return 4; + } + z = x + ( 4.0 * PIO2_1 ); + y[ 0 ] = z + FOUR_PIO2_1T; + return -4; + } + // Case: |x| ~< 2^8 * π/2 (medium size) + if ( ix < MEDIUM ) { + return rempio2fMedium( x, ix, y ); + } + // console.log("Inside kernel for x", x); + // Case: x is NaN or infinity + if ( ix >= EXPONENT_MASK ) { + y[ 0 ] = NaN; + return 0; + } + // Set z = scalbn(|x|, ilogb(x) - 7) for 8-bit chunks... + e0 = (ix >> 23) - 134; // ilogb(x) - 7 (127 bias + 7 for 24-bit significand shift) + z = fromWord( ix - ((e0 << 23)|0) ); + for ( i = 0; i < 2; i++ ) { + TX[ i ] = z|0; + z = (z - TX[i]) * TWO8; + } + nx = 2; + while ( TX[ nx-1 ] === ZERO ) { + nx -= 1; + } + n = rempio2fKernel( TX, TY, e0, nx ); + if ( x < 0.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..d8830145a384 --- /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` using single precision. +* +* @private +* @param {number} x - input value +* @param {Float32Array} y - remainder elements +* @returns {integer} factor of `π/2` +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var y = new Float32Array(1); +* 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/lib/rempio2f_medium.js b/lib/node_modules/@stdlib/math/base/special/rempio2f/lib/rempio2f_medium.js new file mode 100644 index 000000000000..056899512a5c --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/lib/rempio2f_medium.js @@ -0,0 +1,99 @@ +/** +* @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. +* ``` +*/ + +'use strict'; + +// MODULES // + +var round = require( '@stdlib/math/base/special/round' ); +var getWord = require( '@stdlib/number/float32/base/to-word' ); // Single-precision word + + +// VARIABLES // + +// 24 bits of 2/π (single precision): +var INVPIO2 = 0.636619772; // 0x3f22f983 + +// First 24 bits of π/2: +var PIO2_1 = 1.570796326; // 0x3fc90fda + +// PIO2_1T = π/2 - PIO2_1: +var PIO2_1T = 4.960468e-8; // 0x33522168 + +// Exponent mask (255 => 0xff for single precision): +var EXPONENT_MASK = 0xff|0; // asm type annotation + + +// MAIN // + +/** +* Computes `x - nπ/2 = r` for medium-sized inputs using single precision. +* +* @private +* @param {number} x - input value +* @param {uint32} ix - word of `x` (single precision) +* @param {(Array|TypedArray|Object)} y - remainder element (single value) +* @returns {integer} factor of `π/2` +*/ +function rempio2fMedium( x, ix, y ) { + var word; + var n; + var t; + var r; + var w; + var i; + var j; + + n = round( x * INVPIO2 ); + r = x - ( n * PIO2_1 ); + w = n * PIO2_1T; + + // First rounding (good to 24 bits for single precision)... + j = (ix >> 23)|0; // Exponent from 32-bit word + y[ 0 ] = r - w; + word = getWord( y[ 0 ] ); + i = j - ( (word >> 23) & EXPONENT_MASK ); + + // Check if a second iteration is needed... + if ( i > 16 ) { + t = r; + w = n * PIO2_1T; + r = t - w; + y[ 0 ] = r; + } + // No y[1] for single precision + return n; +} + + +// EXPORTS // + +module.exports = rempio2fMedium; 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..0d1b76145f8a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/manifest.json @@ -0,0 +1,76 @@ +{ + "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-float32array", + "@stdlib/napi/create-double", + "@stdlib/napi/export", + "@stdlib/math/base/special/floorf", + "@stdlib/math/base/special/roundf", + "@stdlib/math/base/special/ldexpf", + "@stdlib/number/float32/base/from-word", + "@stdlib/number/float32/base/to-word" + ] + }, + { + "task": "benchmark", + "src": ["./src/main.c"], + "include": ["./include"], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/special/roundf", + "@stdlib/math/base/special/floorf", + "@stdlib/math/base/special/ldexpf", + "@stdlib/number/float32/base/from-word", + "@stdlib/number/float32/base/to-word" + ] + }, + { + "task": "examples", + "src": ["./src/main.c"], + "include": ["./include"], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/special/roundf", + "@stdlib/math/base/special/floorf", + "@stdlib/math/base/special/ldexpf", + "@stdlib/number/float32/base/from-word", + "@stdlib/number/float32/base/to-word" + ] + } + ] +} 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..793e29926d52 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/math/base/special/rempio2f", + "version": "0.0.0", + "description": "Compute `x - nπ/2 = r`. (single-precision)", + "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", + "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..951750e8bd13 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/src/addon.c @@ -0,0 +1,46 @@ +/** +* @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" // For single-precision input +#include "stdlib/napi/argv_float32array.h" // For single-precision array output +#include "stdlib/napi/create_double.h" +#include "stdlib/napi/export.h" +#include + +/** +* 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 ); // Input x as float + STDLIB_NAPI_ARGV_FLOAT32ARRAY( env, y, ylen, argv, 1 ); // Output y as Float32Array + if (ylen < 1) { + napi_throw_error( env, NULL, "Expected output array to have at least 1 element" ); + return NULL; + } + STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_base_rempio2f( x, &y[0] ), n ); // Single remainder + 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..44bc5bcc2d83 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/src/main.c @@ -0,0 +1,341 @@ +/** +* @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_pio2.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/floorf.h" +#include "stdlib/math/base/special/ldexpf.h" +#include "stdlib/number/float32/base/from_word.h" +#include "stdlib/number/float32/base/to_word.h" +#include + +// Single-precision constants: +static const float ZERO = 0.0f; // 0x00000000 +static const float TWO24 = 1.6777216e7f; // 0x4b800000 (2^24 for scaling) +static const float TWON24 = 5.9604645e-8f; // 0x33800000 (2^-24 for normalization) +static const float INVPIO2 = 0.636619772f; // 0x3f22f983 (2/π for quick estimation) +static const float PIO2_1 = 1.57079632679f; // 0x3fc90fdb (π/2, primary term) +static const float PIO2_1T = 4.960468e-8f; // 0x33a22169 (π/2 tail term) + +// High word constants for single precision: +static const int32_t PIO4_HIGH_WORD = 0x3f490fdb; // π/4: 0.785398163 +static const int32_t THREE_PIO4_HIGH_WORD = 0x4016cbe4; // 3π/4: 2.35619449 +static const int32_t FIVE_PIO4_HIGH_WORD = 0x405497ce; // 5π/4: 3.926990817 +static const int32_t THREE_PIO2_HIGH_WORD = 0x4096cbe4; // 3π/2: 4.71238898 +static const int32_t SEVEN_PIO4_HIGH_WORD = 0x40b78909; // 7π/4: 5.497787144 +static const int32_t TWO_PI_HIGH_WORD = 0x40c90fdb; // 2π: 6.283185307 +static const int32_t NINE_PIO4_HIGH_WORD = 0x40fb53d1; // 9π/4: 7.068583471 +static const int32_t MEDIUM = 0x43c90fdb; // 2^8 * π/2 ≈ 402.123859659 +static const int32_t EXPONENT_MASK = 0x7f800000; // Exponent mask (0x7f8 => 255) + +// Table of constants for `2/π` (96 hex digits, 115 decimal): +// Integer array containing the (24*i)-th to (24*i+23)-th bit of `2/π` after the binary point. +// The corresponding floating value is `IPIO2[i] * 2^(-24(i+1))`. +// For single precision (e0 <= 127, jk = 3), this table has sufficient terms. +static const int32_t IPIO2[] = { + 0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62, 0x95993C, 0xD8B3D3, 0x4A9D0D +}; + +/** +* Single-precision kernel for rempio2 computation with single remainder. +* +* ## Method +* +* - Computes the integer (mod 8) and fractional parts of (2/π) * x without full multiplication, skipping known integer parts (0 mod 8), making operations independent of the input exponent. +* +* - `2/π` is represented by an array of 24-bit integers in `IPIO2[]`. +* +* - Input parameters: +* +* - `x[]` The input value (must be positive) broken into `nx` 24-bit chunks in single-precision format. `x[i]` is the i-th 24-bit segment of x. The scaled exponent of `x[0]` is given by `e0` (i.e., `x[0] * 2^e0` matches x up to 24 bits). +* +* Example: Breaking a float positive `z` into `x[0] + x[1]`: +* ``` +* e0 = ilogb(z) - 23 +* z = scalbn(z, -e0) +* for i = 0, 1: +* x[i] = floor(z) +* z = (z - x[i]) * 2^24 +* ``` +* +* - `rem` Output remainder stored as a single float. +* +* - `e0` Exponent of `x[0]`. Must be <= 8188 or the `IPIO2` table needs expansion. +* +* - `nx` Dimension of `x[]`. +* +* - External functions: +* +* - `float stdlib_base_ldexpf()`, `stdlib_base_floorf()` +* +* - Local variables: +* +* - `jk` Initial number of `IPIO2[]` terms needed (3 for single precision). +* +* - `jp` Number of terms needed in the final remainder computation (equals `jk`). +* +* - `jz` Number of `IPIO2[]` terms used. +* +* - `jx` `nx - 1`. +* +* - `jv` Index for selecting `IPIO2[]` terms, ensuring `(2^e0 * x[0] * IPIO2[jv-1] * 2^(-24jv)) / 8` is an integer: `jv = max(0, (e0 - 3) / 24)`. +* +* - `q0` Exponent of the product `Q[0]`, with `Q[i]` having exponent `q0 - 24*i`. +* +* - `F[]` `IPIO2[]` in floating-point form. +* +* - `Q[]` Float array representing 24-bit chunks of `x * (2/π)`. +* +* - `IQ[]` Integer array breaking `Q[]` into 24-bit chunks. +* +* - `ih` Indicates if `Q[] >= 0.5` (sign of result). +* +* - Constants: +* +* - Hexadecimal values are intended; decimal values must convert accurately to these hex values. +* +* @param x input value array +* @param rem output remainder (single value) +* @param e0 exponent of x[0] +* @param nx dimension of x[] +* @return last 3 binary digits of N +*/ +static int32_t rempio2f_kernel(const float* x, float* rem, int32_t e0, int32_t nx) { + float F[10] = {0.0f}; + float Q[10] = {0.0f}; + int32_t IQ[10]; + float z; + float fw; + 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; + + // Initialize for single precision: + jk = 3; + jp = jk; + + // Determine indices: + 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; + for (i = 0; i <= jx + jk; i++) { + F[i] = (j < 0) ? ZERO : (float)IPIO2[j]; + j++; + } + + // Compute `Q[0], Q[1], ..., Q[jk]`: + for (i = 0; i <= jk; i++) { + fw = 0.0f; + for (j = 0; j <= jx; j++) { + fw += x[j] * F[jx + (i - j)]; + } + Q[i] = fw; + } + + jz = jk; + + // Distill `Q[]` into `IQ[]` in reverse order: + z = Q[jz]; + for (i = 0, j = jz; j > 0; i++, j--) { + fw = (float)((int32_t)(TWON24 * z)); + IQ[i] = (int32_t)(z - TWO24 * fw); + z = Q[j - 1] + fw; + } + + // Compute `n`: + z = stdlib_base_ldexpf(z, q0); + z -= 8.0f * stdlib_base_floorf(z * 0.125f); // Trim off integer >= 8 + n = (int32_t)z; + z -= (float)n; + ih = (z >= 0.5f) ? 2 : 0; + + // Case: z > 0.5 + if (ih > 0) { + n += 1; + z = 1.0f - z; + } + + // Check if re-computation is needed: + if (z == ZERO) { + jz--; + q0 -= 24; + while (jz >= 0 && IQ[jz] == 0) { + jz--; + q0 -= 24; + } + if (jz < 0) { + *rem = 0.0f; + return n & 7; + } + } + + // Convert to floating-point: + fw = stdlib_base_ldexpf(1.0f, q0); + for (i = jz; i >= 0; i--) { + Q[i] = fw * (float)IQ[i]; + fw *= TWON24; + } + + // Compute final remainder (single value): + fw = 0.0f; + for (i = 0; i <= jz && i <= jp; i++) { + fw += PIO2_1 * Q[i]; + } + *rem = (ih == 0) ? fw : -fw; + return n & 7; +} + +/** +* Computes `x - nπ/2 = r` using single precision with a single remainder. +* +* ## Notes +* +* - Returns `n` and stores the remainder `r` in `rem`. +* +* @param x input value +* @param rem remainder +* @return factor of `π/2` +* +* @example +* #include +* +* float rem; +* int32_t n = stdlib_base_rempio2f( 128.0f, &rem ); +*/ +int32_t stdlib_base_rempio2f(const float x, float *rem) { + float TX[2]; + uint32_t ux; + int32_t ix; + int32_t hx; + int32_t e0; + int32_t nx; + int32_t n; + float z; + + // Get word representation of x: + stdlib_base_float32_to_word(x, &ux); + hx = (int32_t)ux; + ix = hx & 0x7fffffff; + + // Case: |x| ~<= π/4 (no reduction needed) + if (ix <= PIO4_HIGH_WORD) { + *rem = x; + return 0; + } + + // Case: |x| ~<= 9π/4 + if (ix <= NINE_PIO4_HIGH_WORD) { + // Case: |x| ~<= 3π/4 + if (ix <= THREE_PIO4_HIGH_WORD) { + if (hx > 0) { + z = x - PIO2_1; + *rem = z - PIO2_1T; + return 1; + } else { + z = x + PIO2_1; + *rem = z + PIO2_1T; + return -1; + } + } + // Case: |x| ~<= 5π/4 + if (ix <= FIVE_PIO4_HIGH_WORD) { + if (hx > 0) { + z = x - (2.0f * PIO2_1); + *rem = z - (2.0f * PIO2_1T); + return 2; + } else { + z = x + (2.0f * PIO2_1); + *rem = z + (2.0f * PIO2_1T); + return -2; + } + } + // Case: |x| ~<= 7π/4 + if (ix <= SEVEN_PIO4_HIGH_WORD) { + if (hx > 0) { + z = x - (3.0f * PIO2_1); + *rem = z - (3.0f * PIO2_1T); + return 3; + } else { + z = x + (3.0f * PIO2_1); + *rem = z + (3.0f * PIO2_1T); + return -3; + } + } + // Case: |x| ~<= 9π/4 + if (hx > 0) { + z = x - (4.0f * PIO2_1); + *rem = z - (4.0f * PIO2_1T); + return 4; + } else { + z = x + (4.0f * PIO2_1); + *rem = z + (4.0f * PIO2_1T); + return -4; + } + } + + // Case: |x| ~< 2^8*π/2 (medium size) + if (ix < MEDIUM) { + n = (int32_t)stdlib_base_roundf(x * INVPIO2); + *rem = x - n * (PIO2_1 + PIO2_1T); + return n; + } + + // Case: x is NaN or infinity + if (ix >= EXPONENT_MASK) { + *rem = x - x; // NaN + return 0; + } + + // Set z = scalbn(|x|, ilogb(x)-7): + e0 = (ix >> 23) - 134; // ilogb(x) - 7 + stdlib_base_float32_from_word(ix - (e0 << 23), &z); + TX[0] = (float)((int32_t)z); + TX[1] = (z - TX[0]) * 256.0f; // TWO8 equivalent + nx = (TX[1] == ZERO) ? 1 : 2; + + n = rempio2f_kernel(TX, rem, e0, nx); + if (hx < 0) { + *rem = -*rem; + return -n; + } + 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..80c73ae30867 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/test/test.js @@ -0,0 +1,263 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var incrspace = require( '@stdlib/array/base/incrspace' ); +var linspace = require( '@stdlib/array/base/linspace' ); +var randu = require( '@stdlib/random/base/randu' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); // Changed to float32 +var NINF = require( '@stdlib/constants/float32/ninf' ); // Changed to float32 +var EPS = require( '@stdlib/constants/float32/eps' ); // Changed to float32 +var PIO2 = require( '@stdlib/constants/float32/half-pi' ); // Changed to float32 +var PIO4 = require( '@stdlib/constants/float32/fourth-pi' ); // Changed to float32 +var rempio2f = require( '@stdlib/math/base/special/rempio2f/lib' ); // Changed to rempio2f + + +// 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 the element of `y` to `NaN` if provided `NaN`', function test(t) { + var y = [0.0]; // Single-element array + var n = rempio2f(NaN, y); + t.strictEqual(n, 0, 'returns expected value'); + t.strictEqual(isnan(y[0]), true, 'y[0] is NaN'); + t.end(); +}); + +tape('the function returns `0` and sets the element of `y` to `NaN` if provided positive or negative infinity', function test(t) { + var y = [0.0]; // Single-element array + var n = rempio2f(PINF, y); + t.strictEqual(n, 0, 'returns expected value'); + t.strictEqual(isnan(y[0]), true, 'y[0] is NaN'); + + y = [0.0]; + n = rempio2f(NINF, y); + t.strictEqual(n, 0, 'returns expected value'); + t.strictEqual(isnan(y[0]), true, 'y[0] is NaN'); + t.end(); +}); + +tape('the function returns `n` and stores `r` as a single-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]; // Single-element array + for (i = 0; i < 200; i++) { + x = 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 = (PIO2 * n) + y[0]; // Only y[0] used + + delta = abs(z - x); + tol = EPS * abs(x); + t.strictEqual(delta <= tol, true, 'delta <= tol for x = ' + x); + } + + t.end(); +}); + +tape('the function returns `n` and stores `r` as a single-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]; // Single-element array + for (i = 0; i < 200; i++) { + x = randu() * 1.0e-30; // Tiny positive values + n = rempio2f(x, y); + + t.strictEqual(isInteger(n), true, 'returns expected value'); + t.strictEqual(isNumber(y[0]), true, 'returns expected value'); + + z = (PIO2 * n) + y[0]; // Single remainder term + delta = abs(z - x); + tol = EPS * abs(x); + t.strictEqual(delta <= tol, true, 'returns expected value'); + } + t.end(); +}); + +tape('the function returns `n` and stores `r` as a single-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]; // Single-element array + for (i = 0; i < 200; i++) { + x = -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 = (PIO2 * n) + y[0]; // Single remainder term + delta = abs(z - x); + tol = EPS * abs(x); + t.strictEqual(delta <= tol, true, 'returns expected value'); + } + t.end(); +}); + +tape('the function returns `n` and stores `r` as a single-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]; // Single-element array + for (i = 0; i < 200; i++) { + x = -1.0e-30 * randu(); // Tiny negative values + n = rempio2f(x, y); + + t.strictEqual(isInteger(n), true, 'returns expected value'); + t.strictEqual(isNumber(y[0]), true, 'returns expected value'); + + z = (PIO2 * n) + y[0]; // Single remainder term + delta = abs(z - x); + tol = EPS * abs(x); + t.strictEqual(delta <= tol, true, 'returns expected value'); + } + t.end(); +}); + +tape('the function returns `n` and stores `r` as a single-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]; // Single-element array + for (i = 0; i < x.length; i++) { + n = rempio2f(x[i], y); + + t.strictEqual(isInteger(n), true, 'returns expected value'); + t.strictEqual(isNumber(y[0]), true, 'returns expected value'); + + z = (PIO2 * n) + y[0]; // Single remainder term + delta = abs(z - x[i]); + tol = EPS * abs(x[i]); + t.strictEqual(delta <= tol, true, 'returns expected value'); + } + t.end(); +}); + +tape( 'for large positive input values, the function returns the last three binary digits of `n` and stores `r` as two single-precision floating point numbers in `y`', function test( t ) { + var x; + var y; + var n; + var i; + + x = linspace( pow( 2.0, 20 )*PIO2, pow( 2.0, 30 )*PIO2, 4000 ); // Reduced upper bound for single precision + y = [ 0.0, 0.0 ]; + for ( i = 0; i < x.length; 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( isNumber( y[1] ), 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 single-precision floating point number in `y`', function test(t) { + var x; + var y; + var n; + var i; + + x = linspace(-pow(2.0, 20) * PIO2, -pow(2.0, 25) * PIO2, 4000); // Adjusted for single precision + y = [0.0]; // Single-element array + for (i = 0; i < x.length; 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 single-precision floating point number in `y`', function test(t) { + var x; + var y; + var n; + var i; + + x = linspace(pow(2.0, 30) * PIO2, pow(2.0, 126) * PIO2, 6000); // Adjusted for single precision + y = [0.0]; // Single-element array + for (i = 0; i < x.length; 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 single-precision floating point number in `y`', function test(t) { + var x; + var y; + var n; + var i; + + x = linspace(pow(2.0, 30) * PIO2, pow(2.0, 126) * PIO2, 6000); // Adjusted for single precision + y = [0.0]; // Single-element array + for (i = 0; i < x.length; 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..2d7ea6898aa6 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/rempio2f/test/test.native.js @@ -0,0 +1,268 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var incrspace = require( '@stdlib/array/base/incrspace' ); +var linspace = require( '@stdlib/array/base/linspace' ); +var randu = require( '@stdlib/random/base/randu' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var PIO2 = require( '@stdlib/constants/float32/half-pi' ); +var PIO4 = require( '@stdlib/constants/float32/fourth-pi' ); +var Float32Array = require( '@stdlib/array/float32' ); +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 the element of `y` to `NaN` if provided `NaN`', opts, function test(t) { + var y = new Float32Array(1); // Single-element array + var n = rempio2f(NaN, y); + t.strictEqual(n, 0, 'returns expected value'); + t.strictEqual(isnan(y[0]), true, 'y[0] is NaN'); + t.end(); +}); + +tape('the function returns `0` and sets the element of `y` to `NaN` if provided positive or negative infinity', opts, function test(t) { + var y = new Float32Array(1); // Single-element array + var n = rempio2f(PINF, y); + t.strictEqual(n, 0, 'returns expected value'); + t.strictEqual(isnan(y[0]), true, 'y[0] is NaN'); + + y = new Float32Array(1); // Reset for next test + n = rempio2f(NINF, y); + t.strictEqual(n, 0, 'returns expected value'); + t.strictEqual(isnan(y[0]), true, 'y[0] is NaN'); + t.end(); +}); + +tape('the function returns `n` and stores `r` as a single-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 Float32Array(1); // Single-element array + for (i = 0; i < 200; i++) { + x = 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 = (PIO2 * n) + y[0]; + delta = abs(z - x); + tol = EPS * abs(x); + t.strictEqual(delta <= tol, true, 'can recover input value'); + } + t.end(); +}); + +tape('the function returns `n` and stores `r` as a single-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 Float32Array(1); // Single-element array + for (i = 0; i < 200; i++) { + x = randu() * 1.0e-30; + n = rempio2f(x, y); + + t.strictEqual(isInteger(n), true, 'returns expected value'); + t.strictEqual(isNumber(y[0]), true, 'returns expected value'); + + z = (PIO2 * n) + y[0]; + delta = abs(z - x); + tol = EPS * abs(x); + t.strictEqual(delta <= tol, true, 'can recover input value'); + } + t.end(); +}); + +tape('the function returns `n` and stores `r` as a single-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 Float32Array(1); // Single-element array + for (i = 0; i < 200; i++) { + x = -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 = (PIO2 * n) + y[0]; + delta = abs(z - x); + tol = EPS * abs(x); + t.strictEqual(delta <= tol, true, 'can recover input value'); + } + t.end(); +}); + +tape('the function returns `n` and stores `r` as a single-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 Float32Array(1); // Single-element array + for (i = 0; i < 200; i++) { + x = -1.0e-30 * randu(); + n = rempio2f(x, y); + + t.strictEqual(isInteger(n), true, 'returns expected value'); + t.strictEqual(isNumber(y[0]), true, 'returns expected value'); + + z = (PIO2 * n) + y[0]; + delta = abs(z - x); + tol = EPS * abs(x); + t.strictEqual(delta <= tol, true, 'can recover input value'); + } + t.end(); +}); + +tape('the function returns `n` and stores `r` as a single-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 Float32Array(1); // Single-element array + for (i = 0; i < x.length; i++) { + n = rempio2f(x[i], y); + + t.strictEqual(isInteger(n), true, 'returns expected value'); + t.strictEqual(isNumber(y[0]), true, 'returns expected value'); + + z = (PIO2 * n) + y[0]; + delta = abs(z - x[i]); + tol = EPS * abs(x[i]); + t.strictEqual(delta <= tol, true, 'can recover input value'); + } + t.end(); +}); + +tape('for large positive input values, the function returns the last three binary digits of `n` and stores `r` as a single-precision floating point number in `y`', opts, function test(t) { + var x; + var y; + var n; + var i; + + x = linspace(pow(2.0, 20) * PIO2, pow(2.0, 30) * PIO2, 4000); + y = new Float32Array(1); // Single-element array + for (i = 0; i < x.length; 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 single-precision floating point number in `y`', opts, function test(t) { + var x; + var y; + var n; + var i; + + x = linspace(-pow(2.0, 20) * PIO2, -pow(2.0, 30) * PIO2, 4000); + y = new Float32Array(1); // Single-element array + for (i = 0; i < x.length; 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 single-precision floating point number in `y`', opts, function test(t) { + var x; + var y; + var n; + var i; + + x = linspace(pow(2.0, 30) * PIO2, pow(2.0, 126) * PIO2, 6000); // Adjusted for single precision + y = new Float32Array(1); // Single-element array + for (i = 0; i < x.length; 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 single-precision floating point number in `y`', opts, function test(t) { + var x; + var y; + var n; + var i; + + x = linspace(-pow(2.0, 30) * PIO2, -pow(2.0, 126) * PIO2, 6000); // Adjusted for single precision + y = new Float32Array(1); // Single-element array + for (i = 0; i < x.length; 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(); +});