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
118 changes: 118 additions & 0 deletions lib/node_modules/@stdlib/number/int64/base/get-high-word/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<!--

@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 a 32-bit unsigned integer corresponding to the high 32-bit word of a [64-bit signed integer][@stdlib/number/int64/ctor].

<section class="usage">

## Usage

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

#### getHighWord( x )

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

```javascript
var Int64 = require( '@stdlib/number/int64/ctor' );

var x = new Int64( 4294967296 );
var w = getHighWord( x );
// returns 1
```

For negative values, the function returns the high word of the two's complement representation.

```javascript
var Int64 = require( '@stdlib/number/int64/ctor' );

var x = new Int64( -1 );
var w = getHighWord( x );
// returns 4294967295
```

</section>

<!-- /.usage -->

<section class="examples">

## Examples

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

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

var x = new Int64( 4294967296 );
console.log( getHighWord( x ) );
// => 1

x = new Int64( 0xffffffff );
console.log( getHighWord( x ) );
// => 0

x = new Int64( 0x123400005678 );
console.log( getHighWord( x ) );
// => 4660

x = new Int64( -1 );
console.log( getHighWord( x ) );
// => 4294967295

x = new Int64( -1000000000000 );
console.log( getHighWord( x ) );
// => 4294967063

x = Int64.of( 1234, 5678 );
console.log( getHighWord( x ) );
// => 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/int64/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/number/int64/ctor

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

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

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* @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 MIN_SAFE_INTEGER = require( '@stdlib/constants/float64/min-safe-integer' );
var Int64 = require( '@stdlib/number/int64/ctor' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var pkg = require( './../package.json' ).name;
var getHighWord = require( './../lib' );


// VARIABLES //

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


// MAIN //

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

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = values[ i % N ];
w = getHighWord( x );
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,29 @@

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

Parameters
----------
x: Int64
Input value.

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

Examples
--------
> var x = new {{alias:@stdlib/number/int64/ctor}}( 4294967296 )
<Int64>[ 4294967296n ]
> var w = {{alias}}( x )
1
> x = new {{alias:@stdlib/number/int64/ctor}}( -1 )
<Int64>[ -1n ]
> w = {{alias}}( x )
4294967295

See Also
--------

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* @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 { Int64 } from '@stdlib/types/number';

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


// TESTS //

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

// The compiler throws an error if the function is provided an argument that is not a 64-bit signed 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 x = new Int64( 5 );
getHighWord(); // $ExpectError
getHighWord( x, x ); // $ExpectError
}
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';

var Int64 = require( '@stdlib/number/int64/ctor' );
var getHighWord = require( './../lib' );

var x = new Int64( 4294967296 );
console.log( getHighWord( x ) );
// => 1

x = new Int64( 0xffffffff );
console.log( getHighWord( x ) );
// => 0

x = new Int64( 0x123400005678 );
console.log( getHighWord( x ) );
// => 4660

x = new Int64( -1 );
console.log( getHighWord( x ) );
// => 4294967295

x = new Int64( -1000000000000 );
console.log( getHighWord( x ) );
// => 4294967063

x = Int64.of( 1234, 5678 );
console.log( getHighWord( x ) );
// => 1234
Loading