Skip to content
91 changes: 91 additions & 0 deletions lib/node_modules/@stdlib/number/int32/base/signbit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<!--

@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.

-->

# signbit

> Return a boolean indicating if the sign bit for a signed 32-bit integer is on (true) or off (false).

<section class="usage">

## 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
```

</section>

<!-- /.usage -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```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 );
```

</section>

<!-- /.examples -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

<!-- <related-links> -->

<!-- </related-links> -->

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -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();
});
26 changes: 26 additions & 0 deletions lib/node_modules/@stdlib/number/int32/base/signbit/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -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
--------

Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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 );
46 changes: 46 additions & 0 deletions lib/node_modules/@stdlib/number/int32/base/signbit/lib/index.js
Original file line number Diff line number Diff line change
@@ -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;
49 changes: 49 additions & 0 deletions lib/node_modules/@stdlib/number/int32/base/signbit/lib/main.js
Original file line number Diff line number Diff line change
@@ -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;
Loading
Loading