From 374812807f5d8e976d1eff0539e0e805abba4f86 Mon Sep 17 00:00:00 2001 From: nirmaljb Date: Thu, 7 May 2026 21:39:13 +0530 Subject: [PATCH 01/12] feat: add implementation of math/base/special/cfloornf --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../math/base/special/cfloornf/README.md | 257 ++++++++++++++++ .../special/cfloornf/benchmark/benchmark.js | 58 ++++ .../cfloornf/benchmark/benchmark.native.js | 68 +++++ .../special/cfloornf/benchmark/c/Makefile | 146 +++++++++ .../special/cfloornf/benchmark/c/benchmark.c | 144 +++++++++ .../cfloornf/benchmark/c/native/Makefile | 146 +++++++++ .../cfloornf/benchmark/c/native/benchmark.c | 144 +++++++++ .../math/base/special/cfloornf/binding.gyp | 170 +++++++++++ .../math/base/special/cfloornf/docs/repl.txt | 26 ++ .../special/cfloornf/docs/types/index.d.ts | 43 +++ .../base/special/cfloornf/docs/types/test.ts | 60 ++++ .../base/special/cfloornf/examples/c/Makefile | 146 +++++++++ .../special/cfloornf/examples/c/example.c | 46 +++ .../base/special/cfloornf/examples/index.js | 38 +++ .../math/base/special/cfloornf/include.gypi | 53 ++++ .../stdlib/math/base/special/cfloornf.h | 41 +++ .../math/base/special/cfloornf/lib/index.js | 53 ++++ .../math/base/special/cfloornf/lib/main.js | 63 ++++ .../math/base/special/cfloornf/lib/native.js | 63 ++++ .../math/base/special/cfloornf/manifest.json | 78 +++++ .../math/base/special/cfloornf/package.json | 74 +++++ .../math/base/special/cfloornf/src/Makefile | 70 +++++ .../math/base/special/cfloornf/src/addon.c | 22 ++ .../math/base/special/cfloornf/src/main.c | 56 ++++ .../math/base/special/cfloornf/test/test.js | 278 ++++++++++++++++++ .../base/special/cfloornf/test/test.native.js | 229 +++++++++++++++ 26 files changed, 2572 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/special/cfloornf/README.md create mode 100644 lib/node_modules/@stdlib/math/base/special/cfloornf/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/math/base/special/cfloornf/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/cfloornf/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/cfloornf/benchmark/c/benchmark.c create mode 100644 lib/node_modules/@stdlib/math/base/special/cfloornf/benchmark/c/native/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/cfloornf/benchmark/c/native/benchmark.c create mode 100644 lib/node_modules/@stdlib/math/base/special/cfloornf/binding.gyp create mode 100644 lib/node_modules/@stdlib/math/base/special/cfloornf/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/math/base/special/cfloornf/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/math/base/special/cfloornf/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/math/base/special/cfloornf/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/cfloornf/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/math/base/special/cfloornf/examples/index.js create mode 100644 lib/node_modules/@stdlib/math/base/special/cfloornf/include.gypi create mode 100644 lib/node_modules/@stdlib/math/base/special/cfloornf/include/stdlib/math/base/special/cfloornf.h create mode 100644 lib/node_modules/@stdlib/math/base/special/cfloornf/lib/index.js create mode 100644 lib/node_modules/@stdlib/math/base/special/cfloornf/lib/main.js create mode 100644 lib/node_modules/@stdlib/math/base/special/cfloornf/lib/native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/cfloornf/manifest.json create mode 100644 lib/node_modules/@stdlib/math/base/special/cfloornf/package.json create mode 100644 lib/node_modules/@stdlib/math/base/special/cfloornf/src/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/cfloornf/src/addon.c create mode 100644 lib/node_modules/@stdlib/math/base/special/cfloornf/src/main.c create mode 100644 lib/node_modules/@stdlib/math/base/special/cfloornf/test/test.js create mode 100644 lib/node_modules/@stdlib/math/base/special/cfloornf/test/test.native.js 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(); +}); From 73e61c5b384da6c6c3f518a292527e53fb65560e Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 10 May 2026 23:36:34 -0700 Subject: [PATCH 02/12] bench: use `random_uniform` --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../base/special/cfloornf/benchmark/c/benchmark.c | 14 ++++++++------ .../cfloornf/benchmark/c/native/benchmark.c | 14 ++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) 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 index bd38e92ccfee..88bf9b15bc7a 100644 --- 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 @@ -77,13 +77,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static float rand_float( void ) { - int r = rand(); - return (float)r / ( (float)RAND_MAX + 1.0f ); +static float random_uniform( const float min, const float max ) { + float v = (float)rand() / ( (float)RAND_MAX + 1.0f ); + return min + ( v*(max-min) ); } /** @@ -103,7 +105,7 @@ static double benchmark( void ) { stdlib_complex64_t y; for ( i = 0; i < 100; i++ ) { - v[ i ] = ( 1000.0f * rand_float() ) - 500.0f; + v[ i ] = random_uniform( -500.0f, 500.0f ); } t = tic(); 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 index 41088b01eda4..0d815d4b2632 100644 --- 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 @@ -77,13 +77,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static float rand_float( void ) { - int r = rand(); - return (float)r / ( (float)RAND_MAX + 1.0f ); +static float random_uniform( const float min, const float max ) { + float v = (float)rand() / ( (float)RAND_MAX + 1.0f ); + return min + ( v*(max-min) ); } /** @@ -103,7 +105,7 @@ static double benchmark( void ) { stdlib_complex64_t y; for ( i = 0; i < 100; i++ ) { - v[ i ] = ( 1000.0f * rand_float() ) - 500.0f; + v[ i ] = random_uniform( -500.0f, 500.0f ); } t = tic(); From f4756db2740ff8ab2491db5d4049fc62497c6b7d Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 10 May 2026 23:37:35 -0700 Subject: [PATCH 03/12] docs: clean-up --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/math/base/special/cfloornf/README.md | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/cfloornf/README.md b/lib/node_modules/@stdlib/math/base/special/cfloornf/README.md index ad2bf6a800a9..d60261f5dd0f 100644 --- a/lib/node_modules/@stdlib/math/base/special/cfloornf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/README.md @@ -224,14 +224,6 @@ int main( void ) { @@ -244,12 +236,6 @@ int main( void ) { -[@stdlib/math/base/special/cfloorn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/cfloorn - -[@stdlib/math/base/special/cfloorf]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/cfloorf - -[@stdlib/math/base/special/floornf]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/floornf - From 239a3c8d8260761ab559f75367186b80ebffdf52 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 10 May 2026 23:43:00 -0700 Subject: [PATCH 04/12] test: follow latest project conventions --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../math/base/special/cfloornf/test/test.js | 16 ++++++------ .../base/special/cfloornf/test/test.native.js | 25 ++++++++++++++----- 2 files changed, 27 insertions(+), 14 deletions(-) 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 index 21d1dd1b1d0c..a5646072e7a2 100644 --- a/lib/node_modules/@stdlib/math/base/special/cfloornf/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/test/test.js @@ -197,8 +197,8 @@ tape( 'if a component is too large a float to have decimals and `n < 0`, the com 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.strictEqual( real( v ), x, 'returns expected value' ); + t.strictEqual( imag( v ), x, 'returns expected value' ); } t.end(); }); @@ -214,8 +214,8 @@ tape( 'if `n > 38` and a component is less than zero, the function returns `-inf 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.strictEqual( real( v ), NINF, 'returns expected value' ); + t.strictEqual( imag( v ), NINF, 'returns expected value' ); } t.end(); }); @@ -231,8 +231,8 @@ tape( 'if `n > 38` and a component is greater than or equal to zero, the functio 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.strictEqual( isPositiveZerof( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( imag( v ) ), true, 'returns expected value' ); } t.end(); }); @@ -272,7 +272,7 @@ tape( 'rounding components to a desired number of decimals can result in unexpec 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.strictEqual( isnanf( real( v ) ), false, 'returns expected value' ); + t.strictEqual( isnanf( imag( v ) ), false, 'returns expected value' ); 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 index 580bde4cf837..d9446c4d0c23 100644 --- 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 @@ -161,8 +161,8 @@ tape( 'if a component is too large a float to have decimals and `n < 0`, the com 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.strictEqual( real( v ), x, 'returns expected value' ); + t.strictEqual( imag( v ), x, 'returns expected value' ); } t.end(); }); @@ -178,8 +178,8 @@ tape( 'if `n > 38` and a component is less than zero, the function returns `-inf 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.strictEqual( real( v ), NINF, 'returns expected value' ); + t.strictEqual( imag( v ), NINF, 'returns expected value' ); } t.end(); }); @@ -195,8 +195,8 @@ tape( 'if `n > 38` and a component is greater than or equal to zero, the functio 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.strictEqual( isPositiveZerof( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( imag( v ) ), true, 'returns expected value' ); } t.end(); }); @@ -227,3 +227,16 @@ tape( 'if the function encounters overflow, the function returns the input compo t.end(); }); + +tape( 'rounding components to a desired number of decimals can result in unexpected behavior due to floating-point representation', opts, 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 expected value' ); + t.strictEqual( isnanf( imag( v ) ), false, 'returns expected value' ); + t.end(); +}); From 6d945bab5a65a544ecfc0e509fa426d33fde1433 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Tue, 4 Aug 2026 22:48:34 -0700 Subject: [PATCH 05/12] chore: code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../math/base/special/cfloornf/README.md | 2 +- .../special/cfloornf/benchmark/benchmark.js | 2 +- .../special/cfloornf/benchmark/c/benchmark.c | 23 ++--- .../cfloornf/benchmark/c/native/benchmark.c | 3 +- .../math/base/special/cfloornf/src/main.c | 2 +- .../math/base/special/cfloornf/test/test.js | 80 ++++++++++++---- .../base/special/cfloornf/test/test.native.js | 95 ++++++++++++++++--- 7 files changed, 154 insertions(+), 53 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/cfloornf/README.md b/lib/node_modules/@stdlib/math/base/special/cfloornf/README.md index d60261f5dd0f..50cac55109d9 100644 --- a/lib/node_modules/@stdlib/math/base/special/cfloornf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/README.md @@ -144,7 +144,7 @@ Rounds each component of a single-precision complex floating-point number to the #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 z = stdlib_complex64( -3.141592653589793f, 3.141592653589793f ); stdlib_complex64_t out = stdlib_base_cfloornf( z, -2 ); float re = stdlib_complex64_real( out ); 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 index 1d01f3b2b5ab..cf9593c82ce6 100644 --- a/lib/node_modules/@stdlib/math/base/special/cfloornf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/benchmark/benchmark.js @@ -21,11 +21,11 @@ // MODULES // 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 uniform = require( '@stdlib/random/base/uniform' ); var pkg = require( './../package.json' ).name; var cfloornf = require( './../lib' ); 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 index 88bf9b15bc7a..46c95fa5da99 100644 --- 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 @@ -16,12 +16,10 @@ * limitations under the License. */ -#include "stdlib/math/base/special/cfloornf.h" -#include "stdlib/complex/float32/ctor.h" -#include "stdlib/complex/float32/reim.h" +#include "stdlib/math/base/special/floornf.h" +#include #include #include -#include #include #include @@ -94,15 +92,13 @@ static float random_uniform( const float min, const float max ) { * @return elapsed time in seconds */ static double benchmark( void ) { - float v[ 100 ]; double elapsed; - float re; - float im; + float v[ 100 ]; double t; int i; - stdlib_complex64_t x; - stdlib_complex64_t y; + float complex x; + float complex y; for ( i = 0; i < 100; i++ ) { v[ i ] = random_uniform( -500.0f, 500.0f ); @@ -110,16 +106,15 @@ static double benchmark( void ) { 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 ) { + x = v[ i%100 ] + v[ i%100 ]*I; + y = stdlib_base_floornf( crealf( x ), -2 ) + stdlib_base_floornf( cimagf( x ), -2 )*I; + if ( crealf( y ) != crealf( y ) ) { printf( "unexpected result\n" ); break; } } elapsed = tic() - t; - if ( im != im ) { + if ( cimagf( y ) != cimagf( y ) ) { printf( "unexpected result\n" ); } return elapsed; 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 index 0d815d4b2632..23d31a670533 100644 --- 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 @@ -21,7 +21,6 @@ #include "stdlib/complex/float32/reim.h" #include #include -#include #include #include @@ -94,8 +93,8 @@ static float random_uniform( const float min, const float max ) { * @return elapsed time in seconds */ static double benchmark( void ) { - float v[ 100 ]; double elapsed; + float v[ 100 ]; float re; float im; double t; 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 index f2b7679ce4ea..366876625341 100644 --- a/lib/node_modules/@stdlib/math/base/special/cfloornf/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/src/main.c @@ -34,7 +34,7 @@ * #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 z = stdlib_complex64( -3.141592653589793f, 3.141592653589793f ); * * stdlib_complex64_t out = stdlib_base_cfloornf( z, -2 ); * 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 index a5646072e7a2..308657e8a50b 100644 --- a/lib/node_modules/@stdlib/math/base/special/cfloornf/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/test/test.js @@ -26,7 +26,7 @@ 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 isAlmostSameValuef = require( '@stdlib/number/float32/base/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' ); @@ -52,10 +52,22 @@ tape( 'the function returns a `NaN` if provided a `NaN`', function test( t ) { t.strictEqual( isnanf( real( v ) ), true, 'returns expected value' ); t.strictEqual( isnanf( imag( v ) ), true, 'returns expected value' ); + v = cfloornf( new Complex64( NaN, 3.14 ), 0 ); + t.strictEqual( isnanf( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isnanf( imag( v ) ), false, 'returns expected value' ); + + v = cfloornf( new Complex64( 3.14, NaN ), 0 ); + t.strictEqual( isnanf( real( v ) ), false, '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' ); + v = cfloornf( new Complex64( 3.14, 3.14 ), NaN ); + t.strictEqual( isnanf( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isnanf( imag( v ) ), true, 'returns expected value' ); + t.end(); }); @@ -131,20 +143,20 @@ tape( 'the function supports rounding real and imaginary components to a desired 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' ); + t.strictEqual( real( v ), f32( -3.15 ), 'returns expected value' ); + t.strictEqual( imag( v ), f32( 3.14 ), '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' ); + t.strictEqual( real( v ), f32( 3.14 ), 'returns expected value' ); + t.strictEqual( imag( v ), f32( -3.15 ), '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' ); + t.strictEqual( real( v ), f32( 9.99 ), 'returns expected value' ); + t.strictEqual( imag( v ), f32( 9.99 ), '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' ); + t.strictEqual( real( v ), f32( -10.0 ), 'returns expected value' ); + t.strictEqual( imag( v ), f32( -10.0 ), 'returns expected value' ); v = cfloornf( new Complex64( 0.0, 0.0 ), 2 ); t.strictEqual( real( v ), 0.0, 'returns expected value' ); @@ -157,12 +169,12 @@ tape( 'the function supports rounding components to a desired number of digits', 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.strictEqual( real( v ), -1300.0, 'returns expected value' ); + t.strictEqual( imag( v ), 1200.0, '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.strictEqual( real( v ), 12360.0, 'returns expected value' ); + t.strictEqual( imag( v ), -12380.0, 'returns expected value' ); t.end(); }); @@ -264,15 +276,45 @@ tape( 'if the function encounters overflow, the function returns the input compo t.end(); }); -tape( 'rounding components to a desired number of decimals can result in unexpected behavior due to floating-point representation', function test( t ) { +tape( 'rounding components to a desired number of decimals can result in unexpected behavior', function test( t ) { var x; var v; - x = f32( -0.2 - 0.1 ); - v = cfloornf( new Complex64( x, x ), -6 ); + x = f32( f32( -0.2 ) - f32( 0.1 ) ); // returns -0.30000001192092896 + v = cfloornf( new Complex64( x, x ), -8 ); + t.strictEqual( real( v ), f32( -0.30000000 ), 'returns expected value' ); + t.strictEqual( imag( v ), f32( -0.30000000 ), 'returns expected value' ); + t.end(); +}); - // The result may differ slightly from -0.3 due to float32 precision: - t.strictEqual( isnanf( real( v ) ), false, 'returns expected value' ); - t.strictEqual( isnanf( imag( v ) ), false, 'returns expected value' ); +tape( 'the function supports rounding very small numbers (including subnormals)', function test( t ) { + var expected; + var x; + var n; + var v; + var i; + + x = f32( f32( 3.1468234343023397 ) * powf( f32( 10.0 ), -38 ) ); + + n = []; + for ( i = -38; i > -46; i-- ) { + n.push( i ); + } + expected = [ + f32( 3.0e-38 ), + f32( 3.1e-38 ), + f32( 3.14e-38 ), + f32( 3.146e-38 ), + f32( 3.1468e-38 ), + f32( 3.14682e-38 ), + f32( 3.146823e-38 ), + f32( 3.1468234e-38 ) + ]; + + for ( i = 0; i < n.length; i++ ) { + v = cfloornf( new Complex64( x, x ), n[ i ] ); + t.strictEqual( isAlmostSameValuef( real( v ), expected[ i ], 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( imag( v ), expected[ i ], 1 ), true, 'returns expected value' ); + } 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 index d9446c4d0c23..3750c99f927a 100644 --- 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 @@ -22,11 +22,12 @@ var resolve = require( 'path' ).resolve; 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 isAlmostSameValuef = require( '@stdlib/number/float32/base/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' ); @@ -60,6 +61,32 @@ tape( 'the function returns a `NaN` if provided a `NaN`', opts, function test( t t.strictEqual( isnanf( real( v ) ), true, 'returns expected value' ); t.strictEqual( isnanf( imag( v ) ), true, 'returns expected value' ); + v = cfloornf( new Complex64( NaN, 3.14 ), 0 ); + t.strictEqual( isnanf( real( v ) ), true, 'returns expected value' ); + t.strictEqual( isnanf( imag( v ) ), false, 'returns expected value' ); + + v = cfloornf( new Complex64( 3.14, NaN ), 0 ); + t.strictEqual( isnanf( real( v ) ), false, 'returns expected value' ); + t.strictEqual( isnanf( imag( v ) ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `+infinity` if provided `+infinity`', opts, 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`', opts, 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(); }); @@ -103,16 +130,20 @@ tape( 'the function supports rounding real and imaginary components to a desired 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' ); + t.strictEqual( real( v ), f32( -3.15 ), 'returns expected value' ); + t.strictEqual( imag( v ), f32( 3.14 ), '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' ); + t.strictEqual( real( v ), f32( 3.14 ), 'returns expected value' ); + t.strictEqual( imag( v ), f32( -3.15 ), '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' ); + t.strictEqual( real( v ), f32( 9.99 ), 'returns expected value' ); + t.strictEqual( imag( v ), f32( 9.99 ), 'returns expected value' ); + + v = cfloornf( new Complex64( -9.99999, -9.99999 ), -2 ); + t.strictEqual( real( v ), f32( -10.0 ), 'returns expected value' ); + t.strictEqual( imag( v ), f32( -10.0 ), 'returns expected value' ); v = cfloornf( new Complex64( 0.0, 0.0 ), 2 ); t.strictEqual( real( v ), 0.0, 'returns expected value' ); @@ -125,8 +156,12 @@ tape( 'the function supports rounding components to a desired number of digits', 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.strictEqual( real( v ), -1300.0, 'returns expected value' ); + t.strictEqual( imag( v ), 1200.0, 'returns expected value' ); + + v = cfloornf( new Complex64( 12363.0, -12373.0 ), 1 ); + t.strictEqual( real( v ), 12360.0, 'returns expected value' ); + t.strictEqual( imag( v ), -12380.0, 'returns expected value' ); t.end(); }); @@ -228,15 +263,45 @@ tape( 'if the function encounters overflow, the function returns the input compo t.end(); }); -tape( 'rounding components to a desired number of decimals can result in unexpected behavior due to floating-point representation', opts, function test( t ) { +tape( 'rounding components to a desired number of decimals can result in unexpected behavior', opts, function test( t ) { var x; var v; - x = f32( -0.2 - 0.1 ); - v = cfloornf( new Complex64( x, x ), -6 ); + x = f32( f32( -0.2 ) - f32( 0.1 ) ); // returns -0.30000001192092896 + v = cfloornf( new Complex64( x, x ), -8 ); + t.strictEqual( real( v ), f32( -0.30000000 ), 'returns expected value' ); + t.strictEqual( imag( v ), f32( -0.30000000 ), 'returns expected value' ); + t.end(); +}); - // The result may differ slightly from -0.3 due to float32 precision: - t.strictEqual( isnanf( real( v ) ), false, 'returns expected value' ); - t.strictEqual( isnanf( imag( v ) ), false, 'returns expected value' ); +tape( 'the function supports rounding very small numbers (including subnormals)', opts, function test( t ) { + var expected; + var x; + var n; + var v; + var i; + + x = f32( f32( 3.1468234343023397 ) * powf( f32( 10.0 ), -38 ) ); + + n = []; + for ( i = -38; i > -46; i-- ) { + n.push( i ); + } + expected = [ + f32( 3.0e-38 ), + f32( 3.1e-38 ), + f32( 3.14e-38 ), + f32( 3.146e-38 ), + f32( 3.1468e-38 ), + f32( 3.14682e-38 ), + f32( 3.146823e-38 ), + f32( 3.1468234e-38 ) + ]; + + for ( i = 0; i < n.length; i++ ) { + v = cfloornf( new Complex64( x, x ), n[ i ] ); + t.strictEqual( isAlmostSameValuef( real( v ), expected[ i ], 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( imag( v ), expected[ i ], 1 ), true, 'returns expected value' ); + } t.end(); }); From 4d84e778c293391236e7cee0f3ac8e968a047a86 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Tue, 4 Aug 2026 22:53:02 -0700 Subject: [PATCH 06/12] chore: code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../special/cfloornf/benchmark/c/benchmark.c | 26 ++++++++++--------- .../cfloornf/benchmark/c/native/benchmark.c | 22 ++++++++-------- 2 files changed, 25 insertions(+), 23 deletions(-) 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 index 46c95fa5da99..37cbdebf317e 100644 --- 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 @@ -17,9 +17,10 @@ */ #include "stdlib/math/base/special/floornf.h" -#include #include #include +#include +#include #include #include @@ -92,30 +93,31 @@ static float random_uniform( const float min, const float max ) { * @return elapsed time in seconds */ static double benchmark( void ) { + float complex z1[ 100 ]; + float complex z2; double elapsed; - float v[ 100 ]; double t; + float re; + float im; int i; - float complex x; - float complex y; - for ( i = 0; i < 100; i++ ) { - v[ i ] = random_uniform( -500.0f, 500.0f ); + re = random_uniform( -500.0f, 500.0f ); + im = random_uniform( -500.0f, 500.0f ); + z1[ i ] = re + im*I; } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = v[ i%100 ] + v[ i%100 ]*I; - y = stdlib_base_floornf( crealf( x ), -2 ) + stdlib_base_floornf( cimagf( x ), -2 )*I; - if ( crealf( y ) != crealf( y ) ) { - printf( "unexpected result\n" ); + z2 = stdlib_base_floornf( crealf( z1[ i%100 ] ), -2 ) + stdlib_base_floornf( cimagf( z1[ i%100 ] ), -2 )*I; + if ( crealf( z2 ) != crealf( z2 ) ) { + printf( "should not return NaN\n" ); break; } } elapsed = tic() - t; - if ( cimagf( y ) != cimagf( y ) ) { - printf( "unexpected result\n" ); + if ( cimagf( z2 ) != cimagf( z2 ) ) { + printf( "should not return NaN\n" ); } return elapsed; } 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 index 23d31a670533..60eab14770d2 100644 --- 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 @@ -21,6 +21,7 @@ #include "stdlib/complex/float32/reim.h" #include #include +#include #include #include @@ -93,33 +94,32 @@ static float random_uniform( const float min, const float max ) { * @return elapsed time in seconds */ static double benchmark( void ) { + stdlib_complex64_t z1[ 100 ]; + stdlib_complex64_t z2; double elapsed; - float v[ 100 ]; + double t; float re; float im; - double t; int i; - stdlib_complex64_t x; - stdlib_complex64_t y; - for ( i = 0; i < 100; i++ ) { - v[ i ] = random_uniform( -500.0f, 500.0f ); + re = random_uniform( -500.0f, 500.0f ); + im = random_uniform( -500.0f, 500.0f ); + z1[ i ] = stdlib_complex64( re, im ); } 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 ); + z2 = stdlib_base_cfloornf( z1[ i%100 ], -2 ); + stdlib_complex64_reim( z2, &re, &im ); if ( re != re ) { - printf( "unexpected result\n" ); + printf( "should not return NaN\n" ); break; } } elapsed = tic() - t; if ( im != im ) { - printf( "unexpected result\n" ); + printf( "should not return NaN\n" ); } return elapsed; } From 956b57fbc6155eaec6ee1c0f2dcc8f230231dd58 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Tue, 4 Aug 2026 22:53:41 -0700 Subject: [PATCH 07/12] chore: code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../math/base/special/cfloornf/benchmark/benchmark.js | 8 ++++---- .../base/special/cfloornf/benchmark/benchmark.native.js | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) 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 index cf9593c82ce6..bf56277b8ee2 100644 --- a/lib/node_modules/@stdlib/math/base/special/cfloornf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/benchmark/benchmark.js @@ -24,8 +24,8 @@ 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 realf = require( '@stdlib/complex/float32/real' ); +var imagf = require( '@stdlib/complex/float32/imag' ); var pkg = require( './../package.json' ).name; var cfloornf = require( './../lib' ); @@ -45,12 +45,12 @@ bench( pkg, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { y = cfloornf( values[ i%values.length ], -2 ); - if ( isnanf( real( y ) ) ) { + if ( isnanf( realf( y ) ) ) { b.fail( 'should not return NaN' ); } } b.toc(); - if ( isnanf( imag( y ) ) ) { + if ( isnanf( imagf( y ) ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); 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 index 54ab10b27472..ee351c9da851 100644 --- 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 @@ -25,8 +25,8 @@ 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 realf = require( '@stdlib/complex/float32/real' ); +var imagf = require( '@stdlib/complex/float32/imag' ); var tryRequire = require( '@stdlib/utils/try-require' ); var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; @@ -55,12 +55,12 @@ bench( format( '%s::native', pkg ), opts, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { y = cfloornf( values[ i%values.length ], -2 ); - if ( isnanf( real( y ) ) ) { + if ( isnanf( realf( y ) ) ) { b.fail( 'should not return NaN' ); } } b.toc(); - if ( isnanf( imag( y ) ) ) { + if ( isnanf( imagf( y ) ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); From 3aac2a96150212462e4b44168cbe852836e1ac52 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Tue, 4 Aug 2026 23:01:03 -0700 Subject: [PATCH 08/12] chore: code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../math/base/special/cfloornf/docs/repl.txt | 5 ++- .../base/special/cfloornf/docs/types/test.ts | 34 +++++++++++-------- 2 files changed, 24 insertions(+), 15 deletions(-) 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 index 9330583639ee..9aa18997d9e7 100644 --- a/lib/node_modules/@stdlib/math/base/special/cfloornf/docs/repl.txt +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/docs/repl.txt @@ -3,6 +3,9 @@ Rounds each component of a single-precision complex floating-point number to the nearest multiple of `10^n` toward negative infinity. + When operating on floating-point numbers in bases other than `2`, rounding + to specified digits can be inexact. + Parameters ---------- z: Complex64 @@ -13,7 +16,7 @@ Returns ------- - z: Complex64 + out: Complex64 Result. Examples 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 index bc3a790b32ef..648155af8c0a 100644 --- 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 @@ -24,10 +24,12 @@ import cfloornf = require( './index' ); // The function returns a single-precision complex floating-point number... { - cfloornf( new Complex64( 1.0, 2.0 ), -2 ); // $ExpectType Complex64 + const z = new Complex64( 1.0, 2.0 ); + + cfloornf( z, -2 ); // $ExpectType Complex64 } -// The compiler throws an error if the first argument of the function is provided a value other than a complex number... +// The compiler throws an error if the function is provided a first argument which is not a complex number... { cfloornf( 3, -2 ); // $ExpectError cfloornf( true, -2 ); // $ExpectError @@ -40,21 +42,25 @@ import cfloornf = require( './index' ); 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... +// The compiler throws an error if the function is provided a second argument which is not 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 + const z = new Complex64( 1.0, 2.0 ); + + cfloornf( z, true ); // $ExpectError + cfloornf( z, false ); // $ExpectError + cfloornf( z, null ); // $ExpectError + cfloornf( z, undefined ); // $ExpectError + cfloornf( z, '5' ); // $ExpectError + cfloornf( z, [] ); // $ExpectError + cfloornf( z, {} ); // $ExpectError + cfloornf( z, ( x: number ): number => x ); // $ExpectError } -// The compiler throws an error if the function is provided insufficient arguments... +// The compiler throws an error if the function is provided an unsupported number of arguments... { + const z = new Complex64( 1.0, 2.0 ); + cfloornf(); // $ExpectError - cfloornf( 2 ); // $ExpectError + cfloornf( z ); // $ExpectError + cfloornf( z, -2, {} ); // $ExpectError } From 7939badbeff76e6bde897181f8b7109eb1d5eeee Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Tue, 4 Aug 2026 23:06:23 -0700 Subject: [PATCH 09/12] chore: code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../math/base/special/cfloornf/README.md | 28 +++++++++---------- .../base/special/cfloornf/examples/index.js | 28 +++++++++---------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/cfloornf/README.md b/lib/node_modules/@stdlib/math/base/special/cfloornf/README.md index 50cac55109d9..46dd54ca913d 100644 --- a/lib/node_modules/@stdlib/math/base/special/cfloornf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/README.md @@ -85,24 +85,24 @@ v = cfloornf( new Complex64( NaN, NaN ), 0 ); ```javascript -var Complex64 = require( '@stdlib/complex/float32/ctor' ); -var uniform = require( '@stdlib/random/base/uniform' ); -var randint = require( '@stdlib/random/base/discrete-uniform' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); 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 ) ); +// Generate an array of random complex numbers: +var z = new Complex64Array( uniform( 200, -50.0, 50.0, { + 'dtype': 'float32' +})); - n = randint( -5.0, 0.0 ); - w = cfloornf( z, n ); +// Generate an array of random integer powers of 10: +var n = discreteUniform( 100, -5, 0, { + 'dtype': 'int32' +}); - console.log( 'cfloornf(%s,%s) = %s', z.toString(), n.toString(), w.toString() ); -} +// Round each component of each complex number to the nearest multiple of `10^n` toward negative infinity: +logEachMap( 'cfloornf(%s, %d) = %s', z, n, cfloornf ); ``` 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 index fc447878d9c6..9de108be88d8 100644 --- a/lib/node_modules/@stdlib/math/base/special/cfloornf/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/examples/index.js @@ -18,21 +18,21 @@ '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 Complex64Array = require( '@stdlib/array/complex64' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var cfloornf = require( './../lib' ); -var z; -var w; -var n; -var i; +// Generate an array of random complex numbers: +var z = new Complex64Array( uniform( 200, -50.0, 50.0, { + 'dtype': 'float32' +})); -for ( i = 0; i < 100; i++ ) { - z = new Complex64( uniform( -50.0, 50.0 ), uniform( -50.0, 50.0 ) ); +// Generate an array of random integer powers of 10: +var n = discreteUniform( 100, -5, 0, { + 'dtype': 'int32' +}); - n = randint( -5.0, 0.0 ); - w = cfloornf( z, n ); - - console.log( 'cfloornf(%s,%s) = %s', z.toString(), n.toString(), w.toString() ); -} +// Round each component of each complex number to the nearest multiple of `10^n` toward negative infinity: +logEachMap( 'cfloornf(%s, %d) = %s', z, n, cfloornf ); From 968301a4c5425b178c74f5a03aab2172b6a2d519 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Tue, 4 Aug 2026 23:10:37 -0700 Subject: [PATCH 10/12] chore: code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/math/base/special/cfloornf/lib/main.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 index 5dbcb2981989..ae961a827951 100644 --- a/lib/node_modules/@stdlib/math/base/special/cfloornf/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/lib/main.js @@ -22,8 +22,8 @@ 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' ); +var realf = require( '@stdlib/complex/float32/real' ); +var imagf = require( '@stdlib/complex/float32/imag' ); // MAIN // @@ -54,7 +54,7 @@ var imag = require( '@stdlib/complex/float32/imag' ); * // returns [ NaN, NaN ] */ function cfloornf( z, n ) { - return new Complex64( floornf( real( z ), n ), floornf( imag( z ), n ) ); + return new Complex64( floornf( realf( z ), n ), floornf( imagf( z ), n ) ); } From 4b4fc000819f3e618b6388a415dc686a52524195 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Tue, 4 Aug 2026 23:25:31 -0700 Subject: [PATCH 11/12] chore: code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../math/base/special/cfloornf/test/test.js | 206 ++++++++--------- .../base/special/cfloornf/test/test.native.js | 218 +++++++++--------- 2 files changed, 212 insertions(+), 212 deletions(-) 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 index 308657e8a50b..467d0a8b0636 100644 --- a/lib/node_modules/@stdlib/math/base/special/cfloornf/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/test/test.js @@ -24,7 +24,7 @@ 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 roundf = require( '@stdlib/math/base/special/roundf' ); var powf = require( '@stdlib/math/base/special/powf' ); var isAlmostSameValuef = require( '@stdlib/number/float32/base/assert/is-almost-same-value' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); @@ -32,8 +32,8 @@ 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 realf = require( '@stdlib/complex/float32/real' ); +var imagf = require( '@stdlib/complex/float32/imag' ); var cfloornf = require( './../lib' ); @@ -49,24 +49,24 @@ 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' ); + t.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isnanf( imagf( v ) ), true, 'returns expected value' ); v = cfloornf( new Complex64( NaN, 3.14 ), 0 ); - t.strictEqual( isnanf( real( v ) ), true, 'returns expected value' ); - t.strictEqual( isnanf( imag( v ) ), false, 'returns expected value' ); + t.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isnanf( imagf( v ) ), false, 'returns expected value' ); v = cfloornf( new Complex64( 3.14, NaN ), 0 ); - t.strictEqual( isnanf( real( v ) ), false, 'returns expected value' ); - t.strictEqual( isnanf( imag( v ) ), true, 'returns expected value' ); + t.strictEqual( isnanf( realf( v ) ), false, 'returns expected value' ); + t.strictEqual( isnanf( imagf( 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.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isnanf( imagf( v ) ), true, 'returns expected value' ); v = cfloornf( new Complex64( 3.14, 3.14 ), NaN ); - t.strictEqual( isnanf( real( v ) ), true, 'returns expected value' ); - t.strictEqual( isnanf( imag( v ) ), true, 'returns expected value' ); + t.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isnanf( imagf( v ) ), true, 'returns expected value' ); t.end(); }); @@ -75,12 +75,12 @@ tape( 'the function returns `NaNs` if provided `n = +-infinity`', function test( 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' ); + t.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isnanf( imagf( 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.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isnanf( imagf( v ) ), true, 'returns expected value' ); t.end(); }); @@ -89,16 +89,16 @@ 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' ); + t.strictEqual( isNegativeZerof( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZerof( imagf( 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.strictEqual( isNegativeZerof( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZerof( imagf( 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.strictEqual( isNegativeZerof( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZerof( imagf( v ) ), true, 'returns expected value' ); t.end(); }); @@ -107,16 +107,16 @@ 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' ); + t.strictEqual( isPositiveZerof( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( imagf( 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.strictEqual( isPositiveZerof( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( imagf( 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.strictEqual( isPositiveZerof( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( imagf( v ) ), true, 'returns expected value' ); t.end(); }); @@ -125,8 +125,8 @@ tape( 'the function returns `+infinity` if provided `+infinity`', function test( 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.strictEqual( realf( v ), PINF, 'returns expected value' ); + t.strictEqual( imagf( v ), PINF, 'returns expected value' ); t.end(); }); @@ -134,8 +134,8 @@ tape( 'the function returns `-infinity` if provided `-infinity`', function test( 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.strictEqual( realf( v ), NINF, 'returns expected value' ); + t.strictEqual( imagf( v ), NINF, 'returns expected value' ); t.end(); }); @@ -143,38 +143,49 @@ tape( 'the function supports rounding real and imaginary components to a desired var v; v = cfloornf( new Complex64( -3.141592653589793, 3.141592653589793 ), -2 ); - t.strictEqual( real( v ), f32( -3.15 ), 'returns expected value' ); - t.strictEqual( imag( v ), f32( 3.14 ), 'returns expected value' ); + t.strictEqual( realf( v ), f32( -3.15 ), 'returns expected value' ); + t.strictEqual( imagf( v ), f32( 3.14 ), 'returns expected value' ); v = cfloornf( new Complex64( 3.141592653589793, -3.141592653589793 ), -2 ); - t.strictEqual( real( v ), f32( 3.14 ), 'returns expected value' ); - t.strictEqual( imag( v ), f32( -3.15 ), 'returns expected value' ); + t.strictEqual( realf( v ), f32( 3.14 ), 'returns expected value' ); + t.strictEqual( imagf( v ), f32( -3.15 ), 'returns expected value' ); v = cfloornf( new Complex64( 9.99999, 9.99999 ), -2 ); - t.strictEqual( real( v ), f32( 9.99 ), 'returns expected value' ); - t.strictEqual( imag( v ), f32( 9.99 ), 'returns expected value' ); + t.strictEqual( realf( v ), f32( 9.99 ), 'returns expected value' ); + t.strictEqual( imagf( v ), f32( 9.99 ), 'returns expected value' ); v = cfloornf( new Complex64( -9.99999, -9.99999 ), -2 ); - t.strictEqual( real( v ), f32( -10.0 ), 'returns expected value' ); - t.strictEqual( imag( v ), f32( -10.0 ), 'returns expected value' ); + t.strictEqual( realf( v ), f32( -10.0 ), 'returns expected value' ); + t.strictEqual( imagf( v ), f32( -10.0 ), '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.strictEqual( realf( v ), 0.0, 'returns expected value' ); + t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); t.end(); }); +tape( 'rounding components to a desired number of decimals can result in unexpected behavior', function test( t ) { + var x; + var v; + + x = f32( f32( -0.2 ) - f32( 0.1 ) ); // returns -0.30000001192092896 + v = cfloornf( new Complex64( x, x ), -8 ); + t.strictEqual( realf( v ), f32( -0.30000000 ), 'returns expected value' ); + t.strictEqual( imagf( v ), f32( -0.30000000 ), '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( real( v ), -1300.0, 'returns expected value' ); - t.strictEqual( imag( v ), 1200.0, 'returns expected value' ); + t.strictEqual( realf( v ), -1300.0, 'returns expected value' ); + t.strictEqual( imagf( v ), 1200.0, 'returns expected value' ); v = cfloornf( new Complex64( 12363.0, -12373.0 ), 1 ); - t.strictEqual( real( v ), 12360.0, 'returns expected value' ); - t.strictEqual( imag( v ), -12380.0, 'returns expected value' ); + t.strictEqual( realf( v ), 12360.0, 'returns expected value' ); + t.strictEqual( imagf( v ), -12380.0, 'returns expected value' ); t.end(); }); @@ -186,12 +197,12 @@ tape( 'the function returns the components unchanged if provided an `n` which is var v; var i; for ( i = 0; i < 100; i++ ) { - exp = round( randu()*76.0 ) - 38; + exp = roundf( randu()*76.0 ) - 38; x = f32( (1.0+randu()) * powf( 10.0, exp ) ); - n = -(round( randu()*100.0 ) + 46); + n = -(roundf( 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.strictEqual( realf( v ), x, 'returns expected value' ); + t.strictEqual( imagf( v ), x, 'returns expected value' ); } t.end(); }); @@ -205,12 +216,12 @@ tape( 'if a component is too large a float to have decimals and `n < 0`, the com var i; for ( i = 0; i < 100; i++ ) { sign = ( randu()<0.5 ) ? -1.0 : 1.0; - exp = 8 + round( randu()*30.0 ); + exp = 8 + roundf( randu()*30.0 ); x = f32( sign * (1.0+randu()) * powf( 10.0, exp ) ); - n = -( round( randu()*38.0) ); + n = -( roundf( 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.strictEqual( realf( v ), x, 'returns expected value' ); + t.strictEqual( imagf( v ), x, 'returns expected value' ); } t.end(); }); @@ -222,12 +233,12 @@ tape( 'if `n > 38` and a component is less than zero, the function returns `-inf var v; var i; for ( i = 0; i < 100; i++ ) { - exp = round( randu()*37.0 ); + exp = roundf( randu()*37.0 ); x = f32( -(1.0+randu()) * powf( 10.0, exp ) ); - n = round( randu()*10.0 ) + 39; + n = roundf( randu()*10.0 ) + 39; v = cfloornf( new Complex64( x, x ), n ); - t.strictEqual( real( v ), NINF, 'returns expected value' ); - t.strictEqual( imag( v ), NINF, 'returns expected value' ); + t.strictEqual( realf( v ), NINF, 'returns expected value' ); + t.strictEqual( imagf( v ), NINF, 'returns expected value' ); } t.end(); }); @@ -239,54 +250,16 @@ tape( 'if `n > 38` and a component is greater than or equal to zero, the functio var v; var i; for ( i = 0; i < 100; i++ ) { - exp = round( randu()*37.0 ); + exp = roundf( randu()*37.0 ); x = f32( (1.0+randu()) * powf( 10.0, exp ) ); - n = round( randu()*10.0 ) + 39; + n = roundf( randu()*10.0 ) + 39; v = cfloornf( new Complex64( x, x ), n ); - t.strictEqual( isPositiveZerof( real( v ) ), true, 'returns expected value' ); - t.strictEqual( isPositiveZerof( imag( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( imagf( v ) ), true, 'returns expected value' ); } 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', function test( t ) { - var x; - var v; - - x = f32( f32( -0.2 ) - f32( 0.1 ) ); // returns -0.30000001192092896 - v = cfloornf( new Complex64( x, x ), -8 ); - t.strictEqual( real( v ), f32( -0.30000000 ), 'returns expected value' ); - t.strictEqual( imag( v ), f32( -0.30000000 ), 'returns expected value' ); - t.end(); -}); - tape( 'the function supports rounding very small numbers (including subnormals)', function test( t ) { var expected; var x; @@ -313,8 +286,35 @@ tape( 'the function supports rounding very small numbers (including subnormals)' for ( i = 0; i < n.length; i++ ) { v = cfloornf( new Complex64( x, x ), n[ i ] ); - t.strictEqual( isAlmostSameValuef( real( v ), expected[ i ], 1 ), true, 'returns expected value' ); - t.strictEqual( isAlmostSameValuef( imag( v ), expected[ i ], 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( realf( v ), expected[ i ], 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( imagf( v ), expected[ i ], 1 ), true, 'returns expected value' ); } 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( realf( v ), x, 'returns expected value' ); + t.strictEqual( imagf( v ), x, 'returns expected value' ); + + x = f32( -3.14 ); + v = cfloornf( new Complex64( x, x ), -46 ); + t.strictEqual( realf( v ), x, 'returns expected value' ); + t.strictEqual( imagf( v ), x, 'returns expected value' ); + + x = f32( 16777216.0 ); + v = cfloornf( new Complex64( x, x ), -40 ); + t.strictEqual( realf( v ), x, 'returns expected value' ); + t.strictEqual( imagf( v ), x, 'returns expected value' ); + + x = f32( -16777216.0 ); + v = cfloornf( new Complex64( x, x ), -40 ); + t.strictEqual( realf( v ), x, 'returns expected value' ); + t.strictEqual( imagf( v ), x, 'returns expected value' ); + + 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 index 3750c99f927a..4790db37daad 100644 --- 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 @@ -25,7 +25,7 @@ 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 roundf = require( '@stdlib/math/base/special/roundf' ); var powf = require( '@stdlib/math/base/special/powf' ); var isAlmostSameValuef = require( '@stdlib/number/float32/base/assert/is-almost-same-value' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); @@ -33,8 +33,8 @@ 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 realf = require( '@stdlib/complex/float32/real' ); +var imagf = require( '@stdlib/complex/float32/imag' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -58,52 +58,34 @@ 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.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isnanf( imagf( v ) ), true, 'returns expected value' ); v = cfloornf( new Complex64( NaN, 3.14 ), 0 ); - t.strictEqual( isnanf( real( v ) ), true, 'returns expected value' ); - t.strictEqual( isnanf( imag( v ) ), false, 'returns expected value' ); + t.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isnanf( imagf( v ) ), false, 'returns expected value' ); v = cfloornf( new Complex64( 3.14, NaN ), 0 ); - t.strictEqual( isnanf( real( v ) ), false, 'returns expected value' ); - t.strictEqual( isnanf( imag( v ) ), true, 'returns expected value' ); + t.strictEqual( isnanf( realf( v ) ), false, 'returns expected value' ); + t.strictEqual( isnanf( imagf( v ) ), true, 'returns expected value' ); t.end(); }); -tape( 'the function returns `+infinity` if provided `+infinity`', opts, 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`', opts, 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 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' ); + t.strictEqual( isNegativeZerof( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZerof( imagf( 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.strictEqual( isNegativeZerof( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZerof( imagf( 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.strictEqual( isNegativeZerof( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZerof( imagf( v ) ), true, 'returns expected value' ); t.end(); }); @@ -112,17 +94,35 @@ 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' ); + t.strictEqual( isPositiveZerof( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( imagf( 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.strictEqual( isPositiveZerof( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( imagf( 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.strictEqual( isPositiveZerof( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( imagf( v ) ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `+infinity` if provided `+infinity`', opts, function test( t ) { + var v; + + v = cfloornf( new Complex64( PINF, PINF ), 5 ); + t.strictEqual( realf( v ), PINF, 'returns expected value' ); + t.strictEqual( imagf( v ), PINF, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `-infinity` if provided `-infinity`', opts, function test( t ) { + var v; + v = cfloornf( new Complex64( NINF, NINF ), -3 ); + t.strictEqual( realf( v ), NINF, 'returns expected value' ); + t.strictEqual( imagf( v ), NINF, 'returns expected value' ); t.end(); }); @@ -130,38 +130,49 @@ tape( 'the function supports rounding real and imaginary components to a desired var v; v = cfloornf( new Complex64( -3.141592653589793, 3.141592653589793 ), -2 ); - t.strictEqual( real( v ), f32( -3.15 ), 'returns expected value' ); - t.strictEqual( imag( v ), f32( 3.14 ), 'returns expected value' ); + t.strictEqual( realf( v ), f32( -3.15 ), 'returns expected value' ); + t.strictEqual( imagf( v ), f32( 3.14 ), 'returns expected value' ); v = cfloornf( new Complex64( 3.141592653589793, -3.141592653589793 ), -2 ); - t.strictEqual( real( v ), f32( 3.14 ), 'returns expected value' ); - t.strictEqual( imag( v ), f32( -3.15 ), 'returns expected value' ); + t.strictEqual( realf( v ), f32( 3.14 ), 'returns expected value' ); + t.strictEqual( imagf( v ), f32( -3.15 ), 'returns expected value' ); v = cfloornf( new Complex64( 9.99999, 9.99999 ), -2 ); - t.strictEqual( real( v ), f32( 9.99 ), 'returns expected value' ); - t.strictEqual( imag( v ), f32( 9.99 ), 'returns expected value' ); + t.strictEqual( realf( v ), f32( 9.99 ), 'returns expected value' ); + t.strictEqual( imagf( v ), f32( 9.99 ), 'returns expected value' ); v = cfloornf( new Complex64( -9.99999, -9.99999 ), -2 ); - t.strictEqual( real( v ), f32( -10.0 ), 'returns expected value' ); - t.strictEqual( imag( v ), f32( -10.0 ), 'returns expected value' ); + t.strictEqual( realf( v ), f32( -10.0 ), 'returns expected value' ); + t.strictEqual( imagf( v ), f32( -10.0 ), '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.strictEqual( realf( v ), 0.0, 'returns expected value' ); + t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); t.end(); }); +tape( 'rounding components to a desired number of decimals can result in unexpected behavior', opts, function test( t ) { + var x; + var v; + + x = f32( f32( -0.2 ) - f32( 0.1 ) ); // returns -0.30000001192092896 + v = cfloornf( new Complex64( x, x ), -8 ); + t.strictEqual( realf( v ), f32( -0.30000000 ), 'returns expected value' ); + t.strictEqual( imagf( v ), f32( -0.30000000 ), '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( real( v ), -1300.0, 'returns expected value' ); - t.strictEqual( imag( v ), 1200.0, 'returns expected value' ); + t.strictEqual( realf( v ), -1300.0, 'returns expected value' ); + t.strictEqual( imagf( v ), 1200.0, 'returns expected value' ); v = cfloornf( new Complex64( 12363.0, -12373.0 ), 1 ); - t.strictEqual( real( v ), 12360.0, 'returns expected value' ); - t.strictEqual( imag( v ), -12380.0, 'returns expected value' ); + t.strictEqual( realf( v ), 12360.0, 'returns expected value' ); + t.strictEqual( imagf( v ), -12380.0, 'returns expected value' ); t.end(); }); @@ -173,12 +184,12 @@ tape( 'the function returns the components unchanged if provided an `n` which is var v; var i; for ( i = 0; i < 100; i++ ) { - exp = round( randu()*76.0 ) - 38; + exp = roundf( randu()*76.0 ) - 38; x = f32( (1.0+randu()) * powf( 10.0, exp ) ); - n = -(round( randu()*100.0 ) + 46); + n = -(roundf( 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.strictEqual( realf( v ), x, 'returns expected value' ); + t.strictEqual( imagf( v ), x, 'returns expected value' ); } t.end(); }); @@ -192,12 +203,12 @@ tape( 'if a component is too large a float to have decimals and `n < 0`, the com var i; for ( i = 0; i < 100; i++ ) { sign = ( randu()<0.5 ) ? -1.0 : 1.0; - exp = 8 + round( randu()*30.0 ); + exp = 8 + roundf( randu()*30.0 ); x = f32( sign * (1.0+randu()) * powf( 10.0, exp ) ); - n = -( round( randu()*38.0) ); + n = -( roundf( 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.strictEqual( realf( v ), x, 'returns expected value' ); + t.strictEqual( imagf( v ), x, 'returns expected value' ); } t.end(); }); @@ -209,12 +220,12 @@ tape( 'if `n > 38` and a component is less than zero, the function returns `-inf var v; var i; for ( i = 0; i < 100; i++ ) { - exp = round( randu()*37.0 ); + exp = roundf( randu()*37.0 ); x = f32( -(1.0+randu()) * powf( 10.0, exp ) ); - n = round( randu()*10.0 ) + 39; + n = roundf( randu()*10.0 ) + 39; v = cfloornf( new Complex64( x, x ), n ); - t.strictEqual( real( v ), NINF, 'returns expected value' ); - t.strictEqual( imag( v ), NINF, 'returns expected value' ); + t.strictEqual( realf( v ), NINF, 'returns expected value' ); + t.strictEqual( imagf( v ), NINF, 'returns expected value' ); } t.end(); }); @@ -226,54 +237,16 @@ tape( 'if `n > 38` and a component is greater than or equal to zero, the functio var v; var i; for ( i = 0; i < 100; i++ ) { - exp = round( randu()*37.0 ); + exp = roundf( randu()*37.0 ); x = f32( (1.0+randu()) * powf( 10.0, exp ) ); - n = round( randu()*10.0 ) + 39; + n = roundf( randu()*10.0 ) + 39; v = cfloornf( new Complex64( x, x ), n ); - t.strictEqual( isPositiveZerof( real( v ) ), true, 'returns expected value' ); - t.strictEqual( isPositiveZerof( imag( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( imagf( v ) ), true, 'returns expected value' ); } 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(); -}); - -tape( 'rounding components to a desired number of decimals can result in unexpected behavior', opts, function test( t ) { - var x; - var v; - - x = f32( f32( -0.2 ) - f32( 0.1 ) ); // returns -0.30000001192092896 - v = cfloornf( new Complex64( x, x ), -8 ); - t.strictEqual( real( v ), f32( -0.30000000 ), 'returns expected value' ); - t.strictEqual( imag( v ), f32( -0.30000000 ), 'returns expected value' ); - t.end(); -}); - tape( 'the function supports rounding very small numbers (including subnormals)', opts, function test( t ) { var expected; var x; @@ -300,8 +273,35 @@ tape( 'the function supports rounding very small numbers (including subnormals)' for ( i = 0; i < n.length; i++ ) { v = cfloornf( new Complex64( x, x ), n[ i ] ); - t.strictEqual( isAlmostSameValuef( real( v ), expected[ i ], 1 ), true, 'returns expected value' ); - t.strictEqual( isAlmostSameValuef( imag( v ), expected[ i ], 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( realf( v ), expected[ i ], 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( imagf( v ), expected[ i ], 1 ), true, 'returns expected value' ); } 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( realf( v ), x, 'returns expected value' ); + t.strictEqual( imagf( v ), x, 'returns expected value' ); + + x = f32( -3.14 ); + v = cfloornf( new Complex64( x, x ), -46 ); + t.strictEqual( realf( v ), x, 'returns expected value' ); + t.strictEqual( imagf( v ), x, 'returns expected value' ); + + x = f32( 16777216.0 ); + v = cfloornf( new Complex64( x, x ), -40 ); + t.strictEqual( realf( v ), x, 'returns expected value' ); + t.strictEqual( imagf( v ), x, 'returns expected value' ); + + x = f32( -16777216.0 ); + v = cfloornf( new Complex64( x, x ), -40 ); + t.strictEqual( realf( v ), x, 'returns expected value' ); + t.strictEqual( imagf( v ), x, 'returns expected value' ); + + t.end(); +}); From 4f746d4c493d2171935fc784f336187b526cd8d0 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Tue, 4 Aug 2026 23:30:19 -0700 Subject: [PATCH 12/12] chore: code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/math/base/special/cfloornf/README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/cfloornf/README.md b/lib/node_modules/@stdlib/math/base/special/cfloornf/README.md index 46dd54ca913d..58181f0d8a44 100644 --- a/lib/node_modules/@stdlib/math/base/special/cfloornf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/cfloornf/README.md @@ -67,11 +67,12 @@ v = cfloornf( new Complex64( NaN, NaN ), 0 ); 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 + var x = f32( f32( -0.2 ) - f32( 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 ); + // Should round components to -0.3: + var v = cfloornf( new Complex64( x, x ), -8 ); + // returns [ -0.30000001192092896, -0.30000001192092896 ] ```