diff --git a/lib/node_modules/@stdlib/math/base/special/heavisidef/README.md b/lib/node_modules/@stdlib/math/base/special/heavisidef/README.md new file mode 100644 index 000000000000..805032c2731f --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/heavisidef/README.md @@ -0,0 +1,182 @@ + + +# Heaviside Function + +> Evaluate the [Heaviside function][heaviside-function] for a single-precision floating-point number. + +
+ +The [Heaviside function][heaviside-function] is defined as + + + +```math +H(x) = \begin{cases} 1 & \textrm{if}\ x \gt 0 \\ 0 & \textrm{if}\ x \lt 0\end{cases} +``` + + + + + +and is discontinuous at `0`. Depending on the context, the [Heaviside function][heaviside-function] may be defined as a continuous function. To define the [Heaviside function][heaviside-function] such that the function has rotational symmetry, + + + +```math +H(x) = \begin{cases} x & \textrm{if}\ x \gt 0 \\ \frac{1}{2} & \textrm{if}\ x = 0 \\ 0 & \textrm{if}\ x \lt 0\end{cases} +``` + + + + + +To define the [Heaviside function][heaviside-function] as a left-continuous function, + + + +```math +H(x) = \begin{cases} x & \textrm{if}\ x \gt 0 \\ 0 & \textrm{if}\ x \leq 0\end{cases} +``` + + + + + +To define the [Heaviside function][heaviside-function] as a right-continuous function, + + + +```math +H(x) = \begin{cases} x & \textrm{if}\ x \geq 0 \\ 0 & \textrm{if}\ x \lt 0\end{cases} +``` + + + + + +
+ + + +
+ +## Usage + +```javascript +var heavisidef = require( '@stdlib/math/base/special/heavisidef' ); +``` + +#### heavisidef( x\[, continuity] ) + +Evaluates the [Heaviside function][heaviside-function] for a single-precision floating-point number. + +```javascript +var v = heavisidef( 3.14 ); +// returns 1.0 + +v = heavisidef( -3.14 ); +// returns 0.0 + +v = heavisidef( NaN ); +// returns NaN +``` + +The `continuity` parameter may be one of the following values: + +- `'half-maximum'`: if `x == 0`, the function returns `0.5`. +- `'left-continuous'`: if `x == 0`, the function returns `0.0`. +- `'right-continuous'`: if `x == 0`, the function returns `1.0`. + +By default, the function is discontinuous at `0`. + +```javascript +var v = heavisidef( 0.0 ); +// returns NaN +``` + +To define the [Heaviside function][heaviside-function] as a continuous function, set the `continuity` parameter. + +```javascript +var v = heavisidef( 0.0, 'half-maximum' ); +// returns 0.5 + +v = heavisidef( 0.0, 'left-continuous' ); +// returns 0.0 + +v = heavisidef( 0.0, 'right-continuous' ); +// returns 1.0 +``` + +
+ + + +
+ +## Examples + + + +```javascript +var linspace = require( '@stdlib/array/base/linspace' ); +var heavisidef = require( '@stdlib/math/base/special/heavisidef' ); + +var x = linspace( -10.0, 10.0, 101 ); + +var i; +for ( i = 0; i < x.length; i++ ) { + console.log( 'H(%d) = %f', x[ i ], heavisidef( x[ i ] ) ); +} +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/math/base/special/heavisidef/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/heavisidef/benchmark/benchmark.js new file mode 100644 index 000000000000..25e067228472 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/heavisidef/benchmark/benchmark.js @@ -0,0 +1,118 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pkg = require( './../package.json' ).name; +var heavisidef = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var x; + var y; + var i; + + x = uniform( 100, -50.0, 50.0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = heavisidef( x[ i % x.length ] ); + if ( y > 1.0 ) { + b.fail( 'should not return a value greater than 1' ); + } + } + b.toc(); + if ( y > 1.0 ) { + b.fail( 'should not return a value greater than 1' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::left-continuous', function benchmark( b ) { + var x; + var y; + var i; + + x = uniform( 100, -50.0, 50.0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = heavisidef( x[ i % x.length ], 'left-continuous' ); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::right-continuous', function benchmark( b ) { + var x; + var y; + var i; + + x = uniform( 100, -50.0, 50.0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = heavisidef( x[ i % x.length ], 'right-continuous' ); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::half-maximum', function benchmark( b ) { + var x; + var y; + var i; + + x = uniform( 100, -50.0, 50.0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = heavisidef( x[ i % x.length ], 'half-maximum' ); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/heavisidef/docs/img/equation_heaviside_function.svg b/lib/node_modules/@stdlib/math/base/special/heavisidef/docs/img/equation_heaviside_function.svg new file mode 100644 index 000000000000..2196d674a9b2 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/heavisidef/docs/img/equation_heaviside_function.svg @@ -0,0 +1,50 @@ + +upper H left-parenthesis x right-parenthesis equals StartLayout Enlarged left-brace 1st Row 1st Column 1 2nd Column if x greater-than 0 2nd Row 1st Column 0 2nd Column if x less-than 0 EndLayout + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/base/special/heavisidef/docs/img/equation_heaviside_function_half_maximum.svg b/lib/node_modules/@stdlib/math/base/special/heavisidef/docs/img/equation_heaviside_function_half_maximum.svg new file mode 100644 index 000000000000..1608e3bb4599 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/heavisidef/docs/img/equation_heaviside_function_half_maximum.svg @@ -0,0 +1,74 @@ + +upper H left-parenthesis x right-parenthesis equals StartLayout Enlarged left-brace 1st Row 1st Column x 2nd Column if x greater-than 0 2nd Row 1st Column one-half 2nd Column if x equals 0 3rd Row 1st Column 0 2nd Column if x less-than 0 EndLayout + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/base/special/heavisidef/docs/img/equation_heaviside_function_left_continuous.svg b/lib/node_modules/@stdlib/math/base/special/heavisidef/docs/img/equation_heaviside_function_left_continuous.svg new file mode 100644 index 000000000000..3d98435d2174 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/heavisidef/docs/img/equation_heaviside_function_left_continuous.svg @@ -0,0 +1,49 @@ + +upper H left-parenthesis x right-parenthesis equals StartLayout Enlarged left-brace 1st Row 1st Column x 2nd Column if x greater-than 0 2nd Row 1st Column 0 2nd Column if x less-than-or-equal-to 0 EndLayout + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/base/special/heavisidef/docs/img/equation_heaviside_function_right_continuous.svg b/lib/node_modules/@stdlib/math/base/special/heavisidef/docs/img/equation_heaviside_function_right_continuous.svg new file mode 100644 index 000000000000..d556954c5554 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/heavisidef/docs/img/equation_heaviside_function_right_continuous.svg @@ -0,0 +1,49 @@ + +upper H left-parenthesis x right-parenthesis equals StartLayout Enlarged left-brace 1st Row 1st Column x 2nd Column if x greater-than-or-equal-to 0 2nd Row 1st Column 0 2nd Column if x less-than 0 EndLayout + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/base/special/heavisidef/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/heavisidef/docs/repl.txt new file mode 100644 index 000000000000..dc072e24045b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/heavisidef/docs/repl.txt @@ -0,0 +1,46 @@ + +{{alias}}( x[, continuity] ) + Evaluates the Heaviside function for a single-precision floating-point + number. + + The `continuity` parameter may be one of the following: + + - 'half-maximum': if `x == 0`, the function returns `0.5`. + - 'left-continuous': if `x == 0`, the function returns `0`. + - 'right-continuous': if `x == 0`, the function returns `1`. + + By default, if `x == 0`, the function returns `NaN` (i.e., the function is + discontinuous). + + Parameters + ---------- + x: number + Input value. + + continuity: string (optional) + Specifies how to handle `x == 0`. By default, if `x == 0`, the function + returns `NaN`. + + Returns + ------- + y: number + Function value. + + Examples + -------- + > var y = {{alias}}( 3.14 ) + 1.0 + > y = {{alias}}( -3.14 ) + 0.0 + > y = {{alias}}( 0.0 ) + NaN + > y = {{alias}}( 0.0, 'half-maximum' ) + 0.5 + > y = {{alias}}( 0.0, 'left-continuous' ) + 0.0 + > y = {{alias}}( 0.0, 'right-continuous' ) + 1.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/math/base/special/heavisidef/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/heavisidef/docs/types/index.d.ts new file mode 100644 index 000000000000..d66b9efa85e0 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/heavisidef/docs/types/index.d.ts @@ -0,0 +1,71 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/** +* Evaluates the Heaviside function for a single-precision floating-point number. +* +* ## Notes +* +* - The `continuity` parameter may be one of the following: +* +* - 'half-maximum': if `x == 0`, the function returns `0.5`. +* - 'left-continuous': if `x == 0`, the function returns `0`. +* - 'right-continuous': if `x == 0`, the function returns `1`. +* +* - By default, if `x == 0`, the function returns `NaN` (i.e., the function is discontinuous). +* +* @param x - input value +* @param continuity - continuity option +* @returns function value +* +* @example +* var v = heavisidef( 3.14 ); +* // returns 1.0 +* +* @example +* var v = heavisidef( -3.14 ); +* // returns 0.0 +* +* @example +* var v = heavisidef( 0.0 ); +* // returns NaN +* +* @example +* var v = heavisidef( 0.0, 'half-maximum' ); +* // returns 0.5 +* +* @example +* var v = heavisidef( 0.0, 'left-continuous' ); +* // returns 0.0 +* +* @example +* var v = heavisidef( 0.0, 'right-continuous' ); +* // returns 1.0 +* +* @example +* var v = heavisidef( NaN ); +* // returns NaN +*/ +declare function heavisidef( x: number, continuity?: 'half-maximum' | 'left-continuous' | 'right-continuous' ): number; + + +// EXPORTS // + +export = heavisidef; diff --git a/lib/node_modules/@stdlib/math/base/special/heavisidef/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/heavisidef/docs/types/test.ts new file mode 100644 index 000000000000..822904262069 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/heavisidef/docs/types/test.ts @@ -0,0 +1,57 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import heavisidef = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + heavisidef( 3.141592653589793 ); // $ExpectType number + heavisidef( 0, 'half-maximum' ); // $ExpectType number + heavisidef( 0, 'left-continuous' ); // $ExpectType number + heavisidef( 0, 'right-continuous' ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument other than a number... +{ + heavisidef( true, 'half-maximum' ); // $ExpectError + heavisidef( false, 'half-maximum' ); // $ExpectError + heavisidef( '5', 'half-maximum' ); // $ExpectError + heavisidef( [], 'half-maximum' ); // $ExpectError + heavisidef( {}, 'half-maximum' ); // $ExpectError + heavisidef( ( x: number ): number => x, 'half-maximum' ); // $ExpectError +} + +// The compiler throws an error if the function is provided a value other than `left-continuous`, `left-continuous`, or `half-maximum` as its second argument... +{ + heavisidef( 0, true ); // $ExpectError + heavisidef( 0, false ); // $ExpectError + heavisidef( 0, '5' ); // $ExpectError + heavisidef( 0, 'abc' ); // $ExpectError + heavisidef( 0, [] ); // $ExpectError + heavisidef( 0, {} ); // $ExpectError + heavisidef( 0, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid number of arguments... +{ + heavisidef(); // $ExpectError + heavisidef( 3, 'half-maximum', 8 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/math/base/special/heavisidef/examples/index.js b/lib/node_modules/@stdlib/math/base/special/heavisidef/examples/index.js new file mode 100644 index 000000000000..d1dfdcdd1574 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/heavisidef/examples/index.js @@ -0,0 +1,29 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var linspace = require( '@stdlib/array/base/linspace' ); +var heavisidef = require( './../lib' ); + +var x = linspace( -10.0, 10.0, 101 ); + +var i; +for ( i = 0; i < x.length; i++ ) { + console.log( 'H(%d) = %f', x[ i ], heavisidef( x[ i ] ) ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/heavisidef/lib/index.js b/lib/node_modules/@stdlib/math/base/special/heavisidef/lib/index.js new file mode 100644 index 000000000000..74356df2adc6 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/heavisidef/lib/index.js @@ -0,0 +1,58 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Evaluate the Heaviside function for a single-precision floating-point number. +* +* @module @stdlib/math/base/special/heavisidef +* +* @example +* var heavisidef = require( '@stdlib/math/base/special/heavisidef' ); +* +* var v = heavisidef( 3.14 ); +* // returns 1.0 +* +* v = heavisidef( -3.14 ); +* // returns 0.0 +* +* v = heavisidef( 0.0 ); +* // returns NaN +* +* v = heavisidef( 0.0, 'half-maximum' ); +* // returns 0.5 +* +* v = heavisidef( 0.0, 'left-continuous' ); +* // returns 0.0 +* +* v = heavisidef( 0.0, 'right-continuous' ); +* // returns 1.0 +* +* v = heavisidef( NaN ); +* // returns NaN +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/math/base/special/heavisidef/lib/main.js b/lib/node_modules/@stdlib/math/base/special/heavisidef/lib/main.js new file mode 100644 index 000000000000..247700292d5d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/heavisidef/lib/main.js @@ -0,0 +1,90 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); + + +// MAIN // + +/** +* Evaluates the Heaviside function for a single-precision floating-point number. +* +* @param {number} x - input value +* @param {string} [continuity] - continuity option +* @returns {number} function value +* +* @example +* var v = heavisidef( 3.14 ); +* // returns 1.0 +* +* @example +* var v = heavisidef( -3.14 ); +* // returns 0.0 +* +* @example +* var v = heavisidef( 0.0 ); +* // returns NaN +* +* @example +* var v = heavisidef( 0.0, 'half-maximum' ); +* // returns 0.5 +* +* @example +* var v = heavisidef( 0.0, 'left-continuous' ); +* // returns 0.0 +* +* @example +* var v = heavisidef( 0.0, 'right-continuous' ); +* // returns 1.0 +* +* @example +* var v = heavisidef( NaN ); +* // returns NaN +*/ +function heavisidef( x, continuity ) { + if ( isnanf( x ) ) { + return NaN; + } + if ( x > 0.0 ) { + return 1.0; + } + // Handle `+-0`... + if ( x === 0.0 ) { + if ( continuity === 'half-maximum' ) { + return 0.5; + } + if ( continuity === 'left-continuous' ) { + return 0.0; + } + if ( continuity === 'right-continuous' ) { + return 1.0; + } + // Default behavior is discontinuity... + return NaN; + } + return 0.0; +} + + +// EXPORTS // + +module.exports = heavisidef; diff --git a/lib/node_modules/@stdlib/math/base/special/heavisidef/package.json b/lib/node_modules/@stdlib/math/base/special/heavisidef/package.json new file mode 100644 index 000000000000..21dc66cd1853 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/heavisidef/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/math/base/special/heavisidef", + "version": "0.0.0", + "description": "Evaluate the Heaviside function for a single-precision floating-point number.", + "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", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "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", + "heavisidef", + "discontinuous", + "unit step function", + "step function", + "distribution", + "dist", + "ramp", + "digital signal processing", + "dsp" + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/heavisidef/test/test.js b/lib/node_modules/@stdlib/math/base/special/heavisidef/test/test.js new file mode 100644 index 000000000000..0f8e15510704 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/heavisidef/test/test.js @@ -0,0 +1,131 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var randu = require( '@stdlib/random/base/randu' ); +var heavisidef = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof heavisidef, '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 < 1e3; i++ ) { + x = -( randu()*100.0 ) - EPS; + v = heavisidef( x ); + t.equal( isPositiveZerof( 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 < 1e3; i++ ) { + x = ( randu()*100.0 ) + EPS; + v = heavisidef( x ); + t.equal( v, 1.0, 'returns expected value when provided '+x ); + } + t.end(); +}); + +tape( 'by default, the function returns `NaN` if provided `+-0`', function test( t ) { + var v; + + v = heavisidef( -0.0 ); + t.equal( isnanf( v ), true, 'returns expected value' ); + + v = heavisidef( +0.0 ); + t.equal( isnanf( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if the `continuity` option is `half-maximum`, the function returns `0.5` if provided `+-0`', function test( t ) { + var v; + + v = heavisidef( -0.0, 'half-maximum' ); + t.equal( v, 0.5, 'returns expected value' ); + + v = heavisidef( +0.0, 'half-maximum' ); + t.equal( v, 0.5, 'returns expected value' ); + + t.end(); +}); + +tape( 'if the `continuity` option is `left-continuous`, the function returns `0.0` if provided `+-0`', function test( t ) { + var v; + + v = heavisidef( -0.0, 'left-continuous' ); + t.equal( isPositiveZerof( v ), true, 'returns expected value' ); + + v = heavisidef( +0.0, 'left-continuous' ); + t.equal( isPositiveZerof( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if the `continuity` option is `right-continuous`, the function returns `1` if provided `+-0`', function test( t ) { + var v; + + v = heavisidef( -0.0, 'right-continuous' ); + t.equal( v, 1.0, 'returns expected value' ); + + v = heavisidef( +0.0, 'right-continuous' ); + t.equal( v, 1.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `NaN` if provided `NaN`', function test( t ) { + var v = heavisidef( NaN ); + t.equal( isnanf( v ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `0` if provided `-infinity`', function test( t ) { + var v = heavisidef( NINF ); + t.equal( v, 0.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `+1` if provided `+infinity`', function test( t ) { + var v = heavisidef( PINF ); + t.equal( v, 1.0, 'returns expected value' ); + t.end(); +});