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

-->

# High Word

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

<section class="usage">

## Usage

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

#### getHighWord( x )

Returns an unsigned 32-bit `integer` corresponding to the high 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 = getHighWord( a );
// returns 1
```

</section>

<!-- /.usage -->

<section class="examples">

## Examples

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

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

var a = new Uint64( 4294967296 );
console.log( getHighWord( a ) );
// => 1

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

a = new Uint64( 0x123400005678 );
console.log( getHighWord( a ) );
// => 4660

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

</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 getHighWord = 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 = getHighWord( 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}}( x )
Returns an unsigned 32-bit integer corresponding to the high 32-bit word of
a 64-bit unsigned integer.

Parameters
----------
x: Uint64
Input value.

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

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

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 an unsigned 32-bit integer corresponding to the high 32-bit word of a 64-bit unsigned integer.
*
* @param a - input value
* @returns higher order word (unsigned 32-bit integer)
*
* @example
* var Uint64 = require( '@stdlib/number/uint64/ctor' );
*
* var a = new Uint64( 4294967296 );
* var w = getHighWord( a );
* // returns 1
*/
declare function getHighWord( a: Uint64 ): number;


// EXPORTS //

export = getHighWord;
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 getHighWord = require( './index' );


// TESTS //

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

// The compiler throws an error if the function is provided an argument that is not a 64-bit unsigned integer...
{
getHighWord( 5 ); // $ExpectError
getHighWord( '5' ); // $ExpectError
getHighWord( true ); // $ExpectError
getHighWord( false ); // $ExpectError
getHighWord( [] ); // $ExpectError
getHighWord( {} ); // $ExpectError
getHighWord( ( 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 );
getHighWord(); // $ExpectError
getHighWord( 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 getHighWord = require( './../lib' );

var a = new Uint64( 4294967296 );
console.log( getHighWord( a ) );
// => 1

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

a = new Uint64( 0x123400005678 );
console.log( getHighWord( a ) );
// => 4660

a = new Uint64.of( 1234, 5678 );
console.log( getHighWord( a ) );
// => 1234
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 an unsigned 32-bit integer corresponding to the high 32-bit word of a 64-bit unsigned integer.
*
* @module @stdlib/number/uint64/base/get-high-word
*
* @example
* var Uint64 = require( '@stdlib/number/uint64/ctor' );
* var getHighWord = require( '@stdlib/number/uint64/base/get-high-word' );
*
* var a = new Uint64( 4294967296 );
* var w = getHighWord( a );
* // returns 1
*/

// MODULES //

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


// EXPORTS //

module.exports = main;
Loading