diff --git a/lib/node_modules/@stdlib/math/base/special/cfloornf/README.md b/lib/node_modules/@stdlib/math/base/special/cfloornf/README.md new file mode 100644 index 000000000000..ad2bf6a800a9 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/README.md @@ -0,0 +1,257 @@ + + +# cfloornf + +> Round each component of a single-precision complex floating-point number to the nearest multiple of `10^n` toward negative infinity. + +
+ +## Usage + +```javascript +var cfloornf = require( '@stdlib/math/base/special/cfloornf' ); +``` + +#### cfloornf( z, n ) + +Rounds each component of a single-precision complex floating-point number to the nearest multiple of `10^n` toward negative infinity. + +```javascript +var Complex64 = require( '@stdlib/complex/float32/ctor' ); + +// Round components to the nearest ten: +var v = cfloornf( new Complex64( -15.0, 15.0 ), 1 ); +// returns [ -20.0, 10.0 ] + +// If n = 0, `cfloornf` behaves like `cfloorf`: +v = cfloornf( new Complex64( -3.14, 3.14 ), 0 ); +// returns [ -4.0, 3.0 ] + +// Round components to the nearest hundred: +v = cfloornf( new Complex64( -150.0, 150.0 ), 2 ); +// returns [ -200.0, 100.0 ] + +v = cfloornf( new Complex64( NaN, NaN ), 0 ); +// returns [ NaN, NaN ] +``` + +
+ + + +
+ +## Notes + +- When operating on [floating-point numbers][ieee754] in bases other than `2`, rounding to specified digits can be **inexact**. For example, + + ```javascript + var Complex64 = require( '@stdlib/complex/float32/ctor' ); + var f32 = require( '@stdlib/number/float64/base/to-float32' ); + + var x = f32( -0.2 - 0.1 ); + // returns ~-0.30000001192092896 + + // Should round components to -0.3, but may differ due to float32 precision: + var v = cfloornf( new Complex64( x, x ), -6 ); + ``` + +
+ + + +
+ +## Examples + + + +```javascript +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var randint = require( '@stdlib/random/base/discrete-uniform' ); +var cfloornf = require( '@stdlib/math/base/special/cfloornf' ); + +var z; +var w; +var n; +var i; + +for ( i = 0; i < 100; i++ ) { + z = new Complex64( uniform( -50.0, 50.0 ), uniform( -50.0, 50.0 ) ); + + n = randint( -5.0, 0.0 ); + w = cfloornf( z, n ); + + console.log( 'cfloornf(%s,%s) = %s', z.toString(), n.toString(), w.toString() ); +} +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/math/base/special/cfloornf.h" +``` + +#### stdlib_base_cfloornf( z, n ) + +Rounds each component of a single-precision complex floating-point number to the nearest multiple of `10^n` toward negative infinity. + +```c +#include "stdlib/complex/float32/ctor.h" +#include "stdlib/complex/float32/real.h" +#include "stdlib/complex/float32/imag.h" + +stdlib_complex64_t z = stdlib_complex64( -3.14f, 3.14f ); +stdlib_complex64_t out = stdlib_base_cfloornf( z, -2 ); + +float re = stdlib_complex64_real( out ); +// returns -3.15f + +float im = stdlib_complex64_imag( out ); +// returns 3.14f +``` + +The function accepts the following arguments: + +- **z**: `[in] stdlib_complex64_t` input value. +- **n**: `[in] int32_t` integer power of 10. + +```c +stdlib_complex64_t stdlib_base_cfloornf( const stdlib_complex64_t z, const int32_t n ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/special/cfloornf.h" +#include "stdlib/complex/float32/ctor.h" +#include "stdlib/complex/float32/reim.h" +#include + +int main( void ) { + const stdlib_complex64_t x[] = { + stdlib_complex64( 3.14f, 1.5f ), + stdlib_complex64( -3.14f, -1.5f ), + stdlib_complex64( 0.0f, 0.0f ), + stdlib_complex64( 0.0f/0.0f, 0.0f/0.0f ) + }; + + stdlib_complex64_t v; + stdlib_complex64_t y; + float re1; + float im1; + float re2; + float im2; + int i; + for ( i = 0; i < 4; i++ ) { + v = x[ i ]; + y = stdlib_base_cfloornf( v, -2 ); + stdlib_complex64_reim( v, &re1, &im1 ); + stdlib_complex64_reim( y, &re2, &im2 ); + printf( "cfloornf(%f + %fi, -2) = %f + %fi\n", re1, im1, re2, im2 ); + } +} +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/math/base/special/cfloornf/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/cfloornf/benchmark/benchmark.js new file mode 100644 index 000000000000..1d01f3b2b5ab --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/benchmark/benchmark.js @@ -0,0 +1,58 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var real = require( '@stdlib/complex/float32/real' ); +var imag = require( '@stdlib/complex/float32/imag' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var pkg = require( './../package.json' ).name; +var cfloornf = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var y; + var i; + + values = [ + new Complex64( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ), + new Complex64( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = cfloornf( values[ i%values.length ], -2 ); + if ( isnanf( real( y ) ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( imag( y ) ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/cfloornf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/cfloornf/benchmark/benchmark.native.js new file mode 100644 index 000000000000..54ab10b27472 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/benchmark/benchmark.native.js @@ -0,0 +1,68 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var real = require( '@stdlib/complex/float32/real' ); +var imag = require( '@stdlib/complex/float32/imag' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var cfloornf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( cfloornf instanceof Error ) +}; + + +// MAIN // + +bench( format( '%s::native', pkg ), opts, function benchmark( b ) { + var values; + var y; + var i; + + values = [ + new Complex64( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ), + new Complex64( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = cfloornf( values[ i%values.length ], -2 ); + if ( isnanf( real( y ) ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( imag( y ) ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/cfloornf/benchmark/c/Makefile b/lib/node_modules/@stdlib/math/base/special/cfloornf/benchmark/c/Makefile new file mode 100644 index 000000000000..979768abbcec --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/cfloornf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/special/cfloornf/benchmark/c/benchmark.c new file mode 100644 index 000000000000..bd38e92ccfee --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/benchmark/c/benchmark.c @@ -0,0 +1,144 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/cfloornf.h" +#include "stdlib/complex/float32/ctor.h" +#include "stdlib/complex/float32/reim.h" +#include +#include +#include +#include +#include + +#define NAME "cfloornf" +#define ITERATIONS 1000000 +#define REPEATS 3 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param elapsed elapsed time in seconds +*/ +static void print_results( double elapsed ) { + double rate = (double)ITERATIONS / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [0,1). +* +* @return random number +*/ +static float rand_float( void ) { + int r = rand(); + return (float)r / ( (float)RAND_MAX + 1.0f ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + float v[ 100 ]; + double elapsed; + float re; + float im; + double t; + int i; + + stdlib_complex64_t x; + stdlib_complex64_t y; + + for ( i = 0; i < 100; i++ ) { + v[ i ] = ( 1000.0f * rand_float() ) - 500.0f; + } + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + x = stdlib_complex64( v[ i%100 ], v[ i%100 ] ); + y = stdlib_base_cfloornf( x, -2 ); + stdlib_complex64_reim( y, &re, &im ); + if ( re != re ) { + printf( "unexpected result\n" ); + break; + } + } + elapsed = tic() - t; + if ( im != im ) { + printf( "unexpected result\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int i; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + for ( i = 0; i < REPEATS; i++ ) { + printf( "# c::%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/cfloornf/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/cfloornf/benchmark/c/native/Makefile new file mode 100644 index 000000000000..979768abbcec --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/benchmark/c/native/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/cfloornf/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/cfloornf/benchmark/c/native/benchmark.c new file mode 100644 index 000000000000..41088b01eda4 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/benchmark/c/native/benchmark.c @@ -0,0 +1,144 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/cfloornf.h" +#include "stdlib/complex/float32/ctor.h" +#include "stdlib/complex/float32/reim.h" +#include +#include +#include +#include +#include + +#define NAME "cfloornf" +#define ITERATIONS 1000000 +#define REPEATS 3 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param elapsed elapsed time in seconds +*/ +static void print_results( double elapsed ) { + double rate = (double)ITERATIONS / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [0,1). +* +* @return random number +*/ +static float rand_float( void ) { + int r = rand(); + return (float)r / ( (float)RAND_MAX + 1.0f ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + float v[ 100 ]; + double elapsed; + float re; + float im; + double t; + int i; + + stdlib_complex64_t x; + stdlib_complex64_t y; + + for ( i = 0; i < 100; i++ ) { + v[ i ] = ( 1000.0f * rand_float() ) - 500.0f; + } + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + x = stdlib_complex64( v[ i%100 ], v[ i%100 ] ); + y = stdlib_base_cfloornf( x, -2 ); + stdlib_complex64_reim( y, &re, &im ); + if ( re != re ) { + printf( "unexpected result\n" ); + break; + } + } + elapsed = tic() - t; + if ( im != im ) { + printf( "unexpected result\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int i; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + for ( i = 0; i < REPEATS; i++ ) { + printf( "# c::native::%s\n", NAME ); + elapsed = benchmark(); + print_results( elapsed ); + printf( "ok %d benchmark finished\n", i+1 ); + } + print_summary( REPEATS, REPEATS ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/cfloornf/binding.gyp b/lib/node_modules/@stdlib/math/base/special/cfloornf/binding.gyp new file mode 100644 index 000000000000..0d6508a12e99 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/math/base/special/cfloornf/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/cfloornf/docs/repl.txt new file mode 100644 index 000000000000..9330583639ee --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/docs/repl.txt @@ -0,0 +1,26 @@ + +{{alias}}( z, n ) + Rounds each component of a single-precision complex floating-point number + to the nearest multiple of `10^n` toward negative infinity. + + Parameters + ---------- + z: Complex64 + Complex number. + + n: integer + Integer power of 10. + + Returns + ------- + z: Complex64 + Result. + + Examples + -------- + > var v = {{alias}}( new {{alias:@stdlib/complex/float32/ctor}}( 55.5, -33.3 ), 1 ) + [ 50.0, -40.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/math/base/special/cfloornf/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/cfloornf/docs/types/index.d.ts new file mode 100644 index 000000000000..2aa702d695b2 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/docs/types/index.d.ts @@ -0,0 +1,43 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Complex64 } from '@stdlib/types/complex'; + +/** +* Rounds each component of a single-precision complex floating-point number to the nearest multiple of `10^n` toward negative infinity. +* +* @param z - input value +* @param n - integer power of 10 +* @returns result +* +* @example +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* +* var v = cfloornf( new Complex64( 55.5, -33.3 ), 1 ); +* // returns [ 50.0, -40.0 ] +*/ +declare function cfloornf( z: Complex64, n: number ): Complex64; + + +// EXPORTS // + +export = cfloornf; diff --git a/lib/node_modules/@stdlib/math/base/special/cfloornf/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/cfloornf/docs/types/test.ts new file mode 100644 index 000000000000..bc3a790b32ef --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/docs/types/test.ts @@ -0,0 +1,60 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import Complex64 = require( '@stdlib/complex/float32/ctor' ); +import cfloornf = require( './index' ); + + +// TESTS // + +// The function returns a single-precision complex floating-point number... +{ + cfloornf( new Complex64( 1.0, 2.0 ), -2 ); // $ExpectType Complex64 +} + +// The compiler throws an error if the first argument of the function is provided a value other than a complex number... +{ + cfloornf( 3, -2 ); // $ExpectError + cfloornf( true, -2 ); // $ExpectError + cfloornf( false, -2 ); // $ExpectError + cfloornf( null, -2 ); // $ExpectError + cfloornf( undefined, -2 ); // $ExpectError + cfloornf( '5', -2 ); // $ExpectError + cfloornf( [], -2 ); // $ExpectError + cfloornf( {}, -2 ); // $ExpectError + cfloornf( ( x: number ): number => x, -2 ); // $ExpectError +} + +// The compiler throws an error if the second argument of the function is provided a value other than a number... +{ + cfloornf( new Complex64( 1.0, 2.0 ), 3, -2 ); // $ExpectError + cfloornf( new Complex64( 1.0, 2.0 ), true, -2 ); // $ExpectError + cfloornf( new Complex64( 1.0, 2.0 ), false, -2 ); // $ExpectError + cfloornf( new Complex64( 1.0, 2.0 ), null, -2 ); // $ExpectError + cfloornf( new Complex64( 1.0, 2.0 ), undefined, -2 ); // $ExpectError + cfloornf( new Complex64( 1.0, 2.0 ), '5', -2 ); // $ExpectError + cfloornf( new Complex64( 1.0, 2.0 ), [], -2 ); // $ExpectError + cfloornf( new Complex64( 1.0, 2.0 ), {}, -2 ); // $ExpectError + cfloornf( new Complex64( 1.0, 2.0 ), ( x: number ): number => x, -2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + cfloornf(); // $ExpectError + cfloornf( 2 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/math/base/special/cfloornf/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/cfloornf/examples/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/cfloornf/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/cfloornf/examples/c/example.c new file mode 100644 index 000000000000..0ded147bb471 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/examples/c/example.c @@ -0,0 +1,46 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/cfloornf.h" +#include "stdlib/complex/float32/ctor.h" +#include "stdlib/complex/float32/reim.h" +#include + +int main( void ) { + const stdlib_complex64_t x[] = { + stdlib_complex64( 3.14f, 1.5f ), + stdlib_complex64( -3.14f, -1.5f ), + stdlib_complex64( 0.0f, 0.0f ), + stdlib_complex64( 0.0f/0.0f, 0.0f/0.0f ) + }; + + stdlib_complex64_t v; + stdlib_complex64_t y; + float re1; + float im1; + float re2; + float im2; + int i; + for ( i = 0; i < 4; i++ ) { + v = x[ i ]; + y = stdlib_base_cfloornf( v, -2 ); + stdlib_complex64_reim( v, &re1, &im1 ); + stdlib_complex64_reim( y, &re2, &im2 ); + printf( "cfloornf(%f + %fi, -2) = %f + %fi\n", re1, im1, re2, im2 ); + } +} diff --git a/lib/node_modules/@stdlib/math/base/special/cfloornf/examples/index.js b/lib/node_modules/@stdlib/math/base/special/cfloornf/examples/index.js new file mode 100644 index 000000000000..fc447878d9c6 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/examples/index.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var randint = require( '@stdlib/random/base/discrete-uniform' ); +var cfloornf = require( './../lib' ); + +var z; +var w; +var n; +var i; + +for ( i = 0; i < 100; i++ ) { + z = new Complex64( uniform( -50.0, 50.0 ), uniform( -50.0, 50.0 ) ); + + n = randint( -5.0, 0.0 ); + w = cfloornf( z, n ); + + console.log( 'cfloornf(%s,%s) = %s', z.toString(), n.toString(), w.toString() ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/cfloornf/include.gypi b/lib/node_modules/@stdlib/math/base/special/cfloornf/include.gypi new file mode 100644 index 000000000000..bee8d41a2caf --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A GYP include file for building a Node.js native add-on. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + ' + +/* +* 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 + +/** +* Rounds each component of a single-precision complex floating-point number to the nearest multiple of `10^n` toward negative infinity. +*/ +stdlib_complex64_t stdlib_base_cfloornf( const stdlib_complex64_t z, const int32_t n ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_MATH_BASE_SPECIAL_CFLOORNF_H diff --git a/lib/node_modules/@stdlib/math/base/special/cfloornf/lib/index.js b/lib/node_modules/@stdlib/math/base/special/cfloornf/lib/index.js new file mode 100644 index 000000000000..852046c3ea0f --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/lib/index.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Round each component of a single-precision complex floating-point number to the nearest multiple of `10^n` toward negative infinity. +* +* @module @stdlib/math/base/special/cfloornf +* +* @example +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var cfloornf = require( '@stdlib/math/base/special/cfloornf' ); +* +* // Round components to the nearest ten: +* var v = cfloornf( new Complex64( -15.0, 15.0 ), 1 ); +* // returns [ -20.0, 10.0 ] +* +* // If n = 0, `cfloornf` behaves like `cfloorf`: +* v = cfloornf( new Complex64( 9.99999, 0.1 ), 0 ); +* // returns [ 9.0, 0.0 ] +* +* // Round components to the nearest hundred: +* v = cfloornf( new Complex64( 150.0, -150.0 ), 2 ); +* // returns [ 100.0, -200.0 ] +* +* v = cfloornf( new Complex64( NaN, NaN ), 2 ); +* // returns [ NaN, NaN ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/math/base/special/cfloornf/lib/main.js b/lib/node_modules/@stdlib/math/base/special/cfloornf/lib/main.js new file mode 100644 index 000000000000..5dbcb2981989 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/lib/main.js @@ -0,0 +1,63 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var floornf = require( '@stdlib/math/base/special/floornf' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var real = require( '@stdlib/complex/float32/real' ); +var imag = require( '@stdlib/complex/float32/imag' ); + + +// MAIN // + +/** +* Rounds each component of a single-precision complex floating-point number to the nearest multiple of `10^n` toward negative infinity. +* +* @param {Complex64} z - complex number +* @param {integer} n - integer power of 10 +* @returns {Complex64} result +* +* @example +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* +* // Round components to the nearest ten: +* var v = cfloornf( new Complex64( -15.0, 15.0 ), 1 ); +* // returns [ -20.0, 10.0 ] +* +* // If n = 0, `cfloornf` behaves like `cfloorf`: +* v = cfloornf( new Complex64( 9.99999, 0.1 ), 0 ); +* // returns [ 9.0, 0.0 ] +* +* // Round components to the nearest hundred: +* v = cfloornf( new Complex64( 150.0, -150.0 ), 2 ); +* // returns [ 100.0, -200.0 ] +* +* v = cfloornf( new Complex64( NaN, NaN ), 2 ); +* // returns [ NaN, NaN ] +*/ +function cfloornf( z, n ) { + return new Complex64( floornf( real( z ), n ), floornf( imag( z ), n ) ); +} + + +// EXPORTS // + +module.exports = cfloornf; diff --git a/lib/node_modules/@stdlib/math/base/special/cfloornf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/cfloornf/lib/native.js new file mode 100644 index 000000000000..fa78be0ea43d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/lib/native.js @@ -0,0 +1,63 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Rounds each component of a single-precision complex floating-point number to the nearest multiple of `10^n` toward negative infinity. +* +* @private +* @param {Complex64} z - complex number +* @param {integer} n - integer power of 10 +* @returns {Complex64} result +* +* @example +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* +* // Round components to the nearest ten: +* var v = cfloornf( new Complex64( -15.0, 15.0 ), 1 ); +* // returns [ -20.0, 10.0 ] +* +* // If n = 0, `cfloornf` behaves like `cfloorf`: +* v = cfloornf( new Complex64( 9.99999, 0.1 ), 0 ); +* // returns [ 9.0, 0.0 ] +* +* // Round components to the nearest hundred: +* v = cfloornf( new Complex64( 150.0, -150.0 ), 2 ); +* // returns [ 100.0, -200.0 ] +* +* v = cfloornf( new Complex64( NaN, NaN ), 2 ); +* // returns [ NaN, NaN ] +*/ +function cfloornf( z, n ) { + var v = addon( z, n ); + return new Complex64( v.re, v.im ); +} + + +// EXPORTS // + +module.exports = cfloornf; diff --git a/lib/node_modules/@stdlib/math/base/special/cfloornf/manifest.json b/lib/node_modules/@stdlib/math/base/special/cfloornf/manifest.json new file mode 100644 index 000000000000..c9b745224119 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/manifest.json @@ -0,0 +1,78 @@ +{ + "options": { + "task": "build" + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "task": "build", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/napi/binary", + "@stdlib/complex/float32/ctor", + "@stdlib/complex/float32/reim", + "@stdlib/math/base/special/floornf" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/complex/float32/ctor", + "@stdlib/complex/float32/reim", + "@stdlib/math/base/special/floornf" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/complex/float32/ctor", + "@stdlib/complex/float32/reim", + "@stdlib/math/base/special/floornf" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/cfloornf/package.json b/lib/node_modules/@stdlib/math/base/special/cfloornf/package.json new file mode 100644 index 000000000000..0152d3c532e0 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/package.json @@ -0,0 +1,74 @@ +{ + "name": "@stdlib/math/base/special/cfloornf", + "version": "0.0.0", + "description": "Round each component of a single-precision complex floating-point number to the nearest multiple of 10^n toward negative infinity.", + "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", + "math.floor", + "floor", + "cfloornf", + "round", + "integer", + "nearest", + "value", + "fix", + "tofixed", + "complex", + "cmplx", + "float32", + "single", + "number" + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/cfloornf/src/Makefile b/lib/node_modules/@stdlib/math/base/special/cfloornf/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/cfloornf/src/addon.c b/lib/node_modules/@stdlib/math/base/special/cfloornf/src/addon.c new file mode 100644 index 000000000000..fa358c1843b2 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/src/addon.c @@ -0,0 +1,22 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/cfloornf.h" +#include "stdlib/math/base/napi/binary.h" + +STDLIB_MATH_BASE_NAPI_MODULE_CI_C( stdlib_base_cfloornf ) diff --git a/lib/node_modules/@stdlib/math/base/special/cfloornf/src/main.c b/lib/node_modules/@stdlib/math/base/special/cfloornf/src/main.c new file mode 100644 index 000000000000..f2b7679ce4ea --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/src/main.c @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/cfloornf.h" +#include "stdlib/math/base/special/floornf.h" +#include "stdlib/complex/float32/ctor.h" +#include "stdlib/complex/float32/reim.h" +#include + +/** +* Rounds each component of a single-precision complex floating-point number to the nearest multiple of `10^n` toward negative infinity. +* +* @param z input value +* @param n integer power of 10 +* @return result +* +* @example +* #include "stdlib/complex/float32/ctor.h" +* #include "stdlib/complex/float32/real.h" +* #include "stdlib/complex/float32/imag.h" +* +* stdlib_complex64_t z = stdlib_complex64( -3.14f, 3.14f ); +* +* stdlib_complex64_t out = stdlib_base_cfloornf( z, -2 ); +* +* float re = stdlib_complex64_real( out ); +* // returns -3.15f +* +* float im = stdlib_complex64_imag( out ); +* // returns 3.14f +*/ +stdlib_complex64_t stdlib_base_cfloornf( const stdlib_complex64_t z, const int32_t n ) { + float re; + float im; + + stdlib_complex64_reim( z, &re, &im ); + + re = stdlib_base_floornf( re, n ); + im = stdlib_base_floornf( im, n ); + return stdlib_complex64( re, im ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/cfloornf/test/test.js b/lib/node_modules/@stdlib/math/base/special/cfloornf/test/test.js new file mode 100644 index 000000000000..21d1dd1b1d0c --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/test/test.js @@ -0,0 +1,278 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var powf = require( '@stdlib/math/base/special/powf' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var isNegativeZerof = require( '@stdlib/math/base/assert/is-negative-zerof' ); +var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var real = require( '@stdlib/complex/float32/real' ); +var imag = require( '@stdlib/complex/float32/imag' ); +var cfloornf = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cfloornf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a `NaN` if provided a `NaN`', function test( t ) { + var v; + + v = cfloornf( new Complex64( NaN, NaN ), 0 ); + t.strictEqual( isnanf( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isnanf( imag( v ) ), true, 'returns expected value' ); + + v = cfloornf( new Complex64( NaN, NaN ), NaN ); + t.strictEqual( isnanf( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isnanf( imag( v ) ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `NaNs` if provided `n = +-infinity`', function test( t ) { + var v; + + v = cfloornf( new Complex64( 3.14, 3.14 ), PINF ); + t.strictEqual( isnanf( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isnanf( imag( v ) ), true, 'returns expected value' ); + + v = cfloornf( new Complex64( 3.14, 3.14 ), NINF ); + t.strictEqual( isnanf( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isnanf( imag( v ) ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-0` if provided `-0`', function test( t ) { + var v; + + v = cfloornf( new Complex64( -0.0, -0.0 ), 0 ); + t.strictEqual( isNegativeZerof( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZerof( imag( v ) ), true, 'returns expected value' ); + + v = cfloornf( new Complex64( -0.0, -0.0 ), -2 ); + t.strictEqual( isNegativeZerof( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZerof( imag( v ) ), true, 'returns expected value' ); + + v = cfloornf( new Complex64( -0.0, -0.0 ), 2 ); + t.strictEqual( isNegativeZerof( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZerof( imag( v ) ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `+0` if provided `+0`', function test( t ) { + var v; + + v = cfloornf( new Complex64( +0.0, +0.0 ), 0 ); + t.strictEqual( isPositiveZerof( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( imag( v ) ), true, 'returns expected value' ); + + v = cfloornf( new Complex64( +0.0, +0.0 ), -2 ); + t.strictEqual( isPositiveZerof( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( imag( v ) ), true, 'returns expected value' ); + + v = cfloornf( new Complex64( +0.0, +0.0 ), 2 ); + t.strictEqual( isPositiveZerof( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( imag( v ) ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `+infinity` if provided `+infinity`', function test( t ) { + var v; + + v = cfloornf( new Complex64( PINF, PINF ), 5 ); + t.strictEqual( real( v ), PINF, 'returns expected value' ); + t.strictEqual( imag( v ), PINF, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `-infinity` if provided `-infinity`', function test( t ) { + var v; + + v = cfloornf( new Complex64( NINF, NINF ), -3 ); + t.strictEqual( real( v ), NINF, 'returns expected value' ); + t.strictEqual( imag( v ), NINF, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports rounding real and imaginary components to a desired number of decimals', function test( t ) { + var v; + + v = cfloornf( new Complex64( -3.141592653589793, 3.141592653589793 ), -2 ); + t.strictEqual( isAlmostSameValue( real( v ), f32( -3.15 ), 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( imag( v ), f32( 3.14 ), 1 ), true, 'returns expected value' ); + + v = cfloornf( new Complex64( 3.141592653589793, -3.141592653589793 ), -2 ); + t.strictEqual( isAlmostSameValue( real( v ), f32( 3.14 ), 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( imag( v ), f32( -3.15 ), 1 ), true, 'returns expected value' ); + + v = cfloornf( new Complex64( 9.99999, 9.99999 ), -2 ); + t.strictEqual( isAlmostSameValue( real( v ), f32( 9.99 ), 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( imag( v ), f32( 9.99 ), 1 ), true, 'returns expected value' ); + + v = cfloornf( new Complex64( -9.99999, -9.99999 ), -2 ); + t.strictEqual( isAlmostSameValue( real( v ), f32( -10.00 ), 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( imag( v ), f32( -10.00 ), 1 ), true, 'returns expected value' ); + + v = cfloornf( new Complex64( 0.0, 0.0 ), 2 ); + t.strictEqual( real( v ), 0.0, 'returns expected value' ); + t.strictEqual( imag( v ), 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports rounding components to a desired number of digits', function test( t ) { + var v; + + v = cfloornf( new Complex64( -1234.0, 1234.0 ), 2 ); + t.strictEqual( isAlmostSameValue( real( v ), -1300.0, 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( imag( v ), 1200.0, 1 ), true, 'returns expected value' ); + + v = cfloornf( new Complex64( 12363.0, -12373.0 ), 1 ); + t.strictEqual( isAlmostSameValue( real( v ), 12360.0, 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( imag( v ), -12380.0, 1 ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the components unchanged if provided an `n` which is less than the minimum decimal exponential (-45)', function test( t ) { + var exp; + var n; + var x; + var v; + var i; + for ( i = 0; i < 100; i++ ) { + exp = round( randu()*76.0 ) - 38; + x = f32( (1.0+randu()) * powf( 10.0, exp ) ); + n = -(round( randu()*100.0 ) + 46); + v = cfloornf( new Complex64( x, x ), n ); + t.strictEqual( real( v ), x, 'returns expected value' ); + t.strictEqual( imag( v ), x, 'returns expected value' ); + } + t.end(); +}); + +tape( 'if a component is too large a float to have decimals and `n < 0`, the component is returned unchanged', function test( t ) { + var sign; + var exp; + var x; + var n; + var v; + var i; + for ( i = 0; i < 100; i++ ) { + sign = ( randu()<0.5 ) ? -1.0 : 1.0; + exp = 8 + round( randu()*30.0 ); + x = f32( sign * (1.0+randu()) * powf( 10.0, exp ) ); + n = -( round( randu()*38.0) ); + v = cfloornf( new Complex64( x, x ), n ); + t.strictEqual( real( v ), x, ' returns expected value' ); + t.strictEqual( imag( v ), x, ' returns expected value' ); + } + t.end(); +}); + +tape( 'if `n > 38` and a component is less than zero, the function returns `-infinity`', function test( t ) { + var exp; + var x; + var n; + var v; + var i; + for ( i = 0; i < 100; i++ ) { + exp = round( randu()*37.0 ); + x = f32( -(1.0+randu()) * powf( 10.0, exp ) ); + n = round( randu()*10.0 ) + 39; + v = cfloornf( new Complex64( x, x ), n ); + t.strictEqual( real( v ), NINF, ' returns -infinity' ); + t.strictEqual( imag( v ), NINF, ' returns -infinity' ); + } + t.end(); +}); + +tape( 'if `n > 38` and a component is greater than or equal to zero, the function returns `+0` (sign preserving)', function test( t ) { + var exp; + var x; + var n; + var v; + var i; + for ( i = 0; i < 100; i++ ) { + exp = round( randu()*37.0 ); + x = f32( (1.0+randu()) * powf( 10.0, exp ) ); + n = round( randu()*10.0 ) + 39; + v = cfloornf( new Complex64( x, x ), n ); + t.strictEqual( isPositiveZerof( real( v ) ), true, ' returns +0' ); + t.strictEqual( isPositiveZerof( imag( v ) ), true, ' returns +0' ); + } + t.end(); +}); + +tape( 'if the function encounters overflow, the function returns the input component', function test( t ) { + var x; + var v; + + x = f32( 3.14 ); + v = cfloornf( new Complex64( x, x ), -46 ); + t.strictEqual( real( v ), x, 'returns expected value' ); + t.strictEqual( imag( v ), x, 'returns expected value' ); + + x = f32( -3.14 ); + v = cfloornf( new Complex64( x, x ), -46 ); + t.strictEqual( real( v ), x, 'returns expected value' ); + t.strictEqual( imag( v ), x, 'returns expected value' ); + + x = f32( 16777216.0 ); + v = cfloornf( new Complex64( x, x ), -40 ); + t.strictEqual( real( v ), x, 'returns expected value' ); + t.strictEqual( imag( v ), x, 'returns expected value' ); + + x = f32( -16777216.0 ); + v = cfloornf( new Complex64( x, x ), -40 ); + t.strictEqual( real( v ), x, 'returns expected value' ); + t.strictEqual( imag( v ), x, 'returns expected value' ); + + t.end(); +}); + +tape( 'rounding components to a desired number of decimals can result in unexpected behavior due to floating-point representation', function test( t ) { + var x; + var v; + + x = f32( -0.2 - 0.1 ); + v = cfloornf( new Complex64( x, x ), -6 ); + + // The result may differ slightly from -0.3 due to float32 precision: + t.strictEqual( isnanf( real( v ) ), false, 'returns a number and not NaN' ); + t.strictEqual( isnanf( imag( v ) ), false, 'returns a number and not NaN' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/cfloornf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/cfloornf/test/test.native.js new file mode 100644 index 000000000000..580bde4cf837 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/test/test.native.js @@ -0,0 +1,229 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var powf = require( '@stdlib/math/base/special/powf' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var isNegativeZerof = require( '@stdlib/math/base/assert/is-negative-zerof' ); +var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var real = require( '@stdlib/complex/float32/real' ); +var imag = require( '@stdlib/complex/float32/imag' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var cfloornf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( cfloornf instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cfloornf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a `NaN` if provided a `NaN`', opts, function test( t ) { + var v; + + v = cfloornf( new Complex64( NaN, NaN ), 0 ); + t.strictEqual( isnanf( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isnanf( imag( v ) ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-0` if provided `-0`', opts, function test( t ) { + var v; + + v = cfloornf( new Complex64( -0.0, -0.0 ), 0 ); + t.strictEqual( isNegativeZerof( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZerof( imag( v ) ), true, 'returns expected value' ); + + v = cfloornf( new Complex64( -0.0, -0.0 ), -2 ); + t.strictEqual( isNegativeZerof( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZerof( imag( v ) ), true, 'returns expected value' ); + + v = cfloornf( new Complex64( -0.0, -0.0 ), 2 ); + t.strictEqual( isNegativeZerof( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZerof( imag( v ) ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `+0` if provided `+0`', opts, function test( t ) { + var v; + + v = cfloornf( new Complex64( +0.0, +0.0 ), 0 ); + t.strictEqual( isPositiveZerof( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( imag( v ) ), true, 'returns expected value' ); + + v = cfloornf( new Complex64( +0.0, +0.0 ), -2 ); + t.strictEqual( isPositiveZerof( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( imag( v ) ), true, 'returns expected value' ); + + v = cfloornf( new Complex64( +0.0, +0.0 ), 2 ); + t.strictEqual( isPositiveZerof( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( imag( v ) ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports rounding real and imaginary components to a desired number of decimals', opts, function test( t ) { + var v; + + v = cfloornf( new Complex64( -3.141592653589793, 3.141592653589793 ), -2 ); + t.strictEqual( isAlmostSameValue( real( v ), f32( -3.15 ), 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( imag( v ), f32( 3.14 ), 1 ), true, 'returns expected value' ); + + v = cfloornf( new Complex64( 3.141592653589793, -3.141592653589793 ), -2 ); + t.strictEqual( isAlmostSameValue( real( v ), f32( 3.14 ), 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( imag( v ), f32( -3.15 ), 1 ), true, 'returns expected value' ); + + v = cfloornf( new Complex64( 9.99999, 9.99999 ), -2 ); + t.strictEqual( isAlmostSameValue( real( v ), f32( 9.99 ), 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( imag( v ), f32( 9.99 ), 1 ), true, 'returns expected value' ); + + v = cfloornf( new Complex64( 0.0, 0.0 ), 2 ); + t.strictEqual( real( v ), 0.0, 'returns expected value' ); + t.strictEqual( imag( v ), 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports rounding components to a desired number of digits', opts, function test( t ) { + var v; + + v = cfloornf( new Complex64( -1234.0, 1234.0 ), 2 ); + t.strictEqual( isAlmostSameValue( real( v ), -1300.0, 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( imag( v ), 1200.0, 1 ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the components unchanged if provided an `n` which is less than the minimum decimal exponential (-45)', opts, function test( t ) { + var exp; + var n; + var x; + var v; + var i; + for ( i = 0; i < 100; i++ ) { + exp = round( randu()*76.0 ) - 38; + x = f32( (1.0+randu()) * powf( 10.0, exp ) ); + n = -(round( randu()*100.0 ) + 46); + v = cfloornf( new Complex64( x, x ), n ); + t.strictEqual( real( v ), x, 'returns expected value' ); + t.strictEqual( imag( v ), x, 'returns expected value' ); + } + t.end(); +}); + +tape( 'if a component is too large a float to have decimals and `n < 0`, the component is returned unchanged', opts, function test( t ) { + var sign; + var exp; + var x; + var n; + var v; + var i; + for ( i = 0; i < 100; i++ ) { + sign = ( randu()<0.5 ) ? -1.0 : 1.0; + exp = 8 + round( randu()*30.0 ); + x = f32( sign * (1.0+randu()) * powf( 10.0, exp ) ); + n = -( round( randu()*38.0) ); + v = cfloornf( new Complex64( x, x ), n ); + t.strictEqual( real( v ), x, ' returns expected value' ); + t.strictEqual( imag( v ), x, ' returns expected value' ); + } + t.end(); +}); + +tape( 'if `n > 38` and a component is less than zero, the function returns `-infinity`', opts, function test( t ) { + var exp; + var x; + var n; + var v; + var i; + for ( i = 0; i < 100; i++ ) { + exp = round( randu()*37.0 ); + x = f32( -(1.0+randu()) * powf( 10.0, exp ) ); + n = round( randu()*10.0 ) + 39; + v = cfloornf( new Complex64( x, x ), n ); + t.strictEqual( real( v ), NINF, ' returns -infinity' ); + t.strictEqual( imag( v ), NINF, ' returns -infinity' ); + } + t.end(); +}); + +tape( 'if `n > 38` and a component is greater than or equal to zero, the function returns `+0` (sign preserving)', opts, function test( t ) { + var exp; + var x; + var n; + var v; + var i; + for ( i = 0; i < 100; i++ ) { + exp = round( randu()*37.0 ); + x = f32( (1.0+randu()) * powf( 10.0, exp ) ); + n = round( randu()*10.0 ) + 39; + v = cfloornf( new Complex64( x, x ), n ); + t.strictEqual( isPositiveZerof( real( v ) ), true, ' returns +0' ); + t.strictEqual( isPositiveZerof( imag( v ) ), true, ' returns +0' ); + } + t.end(); +}); + +tape( 'if the function encounters overflow, the function returns the input component', opts, function test( t ) { + var x; + var v; + + x = f32( 3.14 ); + v = cfloornf( new Complex64( x, x ), -46 ); + t.strictEqual( real( v ), x, 'returns expected value' ); + t.strictEqual( imag( v ), x, 'returns expected value' ); + + x = f32( -3.14 ); + v = cfloornf( new Complex64( x, x ), -46 ); + t.strictEqual( real( v ), x, 'returns expected value' ); + t.strictEqual( imag( v ), x, 'returns expected value' ); + + x = f32( 16777216.0 ); + v = cfloornf( new Complex64( x, x ), -40 ); + t.strictEqual( real( v ), x, 'returns expected value' ); + t.strictEqual( imag( v ), x, 'returns expected value' ); + + x = f32( -16777216.0 ); + v = cfloornf( new Complex64( x, x ), -40 ); + t.strictEqual( real( v ), x, 'returns expected value' ); + t.strictEqual( imag( v ), x, 'returns expected value' ); + + t.end(); +});