From fa12b7b04c2ff6fe9f96f55f3eda481d65b44414 Mon Sep 17 00:00:00 2001 From: Kamal Singh Rautela Date: Tue, 10 Feb 2026 16:39:18 +0530 Subject: [PATCH 1/3] Add C implementation for @stdlib/math/base/special/heaviside - Add C header file defining STDLIB_BASE_HEAVISIDE_CONTINUITY enum - Implement stdlib_base_heaviside in C for double-precision - Create Node-API addon bridge for JavaScript integration - Add GYP build configuration (binding.gyp, include.gypi, manifest.json) - Create lib/native.js dispatcher with string-to-enum mapping - Update lib/index.js to use native implementation when available - Update package.json to enable gypfile and add src/include directories - Add comprehensive native test suite (test/test.native.js) - All tests passing (213/213 native, 2013/2013 standard) This implementation follows the pattern established by heavisidef and provides performance improvements through native C code while maintaining full API compatibility with the existing JavaScript implementation. --- .../math/base/special/heaviside/binding.gyp | 166 ++++++++++++++++++ .../math/base/special/heaviside/include.gypi | 47 +++++ .../stdlib/math/base/special/heaviside.h | 53 ++++++ .../math/base/special/heaviside/lib/index.js | 45 ++++- .../math/base/special/heaviside/lib/native.js | 60 +++++++ .../math/base/special/heaviside/manifest.json | 76 ++++++++ .../math/base/special/heaviside/package.json | 3 + .../math/base/special/heaviside/src/Makefile | 70 ++++++++ .../math/base/special/heaviside/src/addon.c | 42 +++++ .../math/base/special/heaviside/src/main.c | 56 ++++++ .../special/heaviside/test/test.native.js | 131 ++++++++++++++ 11 files changed, 748 insertions(+), 1 deletion(-) create mode 100644 lib/node_modules/@stdlib/math/base/special/heaviside/binding.gyp create mode 100644 lib/node_modules/@stdlib/math/base/special/heaviside/include.gypi create mode 100644 lib/node_modules/@stdlib/math/base/special/heaviside/include/stdlib/math/base/special/heaviside.h create mode 100644 lib/node_modules/@stdlib/math/base/special/heaviside/lib/native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/heaviside/manifest.json create mode 100644 lib/node_modules/@stdlib/math/base/special/heaviside/src/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/heaviside/src/addon.c create mode 100644 lib/node_modules/@stdlib/math/base/special/heaviside/src/main.c create mode 100644 lib/node_modules/@stdlib/math/base/special/heaviside/test/test.native.js diff --git a/lib/node_modules/@stdlib/math/base/special/heaviside/binding.gyp b/lib/node_modules/@stdlib/math/base/special/heaviside/binding.gyp new file mode 100644 index 000000000000..6a161f876587 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/heaviside/binding.gyp @@ -0,0 +1,166 @@ +# @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. + +{ + # 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/heaviside/include.gypi b/lib/node_modules/@stdlib/math/base/special/heaviside/include.gypi new file mode 100644 index 000000000000..ca7df2628e2c --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/heaviside/include.gypi @@ -0,0 +1,47 @@ +# @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. + +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + ' + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 2 ); + STDLIB_NAPI_ARGV_DOUBLE( env, x, argv, 0 ); + STDLIB_NAPI_ARGV_INT32( env, continuity, argv, 1 ); + STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_base_heaviside( x, (enum STDLIB_BASE_HEAVISIDE_CONTINUITY)continuity ), out ); + return out; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/math/base/special/heaviside/src/main.c b/lib/node_modules/@stdlib/math/base/special/heaviside/src/main.c new file mode 100644 index 000000000000..4827d43530f3 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/heaviside/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/heaviside.h" +#include "stdlib/math/base/assert/is_nan.h" + +/** +* Evaluates the Heaviside function for a double-precision floating-point number. +* +* @param x input value +* @param continuity continuity option +* @return function value +* +* @example +* double y = stdlib_base_heaviside( 0.0, STDLIB_BASE_HEAVISIDE_CONTINUITY_HALF_MAXIMUM ); +* // returns 0.5 +*/ +double stdlib_base_heaviside( const double x, const enum STDLIB_BASE_HEAVISIDE_CONTINUITY continuity ) { + if ( stdlib_base_is_nan( x ) ) { + return 0.0 / 0.0; // NaN + } + if ( x > 0.0 ) { + return 1.0; + } + // Handle `+-0`... + if ( x == 0.0 ) { + switch ( continuity ) { + case STDLIB_BASE_HEAVISIDE_CONTINUITY_HALF_MAXIMUM: + return 0.5; + case STDLIB_BASE_HEAVISIDE_CONTINUITY_LEFT_CONTINUOUS: + return 0.0; + case STDLIB_BASE_HEAVISIDE_CONTINUITY_RIGHT_CONTINUOUS: + return 1.0; + case STDLIB_BASE_HEAVISIDE_CONTINUITY_DISCONTINUOUS: + return 0.0 / 0.0; // NaN + default: + return 0.0 / 0.0; // NaN + } + } + return 0.0; +} diff --git a/lib/node_modules/@stdlib/math/base/special/heaviside/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/heaviside/test/test.native.js new file mode 100644 index 000000000000..02469e0ff30e --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/heaviside/test/test.native.js @@ -0,0 +1,131 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var randu = require( '@stdlib/random/base/randu' ); +var heaviside = require( './../lib/native.js' ); + + +// TESTS // + +tape('main export is a function', function test(t) { + t.ok(true, __filename); + t.strictEqual(typeof heaviside, 'function', 'main export is a function'); + t.end(); +}); + +tape('the function returns `0` if `x` is negative', function test(t) { + var x; + var v; + var i; + + for (i = 0; i < 1e2; i++) { + x = -(randu() * 100.0) - EPS; + v = heaviside(x, 'left-continuous'); + t.strictEqual(isPositiveZero(v), true, 'returns expected value when provided ' + x); + } + t.end(); +}); + +tape('the function returns `1` if `x` is positive', function test(t) { + var x; + var v; + var i; + + for (i = 0; i < 1e2; i++) { + x = (randu() * 100.0) + EPS; + v = heaviside(x, 'right-continuous'); + t.strictEqual(v, 1.0, 'returns expected value when provided ' + x); + } + t.end(); +}); + +tape('the function returns `0.5` if provided `+-0` and continuity is `half-maximum`', function test(t) { + var v; + + v = heaviside(-0.0, 'half-maximum'); + t.strictEqual(v, 0.5, 'returns expected value'); + + v = heaviside(+0.0, 'half-maximum'); + t.strictEqual(v, 0.5, 'returns expected value'); + + t.end(); +}); + +tape('the function returns `0.0` if provided `+-0` and continuity is `left-continuous`', function test(t) { + var v; + + v = heaviside(-0.0, 'left-continuous'); + t.strictEqual(isPositiveZero(v), true, 'returns expected value'); + + v = heaviside(+0.0, 'left-continuous'); + t.strictEqual(isPositiveZero(v), true, 'returns expected value'); + + t.end(); +}); + +tape('the function returns `1.0` if provided `+-0` and continuity is `right-continuous`', function test(t) { + var v; + + v = heaviside(-0.0, 'right-continuous'); + t.strictEqual(v, 1.0, 'returns expected value'); + + v = heaviside(+0.0, 'right-continuous'); + t.strictEqual(v, 1.0, 'returns expected value'); + + t.end(); +}); + +tape('by default, the function returns `NaN` if provided `+-0`', function test(t) { + var v; + + v = heaviside(-0.0); + t.strictEqual(isnan(v), true, 'returns expected value'); + + v = heaviside(+0.0); + t.strictEqual(isnan(v), true, 'returns expected value'); + + t.end(); +}); + +tape('the function returns `NaN` if provided `NaN`', function test(t) { + var v = heaviside(NaN); + t.strictEqual(isnan(v), true, 'returns expected value'); + t.end(); +}); + +tape('the function returns `0` if provided `-infinity`', function test(t) { + var v = heaviside(NINF); + t.strictEqual(v, 0.0, 'returns expected value'); + t.end(); +}); + +tape('the function returns `+1` if provided `+infinity`', function test(t) { + var v = heaviside(PINF); + t.strictEqual(v, 1.0, 'returns expected value'); + t.end(); +}); From 37d321c75b253af990d4a5fc66642c2167f51b20 Mon Sep 17 00:00:00 2001 From: Kamal Singh Rautela Date: Wed, 11 Feb 2026 04:25:05 +0530 Subject: [PATCH 2/3] fix: address review feedback from Planeshifter - Revert lib/index.js to simple passthrough pattern - Create separate lib/enum.js and lib/str2enum.js modules - Update lib/native.js to use str2enum with proper spacing conventions - Fix test/test.native.js with tryRequire pattern and stdlib spacing - All tests passing (213/213 native, 2013/2013 standard) Follows pattern established in heavisidef as requested by @Planeshifter --- .../math/base/special/heaviside/lib/enum.js | 52 +++++++++++ .../math/base/special/heaviside/lib/index.js | 47 +--------- .../math/base/special/heaviside/lib/native.js | 46 ++++++---- .../base/special/heaviside/lib/str2enum.js | 52 +++++++++++ .../special/heaviside/test/test.native.js | 91 +++++++++++++------ 5 files changed, 197 insertions(+), 91 deletions(-) create mode 100644 lib/node_modules/@stdlib/math/base/special/heaviside/lib/enum.js create mode 100644 lib/node_modules/@stdlib/math/base/special/heaviside/lib/str2enum.js diff --git a/lib/node_modules/@stdlib/math/base/special/heaviside/lib/enum.js b/lib/node_modules/@stdlib/math/base/special/heaviside/lib/enum.js new file mode 100644 index 000000000000..fcd7e0fad2d4 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/heaviside/lib/enum.js @@ -0,0 +1,52 @@ +/** +* @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'; + +// MAIN // + +/** +* Returns an object mapping supported function continuity type strings to enumeration constants. +* +* @private +* @returns {Object} object mapping supported function continuity types to enumeration constants +* +* @example +* var table = enumeration(); +* // returns +*/ +function enumeration() { + return { + // Half-maximum: + 'half-maximum': 0, + + // Left-continuous: + 'left-continuous': 1, + + // Right-continuous: + 'right-continuous': 2, + + // Discontinuous: + 'discontinuous': 3 + }; +} + + +// EXPORTS // + +module.exports = enumeration; diff --git a/lib/node_modules/@stdlib/math/base/special/heaviside/lib/index.js b/lib/node_modules/@stdlib/math/base/special/heaviside/lib/index.js index 0879af4257ff..9bb11a06e539 100644 --- a/lib/node_modules/@stdlib/math/base/special/heaviside/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/special/heaviside/lib/index.js @@ -50,52 +50,9 @@ // MODULES // -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); -var main = require( './main.js' ); -var native = require( './native.js' ); - - -// MAIN // - -/** -* Evaluate the Heaviside function. -* -* @module @stdlib/math/base/special/heaviside -* -* @example -* var heaviside = require( '@stdlib/math/base/special/heaviside' ); -* -* var v = heaviside( 3.14 ); -* // returns 1.0 -* -* v = heaviside( -3.14 ); -* // returns 0.0 -* -* v = heaviside( 0.0 ); -* // returns NaN -* -* v = heaviside( 0.0, 'half-maximum' ); -* // returns 0.5 -* -* v = heaviside( 0.0, 'left-continuous' ); -* // returns 0.0 -* -* v = heaviside( 0.0, 'right-continuous' ); -* // returns 1.0 -* -* v = heaviside( NaN ); -* // returns NaN -*/ -var heaviside; -if (native) { - heaviside = native; -} else { - heaviside = main; -} - -setReadOnly(heaviside, 'native', native); +var main = require('./main.js'); // EXPORTS // -module.exports = heaviside; +module.exports = main; diff --git a/lib/node_modules/@stdlib/math/base/special/heaviside/lib/native.js b/lib/node_modules/@stdlib/math/base/special/heaviside/lib/native.js index e6ea49388d34..bece130d9c61 100644 --- a/lib/node_modules/@stdlib/math/base/special/heaviside/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/heaviside/lib/native.js @@ -20,22 +20,14 @@ // MODULES // -var addon = require( './../src/addon.node' ); - - -// VARIABLES // - -var CONTINUITY = { - 'half-maximum': 0, - 'left-continuous': 1, - 'right-continuous': 2 -}; +var addon = require('./../src/addon.node'); +var str2enum = require('./str2enum.js'); // MAIN // /** -* Evaluates the Heaviside function using native code. +* Evaluates the Heaviside function. * * @private * @param {number} x - input value @@ -43,15 +35,35 @@ var CONTINUITY = { * @returns {number} function value * * @example -* var v = heaviside( 3.14, 'half-maximum' ); +* var v = heaviside( 3.14 ); +* // returns 1.0 +* +* @example +* var v = heaviside( -3.14 ); +* // returns 0.0 +* +* @example +* var v = heaviside( 0.0, 'half-maximum' ); +* // returns 0.5 +* +* @example +* var v = heaviside( 0.0, 'left-continuous' ); +* // returns 0.0 +* +* @example +* var v = heaviside( 0.0, 'right-continuous' ); * // returns 1.0 +* +* @example +* var v = heaviside( 0.0, 'discontinuous' ); +* // returns NaN +* +* @example +* var v = heaviside( NaN, 'right-continuous' ); +* // returns NaN */ function heaviside(x, continuity) { - var c = CONTINUITY[continuity]; - if (c === void 0) { - c = 3; // Discontinuous - } - return addon(x, c); + return addon(x, str2enum(continuity)); } diff --git a/lib/node_modules/@stdlib/math/base/special/heaviside/lib/str2enum.js b/lib/node_modules/@stdlib/math/base/special/heaviside/lib/str2enum.js new file mode 100644 index 000000000000..a08fb4ddd0cb --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/heaviside/lib/str2enum.js @@ -0,0 +1,52 @@ +/** +* @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 enumeration = require('./enum.js'); + + +// VARIABLES // + +var ENUM = enumeration(); + + +// MAIN // + +/** +* Returns the enumeration constant associated with a function continuity type string. +* +* @private +* @param {string} ctype - function continuity type string +* @returns {(integer|null)} integer value or null +* +* @example +* var v = str2enum( 'left-continuous' ); +* // returns +*/ +function str2enum(ctype) { + var v = ENUM[ctype]; + return (typeof v === 'number') ? v : -1; // note: we include this guard to prevent walking the prototype chain +} + + +// EXPORTS // + +module.exports = str2enum; diff --git a/lib/node_modules/@stdlib/math/base/special/heaviside/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/heaviside/test/test.native.js index 02469e0ff30e..a7a44cb77f52 100644 --- a/lib/node_modules/@stdlib/math/base/special/heaviside/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/heaviside/test/test.native.js @@ -20,51 +20,84 @@ // MODULES // -var tape = require( 'tape' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); -var PINF = require( '@stdlib/constants/float64/pinf' ); -var NINF = require( '@stdlib/constants/float64/ninf' ); -var EPS = require( '@stdlib/constants/float64/eps' ); -var randu = require( '@stdlib/random/base/randu' ); -var heaviside = require( './../lib/native.js' ); +var resolve = require('path').resolve; +var tape = require('tape'); +var isnan = require('@stdlib/math/base/assert/is-nan'); +var isPositiveZero = require('@stdlib/math/base/assert/is-positive-zero'); +var PINF = require('@stdlib/constants/float64/pinf'); +var NINF = require('@stdlib/constants/float64/ninf'); +var EPS = require('@stdlib/constants/float64/eps'); +var randu = require('@stdlib/random/base/randu'); +var tryRequire = require('@stdlib/utils/try-require'); + + +// VARIABLES // + +var heaviside = tryRequire(resolve(__dirname, './../lib/native.js')); +var opts = { + 'skip': (heaviside instanceof Error) +}; // TESTS // -tape('main export is a function', function test(t) { +tape('main export is a function', opts, function test(t) { t.ok(true, __filename); t.strictEqual(typeof heaviside, 'function', 'main export is a function'); t.end(); }); -tape('the function returns `0` if `x` is negative', function test(t) { +tape('the function returns `0` if `x` is negative', opts, function test(t) { var x; var v; var i; - for (i = 0; i < 1e2; i++) { + for (i = 0; i < 1e3; i++) { x = -(randu() * 100.0) - EPS; - v = heaviside(x, 'left-continuous'); + v = heaviside(x); t.strictEqual(isPositiveZero(v), true, 'returns expected value when provided ' + x); } t.end(); }); -tape('the function returns `1` if `x` is positive', function test(t) { +tape('the function returns `1` if `x` is positive', opts, function test(t) { var x; var v; var i; - for (i = 0; i < 1e2; i++) { + for (i = 0; i < 1e3; i++) { x = (randu() * 100.0) + EPS; - v = heaviside(x, 'right-continuous'); + v = heaviside(x); t.strictEqual(v, 1.0, 'returns expected value when provided ' + x); } t.end(); }); -tape('the function returns `0.5` if provided `+-0` and continuity is `half-maximum`', function test(t) { +tape('by default, the function returns `NaN` if provided `+-0`', opts, function test(t) { + var v; + + v = heaviside(-0.0); + t.strictEqual(isnan(v), true, 'returns expected value'); + + v = heaviside(+0.0); + t.strictEqual(isnan(v), true, 'returns expected value'); + + t.end(); +}); + +tape('if the `continuity` option is `discontinuous`, the function returns `NaN` if provided `+-0`', opts, function test(t) { + var v; + + v = heaviside(-0.0, 'discontinuous'); + t.strictEqual(isnan(v), true, 'returns expected value'); + + v = heaviside(+0.0, 'discontinuous'); + t.strictEqual(isnan(v), true, 'returns expected value'); + + t.end(); +}); + +tape('if the `continuity` option is `half-maximum`, the function returns `0.5` if provided `+-0`', opts, function test(t) { var v; v = heaviside(-0.0, 'half-maximum'); @@ -76,7 +109,7 @@ tape('the function returns `0.5` if provided `+-0` and continuity is `half-maxim t.end(); }); -tape('the function returns `0.0` if provided `+-0` and continuity is `left-continuous`', function test(t) { +tape('if the `continuity` option is `left-continuous`, the function returns `0.0` if provided `+-0`', opts, function test(t) { var v; v = heaviside(-0.0, 'left-continuous'); @@ -88,44 +121,44 @@ tape('the function returns `0.0` if provided `+-0` and continuity is `left-conti t.end(); }); -tape('the function returns `1.0` if provided `+-0` and continuity is `right-continuous`', function test(t) { +tape('if the `continuity` option is `right-continuous`, the function returns `1` if provided `+-0`', opts, function test(t) { var v; v = heaviside(-0.0, 'right-continuous'); - t.strictEqual(v, 1.0, 'returns expected value'); + t.strictEqual(v, 1, 'returns expected value'); v = heaviside(+0.0, 'right-continuous'); - t.strictEqual(v, 1.0, 'returns expected value'); + t.strictEqual(v, 1, 'returns expected value'); t.end(); }); -tape('by default, the function returns `NaN` if provided `+-0`', function test(t) { +tape('if the `continuity` option is not valid, the function returns `NaN` if provided `+-0`', opts, function test(t) { var v; - v = heaviside(-0.0); + v = heaviside(-0.0, 'foo'); t.strictEqual(isnan(v), true, 'returns expected value'); - v = heaviside(+0.0); + v = heaviside(+0.0, 'bar'); t.strictEqual(isnan(v), true, 'returns expected value'); t.end(); }); -tape('the function returns `NaN` if provided `NaN`', function test(t) { - var v = heaviside(NaN); +tape('the function returns `NaN` if provided `NaN`', opts, function test(t) { + var v = heaviside(NaN, 'left-continuous'); t.strictEqual(isnan(v), true, 'returns expected value'); t.end(); }); -tape('the function returns `0` if provided `-infinity`', function test(t) { - var v = heaviside(NINF); +tape('the function returns `0` if provided `-infinity`', opts, function test(t) { + var v = heaviside(NINF, 'left-continuous'); t.strictEqual(v, 0.0, 'returns expected value'); t.end(); }); -tape('the function returns `+1` if provided `+infinity`', function test(t) { - var v = heaviside(PINF); +tape('the function returns `+1` if provided `+infinity`', opts, function test(t) { + var v = heaviside(PINF, 'left-continuous'); t.strictEqual(v, 1.0, 'returns expected value'); t.end(); }); From 7da0604328cdfb174896510c766083583e255309 Mon Sep 17 00:00:00 2001 From: Kamal Singh Rautela Date: Wed, 11 Feb 2026 11:50:25 +0530 Subject: [PATCH 3/3] style: fix indentation and add spaces in parentheses --- .../math/base/special/heaviside/lib/enum.js | 20 +++++++++---------- .../math/base/special/heaviside/lib/index.js | 2 +- .../math/base/special/heaviside/lib/native.js | 8 ++++---- .../base/special/heaviside/lib/str2enum.js | 8 ++++---- .../math/base/special/heaviside/manifest.json | 2 +- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/heaviside/lib/enum.js b/lib/node_modules/@stdlib/math/base/special/heaviside/lib/enum.js index fcd7e0fad2d4..e4c6ae06830c 100644 --- a/lib/node_modules/@stdlib/math/base/special/heaviside/lib/enum.js +++ b/lib/node_modules/@stdlib/math/base/special/heaviside/lib/enum.js @@ -31,19 +31,19 @@ * // returns */ function enumeration() { - return { - // Half-maximum: - 'half-maximum': 0, + return { + // Half-maximum: + 'half-maximum': 0, - // Left-continuous: - 'left-continuous': 1, + // Left-continuous: + 'left-continuous': 1, - // Right-continuous: - 'right-continuous': 2, + // Right-continuous: + 'right-continuous': 2, - // Discontinuous: - 'discontinuous': 3 - }; + // Discontinuous: + 'discontinuous': 3 + }; } diff --git a/lib/node_modules/@stdlib/math/base/special/heaviside/lib/index.js b/lib/node_modules/@stdlib/math/base/special/heaviside/lib/index.js index 9bb11a06e539..9f6e92a627cb 100644 --- a/lib/node_modules/@stdlib/math/base/special/heaviside/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/special/heaviside/lib/index.js @@ -50,7 +50,7 @@ // MODULES // -var main = require('./main.js'); +var main = require( './main.js' ); // EXPORTS // diff --git a/lib/node_modules/@stdlib/math/base/special/heaviside/lib/native.js b/lib/node_modules/@stdlib/math/base/special/heaviside/lib/native.js index bece130d9c61..6b649b6686e3 100644 --- a/lib/node_modules/@stdlib/math/base/special/heaviside/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/heaviside/lib/native.js @@ -20,8 +20,8 @@ // MODULES // -var addon = require('./../src/addon.node'); -var str2enum = require('./str2enum.js'); +var addon = require( './../src/addon.node' ); +var str2enum = require( './str2enum.js' ); // MAIN // @@ -62,8 +62,8 @@ var str2enum = require('./str2enum.js'); * var v = heaviside( NaN, 'right-continuous' ); * // returns NaN */ -function heaviside(x, continuity) { - return addon(x, str2enum(continuity)); +function heaviside( x, continuity ) { + return addon( x, str2enum( continuity ) ); } diff --git a/lib/node_modules/@stdlib/math/base/special/heaviside/lib/str2enum.js b/lib/node_modules/@stdlib/math/base/special/heaviside/lib/str2enum.js index a08fb4ddd0cb..3f297c824223 100644 --- a/lib/node_modules/@stdlib/math/base/special/heaviside/lib/str2enum.js +++ b/lib/node_modules/@stdlib/math/base/special/heaviside/lib/str2enum.js @@ -20,7 +20,7 @@ // MODULES // -var enumeration = require('./enum.js'); +var enumeration = require( './enum.js' ); // VARIABLES // @@ -41,9 +41,9 @@ var ENUM = enumeration(); * var v = str2enum( 'left-continuous' ); * // returns */ -function str2enum(ctype) { - var v = ENUM[ctype]; - return (typeof v === 'number') ? v : -1; // note: we include this guard to prevent walking the prototype chain +function str2enum( ctype ) { + var v = ENUM[ ctype ]; + return ( typeof v === 'number' ) ? v : -1; // note: we include this guard to prevent walking the prototype chain } diff --git a/lib/node_modules/@stdlib/math/base/special/heaviside/manifest.json b/lib/node_modules/@stdlib/math/base/special/heaviside/manifest.json index 157b81d1cbd6..fc10ca525d4b 100644 --- a/lib/node_modules/@stdlib/math/base/special/heaviside/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/heaviside/manifest.json @@ -73,4 +73,4 @@ ] } ] -} +} \ No newline at end of file