Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions lib/node_modules/@stdlib/number/uint64/base/get-low-word/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<!--

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

-->

# Low Word

> Return a 32-bit unsigned integer corresponding to the low 32-bit word of a [64-bit unsigned integer][@stdlib/number/uint64/ctor].

<section class="usage">

## Usage

```javascript
var getLowWord = require( '@stdlib/number/uint64/base/get-low-word' );
```

#### getLowWord( a )

Returns a 32-bit unsigned integer corresponding to the low 32-bit word of a [64-bit unsigned integer][@stdlib/number/uint64/ctor].

```javascript
var Uint64 = require( '@stdlib/number/uint64/ctor' );

var a = new Uint64( 4294967296 );
var w = getLowWord( a );
// returns 0
```

</section>

<!-- /.usage -->

<section class="examples">

## Examples

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

```javascript
var Uint64 = require( '@stdlib/number/uint64/ctor' );
var getLowWord = require( '@stdlib/number/uint64/base/get-low-word' );

var a = new Uint64( 4294967296 );
console.log( getLowWord( a ) );
// => 0

a = new Uint64( 0xffffffff );
console.log( getLowWord( a ) );
// => 4294967295

a = new Uint64( 0x123400005678 );
console.log( getLowWord( a ) );
// => 22136

a = Uint64.of( 1234, 5678 );
console.log( getLowWord( a ) );
// => 5678
```

</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">

[@stdlib/number/uint64/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/number/uint64/ctor

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

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

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* @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 isnan = require( '@stdlib/assert/is-nan' ).isPrimitive;
var bench = require( '@stdlib/bench' );
var MAX_SAFE_INTEGER = require( '@stdlib/constants/float64/max-safe-integer' );
var Uint64 = require( '@stdlib/number/uint64/ctor' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var pkg = require( './../package.json' ).name;
var getLowWord = require( './../lib' );


// VARIABLES //

var rand = discreteUniform.factory( 0, MAX_SAFE_INTEGER );


// MAIN //

bench( pkg, function benchmark( b ) {
var values;
var N;
var a;
var i;
var w;

N = 100;
values = [];
for ( i = 0; i < N; i++ ) {
values.push( new Uint64( rand() ) );
}

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
a = values[ i % N ];
w = getLowWord( a );
if ( isnan( w ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( w ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

{{alias}}( a )
Returns a 32-bit unsigned integer corresponding to the low 32-bit word of a
64-bit unsigned integer.

Parameters
----------
a: Uint64
Input value.

Returns
-------
out: integer
Lower order word (32-bit unsigned integer).

Examples
--------
> var a = new {{alias:@stdlib/number/uint64/ctor}}( 4294967296 )
<Uint64>[ 4294967296n ]
> var w = {{alias}}( a )
0

See Also
--------

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.
*/

// TypeScript Version: 4.1

/// <reference types="@stdlib/types"/>

import { Uint64 } from '@stdlib/types/number';

/**
* Returns a 32-bit unsigned integer corresponding to the low 32-bit word of a 64-bit unsigned integer.
*
* @param a - input value
* @returns lower order word (32-bit unsigned integer)
*
* @example
* var Uint64 = require( '@stdlib/number/uint64/ctor' );
*
* var a = new Uint64( 4294967296 );
* var w = getLowWord( a );
* // returns 0
*/
declare function getLowWord( a: Uint64 ): number;


// EXPORTS //

export = getLowWord;
Original file line number Diff line number Diff line change
@@ -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.
*/

import Uint64 = require( '@stdlib/number/uint64/ctor' );
import getLowWord = require( './index' );


// TESTS //

// The function returns a number...
{
const a = new Uint64( 5 );
getLowWord( a ); // $ExpectType number
}

// The compiler throws an error if the function is provided an argument that is not a 64-bit unsigned integer...
{
getLowWord( 5 ); // $ExpectError
getLowWord( '5' ); // $ExpectError
getLowWord( true ); // $ExpectError
getLowWord( false ); // $ExpectError
getLowWord( [] ); // $ExpectError
getLowWord( {} ); // $ExpectError
getLowWord( ( x: number ): number => x ); // $ExpectError
}

// The compiler throws an error if the function is provided an unsupported number of arguments...
{
const a = new Uint64( 5 );
getLowWord(); // $ExpectError
getLowWord( a, a ); // $ExpectError
}
Original file line number Diff line number Diff line change
@@ -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 Uint64 = require( '@stdlib/number/uint64/ctor' );
var getLowWord = require( './../lib' );

var a = new Uint64( 4294967296 );
console.log( getLowWord( a ) );
// => 0

a = new Uint64( 0xffffffff );
console.log( getLowWord( a ) );
// => 4294967295

a = new Uint64( 0x123400005678 );
console.log( getLowWord( a ) );
// => 22136

a = Uint64.of( 1234, 5678 );
console.log( getLowWord( a ) );
// => 5678
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @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 32-bit unsigned integer corresponding to the low 32-bit word of a 64-bit unsigned integer.
*
* @module @stdlib/number/uint64/base/get-low-word
*
* @example
* var Uint64 = require( '@stdlib/number/uint64/ctor' );
* var getLowWord = require( '@stdlib/number/uint64/base/get-low-word' );
*
* var a = new Uint64( 4294967296 );
* var w = getLowWord( a );
* // returns 0
*/

// MODULES //

var main = require( './main.js' );


// EXPORTS //

module.exports = main;
Loading
Loading