Skip to content
Open
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
160 changes: 160 additions & 0 deletions lib/node_modules/@stdlib/number/uint64/base/right-shift/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<!--

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

-->

# rightShift

> Perform bitwise shift to the right on a 64-bit unsigned integer.

<section class="intro">

</section>

<!-- /.intro -->

<section class="usage">

## Usage

```javascript
var rightShift = require( '@stdlib/number/uint64/base/right-shift' );
```

#### rightShift( a, shift )

Performs bitwise shift to the right on a 64-bit unsigned integer.

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

var a = new Uint64( 10 );

var v = rightShift( a, 1 );
// returns <Uint64>[ 5n ]
```

#### rightShift.assign( ah, al, shift, out, stride, offset )

Performs bitwise shift to the right on a 64-bit unsigned integer and assigns results to a provided output array.

```javascript
var Uint32Array = require( '@stdlib/array/uint32' );

var out = new Uint32Array( 2 );
var v = rightShift.assign( 2, 4, 1, out, 1, 0 );
// returns <Uint32Array>[ 1, 2 ]

var bool = ( out === v );
// returns true
```

The function supports the following parameters:

- **ah**: high 32-bit word of the 64-bit unsigned integer.
- **al**: low 32-bit word of the 64-bit unsigned integer.
- **shift**: number of bits to shift (0-63).
- **out**: output array.
- **stride**: stride length for `out`.
- **offset**: starting index for `out`.

#### rightShift.strided( a, sa, oa, shift, out, so, oo )

Performs bitwise shift to the right on a 64-bit unsigned integer stored in integer-valued strided array views and assigns results to a provided strided output array.

```javascript
var Uint32Array = require( '@stdlib/array/uint32' );

var a = new Uint32Array( [ 2, 4 ] );
var out = new Uint32Array( 2 );

var v = rightShift.strided( a, 1, 0, 1, out, 1, 0 );
// returns <Uint32Array>[ 1, 2 ]

var bool = ( out === v );
// returns true
```

The function supports the following parameters:

- **a**: 64-bit unsigned integer strided array view containing interleaved 32-bit unsigned integer high and low order words.
- **sa**: stride length for `a`.
- **oa**: starting index for `a`.
- **shift**: number of bits to shift (0-63).
- **out**: output array.
- **so**: stride length for `out`.
- **oo**: starting index for `out`.

</section>

<!-- /.usage -->

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

## Notes

- If provided a shift value less than `0` or greater than `63`, only the `6` least significant bits are used.

</section>

<!-- /.notes -->

<section class="examples">

## Examples

```javascript
var zeroTo = require( '@stdlib/array/zero-to' );
var logEachMap = require( '@stdlib/console/log-each-map' );
var Uint64 = require( '@stdlib/number/uint64/ctor' );
var rightShift = require( '@stdlib/number/uint64/base/right-shift' );

var a = Uint64.of( 0xdeadbeef, 0x0badf00d );
// returns <Uint64>

var shifts = zeroTo( 64, 'uint32' );
// returns <Uint32Array>

logEachMap( 'rightShift(%x, %s) = %b', a, shifts, rightShift );
```

</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,137 @@
/**
* @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 Uint32Array = require( '@stdlib/array/uint32' );
var zeroTo = require( '@stdlib/array/zero-to' );
var bench = require( '@stdlib/bench' );
var UINT32_MAX = require( '@stdlib/constants/uint32/max' );
var Uint64 = require( '@stdlib/number/uint64/ctor' );
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var rightShift = require( './../lib' );


// VARIABLES //

var options = {
'dtype': 'uint32'
};


// MAIN //

bench( pkg, function benchmark( b ) {
var shifts;
var values;
var out;
var N;
var M;
var x;
var i;

N = 100;
x = discreteUniform( N, 0, UINT32_MAX, options );
values = [];
for ( i = 0; i < N; i++ ) {
values.push( Uint64.of( x[ i ], x[ (i+1)%N ] ) );
}

shifts = zeroTo( 64, 'uint32' );
M = shifts.length;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = rightShift( values[ i%N ], shifts[ i%M ] );
if ( typeof out !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( !( out instanceof Uint64 ) ) {
b.fail( 'should return a Uint64 instance' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( format( '%s:assign', pkg ), function benchmark( b ) {
var shifts;
var out;
var N;
var M;
var x;
var i;

N = 100;
x = discreteUniform( N, 0, UINT32_MAX, options );
shifts = zeroTo( 64, 'uint32' );
M = shifts.length;

out = new Uint32Array( 2 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = rightShift.assign( x[ i%N ], x[ (i+1)%N ], shifts[ i%M ], out, 1, 0 ); // eslint-disable-line max-len
if ( typeof out !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( !( out instanceof Uint32Array ) ) {
b.fail( 'should return a Uint32Array' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( format( '%s:strided', pkg ), function benchmark( b ) {
var shifts;
var out;
var N;
var M;
var x;
var i;
var j;

N = 50;
x = discreteUniform( N*2, 0, UINT32_MAX, options );
shifts = zeroTo( 64, 'uint32' );
M = shifts.length;

out = new Uint32Array( 2 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
j = ( i % N ) * 2;
out = rightShift.strided( x, 1, j, shifts[ i%M ], out, 1, 0 );
if ( typeof out !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( !( out instanceof Uint32Array ) ) {
b.fail( 'should return a Uint32Array' );
}
b.pass( 'benchmark finished' );
b.end();
});
Loading