diff --git a/lib/node_modules/@stdlib/number/int32/base/signbit/README.md b/lib/node_modules/@stdlib/number/int32/base/signbit/README.md new file mode 100644 index 000000000000..0a93403a34cf --- /dev/null +++ b/lib/node_modules/@stdlib/number/int32/base/signbit/README.md @@ -0,0 +1,91 @@ + + +# signbit + +> Return a boolean indicating if the sign bit for a signed 32-bit integer is on (true) or off (false). + +
+ +## Usage + +```javascript +var signbit = require( '@stdlib/number/int32/base/signbit' ); +``` + +#### signbit( x ) + +Returns a boolean indicating if the sign bit for a signed 32-bit integer is on (`true`) or off (`false`). + +```javascript +var bool = signbit( 4 ); +// returns false + +bool = signbit( -4 ); +// returns true + +bool = signbit( 0 ); +// returns false +``` + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var signbit = require( '@stdlib/number/int32/base/signbit' ); + +var x = discreteUniform( 100, -50, 50, { + 'dtype': 'generic' +}); +logEachMap( 'x: %d. signbit: %s.', x, signbit ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/number/int32/base/signbit/benchmark/benchmark.js b/lib/node_modules/@stdlib/number/int32/base/signbit/benchmark/benchmark.js new file mode 100644 index 000000000000..923142c70b8d --- /dev/null +++ b/lib/node_modules/@stdlib/number/int32/base/signbit/benchmark/benchmark.js @@ -0,0 +1,54 @@ +/** +* @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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var signbit = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var x; + var y; + var i; + + x = discreteUniform( 100, -100, 100, { + 'dtype': 'generic' + }); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = signbit( x[ i%x.length ] ); + if ( typeof y !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( y ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/number/int32/base/signbit/docs/repl.txt b/lib/node_modules/@stdlib/number/int32/base/signbit/docs/repl.txt new file mode 100644 index 000000000000..aac90c871aec --- /dev/null +++ b/lib/node_modules/@stdlib/number/int32/base/signbit/docs/repl.txt @@ -0,0 +1,26 @@ + +{{alias}}( x ) + Returns a boolean indicating if the sign bit is on (true) or off (false). + + Parameters + ---------- + x: integer + Signed 32-bit integer. + + Returns + ------- + bool: boolean + Boolean indicating if sign bit is on or off. + + Examples + -------- + > var bool = {{alias}}( 4 ) + false + > bool = {{alias}}( -4 ) + true + > bool = {{alias}}( 0 ) + false + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/number/int32/base/signbit/docs/types/index.d.ts b/lib/node_modules/@stdlib/number/int32/base/signbit/docs/types/index.d.ts new file mode 100644 index 000000000000..da2d79f2b51f --- /dev/null +++ b/lib/node_modules/@stdlib/number/int32/base/signbit/docs/types/index.d.ts @@ -0,0 +1,44 @@ +/* +* @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 + +/** +* Returns a boolean indicating if the sign bit is on (true) or off (false). +* +* @param x - input value +* @returns boolean indicating if sign bit is on or off +* +* @example +* var bool = signbit( 4 ); +* // returns false +* +* @example +* var bool = signbit( -4 ); +* // returns true +* +* @example +* var bool = signbit( 0 ); +* // returns false +*/ +declare function signbit( x: number ): boolean; + + +// EXPORTS // + +export = signbit; diff --git a/lib/node_modules/@stdlib/number/int32/base/signbit/docs/types/test.ts b/lib/node_modules/@stdlib/number/int32/base/signbit/docs/types/test.ts new file mode 100644 index 000000000000..89de07d40692 --- /dev/null +++ b/lib/node_modules/@stdlib/number/int32/base/signbit/docs/types/test.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. +*/ + +import signbit = require( './index' ); + + +// TESTS // + +// The function returns a boolean... +{ + signbit( 1 ); // $ExpectType boolean + signbit( -1 ); // $ExpectType boolean +} + +// The compiler throws an error if the function is provided a value other than a number... +{ + signbit( true ); // $ExpectError + signbit( false ); // $ExpectError + signbit( 'abc' ); // $ExpectError + signbit( [] ); // $ExpectError + signbit( {} ); // $ExpectError + signbit( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + signbit(); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/number/int32/base/signbit/examples/index.js b/lib/node_modules/@stdlib/number/int32/base/signbit/examples/index.js new file mode 100644 index 000000000000..c12a2564e8fb --- /dev/null +++ b/lib/node_modules/@stdlib/number/int32/base/signbit/examples/index.js @@ -0,0 +1,28 @@ +/** +* @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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var signbit = require( './../lib' ); + +var x = discreteUniform( 100, -50, 50, { + 'dtype': 'generic' +}); +logEachMap( 'x: %d. signbit: %s.', x, signbit ); diff --git a/lib/node_modules/@stdlib/number/int32/base/signbit/lib/index.js b/lib/node_modules/@stdlib/number/int32/base/signbit/lib/index.js new file mode 100644 index 000000000000..e1493a498648 --- /dev/null +++ b/lib/node_modules/@stdlib/number/int32/base/signbit/lib/index.js @@ -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. +*/ + +'use strict'; + +/** +* Return a boolean indicating if the sign bit is on (true) or off (false). +* +* @module @stdlib/number/int32/base/signbit +* +* @example +* var signbit = require( '@stdlib/number/int32/base/signbit' ); +* +* var bool = signbit( 4 ); +* // returns false +* +* var bool = signbit( -4 ); +* // returns true +* +* var bool = signbit( 0 ); +* // returns false +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/number/int32/base/signbit/lib/main.js b/lib/node_modules/@stdlib/number/int32/base/signbit/lib/main.js new file mode 100644 index 000000000000..19c870ddb276 --- /dev/null +++ b/lib/node_modules/@stdlib/number/int32/base/signbit/lib/main.js @@ -0,0 +1,49 @@ +/** +* @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 a boolean indicating if the sign bit is on (true) or off (false). +* +* @param {integer32} x - signed 32-bit integer +* @returns {boolean} boolean indicating if sign bit is on or off +* +* @example +* var bool = signbit( 4 ); +* // returns false +* +* @example +* var bool = signbit( -4 ); +* // returns true +* +* @example +* var bool = signbit( 0 ); +* // returns false +*/ +function signbit( x ) { + // Shift off all bits which are not the sign bit and check if the sign bit is on: + return ( x >>> 31 ) ? true : false; // eslint-disable-line no-unneeded-ternary +} + + +// EXPORTS // + +module.exports = signbit; diff --git a/lib/node_modules/@stdlib/number/int32/base/signbit/package.json b/lib/node_modules/@stdlib/number/int32/base/signbit/package.json new file mode 100644 index 000000000000..1133a4a01743 --- /dev/null +++ b/lib/node_modules/@stdlib/number/int32/base/signbit/package.json @@ -0,0 +1,70 @@ +{ + "name": "@stdlib/number/int32/base/signbit", + "version": "0.0.0", + "description": "Return a boolean indicating if the sign bit for a double-precision floating-point number is on (true) or off (false).", + "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/index.js", + "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", + "stdtypes", + "base", + "utilities", + "utility", + "utils", + "util", + "types", + "type", + "signbit", + "sign", + "bit", + "int32", + "signed", + "integer", + "int", + "32-bit" + ] +} diff --git a/lib/node_modules/@stdlib/number/int32/base/signbit/test/test.js b/lib/node_modules/@stdlib/number/int32/base/signbit/test/test.js new file mode 100644 index 000000000000..1d726b1376ac --- /dev/null +++ b/lib/node_modules/@stdlib/number/int32/base/signbit/test/test.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'; + +// MODULES // + +var tape = require( 'tape' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var MAX_INT32 = require( '@stdlib/constants/int32/max' ); +var signbit = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof signbit, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a boolean', function test( t ) { + t.strictEqual( typeof signbit( 5 ), 'boolean', 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a boolean indicating if a sign bit is on (true) or off (false)', function test( t ) { + var x; + var i; + + x = discreteUniform( 1e3, -MAX_INT32, MAX_INT32, { + 'dtype': 'generic' + }); + for ( i = 0; i < x.length; i++ ) { + t.strictEqual( signbit( x[ i ] ), x[ i ] < 0, 'returns expected value for '+x[ i ] ); + } + t.end(); +});