diff --git a/lib/node_modules/@stdlib/number/uint64/base/right-shift/README.md b/lib/node_modules/@stdlib/number/uint64/base/right-shift/README.md new file mode 100644 index 000000000000..5e43271b47d3 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/right-shift/README.md @@ -0,0 +1,160 @@ + + +# rightShift + +> Perform bitwise shift to the right on a 64-bit unsigned integer. + +
+ +
+ + + +
+ +## 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 [ 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 [ 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 [ 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`. + +
+ + + + + +
+ +## Notes + +- If provided a shift value less than `0` or greater than `63`, only the `6` least significant bits are used. + +
+ + + +
+ +## 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 + +var shifts = zeroTo( 64, 'uint32' ); +// returns + +logEachMap( 'rightShift(%x, %s) = %b', a, shifts, rightShift ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/number/uint64/base/right-shift/benchmark/benchmark.js b/lib/node_modules/@stdlib/number/uint64/base/right-shift/benchmark/benchmark.js new file mode 100644 index 000000000000..5d16d9850e91 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/right-shift/benchmark/benchmark.js @@ -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(); +}); diff --git a/lib/node_modules/@stdlib/number/uint64/base/right-shift/docs/repl.txt b/lib/node_modules/@stdlib/number/uint64/base/right-shift/docs/repl.txt new file mode 100644 index 000000000000..fd12246ba42b --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/right-shift/docs/repl.txt @@ -0,0 +1,105 @@ + +{{alias}}( a, shift ) + Performs bitwise shift to the right on a 64-bit unsigned integer. + + Parameters + ---------- + a: Uint64 + 64-bit unsigned integer. + + shift: integer + Number of bits to shift (0-63). + + Returns + ------- + out: Uint64 + Result. + + Examples + -------- + > var a = new {{alias:@stdlib/number/uint64/ctor}}( 10 ) + [ 10n ] + > var out = {{alias}}( a, 1 ) + [ 5n ] + + +{{alias}}.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. + + Parameters + ---------- + ah: integer + High 32-bit word of the 64-bit unsigned integer. + + al: integer + Low 32-bit word of the 64-bit unsigned integer. + + shift: integer + Number of bits to shift (0-63). + + out: ArrayLikeObject + Output array. + + stride: integer + Stride length. + + offset: integer + Starting index. + + Returns + ------- + out: ArrayLikeObject + Output array. + + Examples + -------- + > var out = new {{alias:@stdlib/array/uint32}}( 2 ); + > {{alias}}.assign( 2, 4, 1, out, 1, 0 ) + [ 1, 2 ] + + +{{alias}}.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. + + Parameters + ---------- + a: ArrayLikeObject + 64-bit unsigned integer strided array view containing interleaved 32-bit + unsigned integer high and low order words. + + sa: integer + Stride length for `a`. + + oa: integer + Starting index for `a`. + + shift: integer + Number of bits to shift (0-63). + + out: ArrayLikeObject + Output array. + + so: integer + Stride length for `out`. + + oo: integer + Starting index for `out`. + + Returns + ------- + out: ArrayLikeObject + Output array. + + Examples + -------- + > var a = new {{alias:@stdlib/array/uint32}}( [ 2, 4 ] ); + > var out = new {{alias:@stdlib/array/uint32}}( 2 ); + > {{alias}}.strided( a, 1, 0, 1, out, 1, 0 ) + [ 1, 2 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/number/uint64/base/right-shift/docs/types/index.d.ts b/lib/node_modules/@stdlib/number/uint64/base/right-shift/docs/types/index.d.ts new file mode 100644 index 000000000000..8c882126e243 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/right-shift/docs/types/index.d.ts @@ -0,0 +1,123 @@ +/* +* @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 + +/// + +import { Uint64 } from '@stdlib/types/number'; +import { Collection, NumericArray } from '@stdlib/types/array'; + +/** +* Interface for computing the bitwise XOR of two 64-bit unsigned integers. +*/ +interface RightShift { + /** + * Performs bitwise shift to the right on a 64-bit unsigned integer. + * + * @param a - 64-bit unsigned integer + * @param shift - number of bits to shift (0-63) + * @returns result + * + * @example + * var Uint64 = require( '@stdlib/number/uint64/ctor' ); + * + * var a = new Uint64( 10 ); + * + * var v = rightShift( a, 1 ); + * // returns [ 5n ] + */ + ( a: Uint64, shift: number ): Uint64; + + /** + * Performs bitwise shift to the right on a 64-bit unsigned integer and assigns results to a provided output array. + * + * @param ah - high 32-bit word of the 64-bit unsigned integer + * @param al - low 32-bit word of the 64-bit unsigned integer + * @param shift - number of bits to shift (0-63) + * @param out - output array + * @param stride - stride length + * @param offset - starting index + * @returns output array + * + * @example + * var Uint32Array = require( '@stdlib/array/uint32' ); + * + * var out = rightShift.assign( 2, 4, 1, new Uint32Array( 2 ), 1, 0 ); + * // returns [ 1, 2 ] + */ + assign>( ah: number, al: number, shift: number, out: T, stride: number, offset: number ): T; + + /** + * 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. + * + * @param a - 64-bit unsigned integer strided array view containing interleaved 32-bit unsigned integer high and low order words + * @param sa - stride length for `a` + * @param oa - starting index for `a` + * @param shift - number of bits to shift (0-63) + * @param out - output array + * @param so - stride length for `out` + * @param oo - starting index for `out` + * @returns output array + * + * @example + * var Uint32Array = require( '@stdlib/array/uint32' ); + * + * var a = new Uint32Array( [ 2, 4 ] ); + * + * var out = rightShift.strided( a, 1, 0, 1, new Uint32Array( 2 ), 1, 0 ); + * // returns [ 1, 2 ] + */ + strided, U extends NumericArray | Collection>( a: T, sa: number, oa: number, shift: number, out: U, so: number, oo: number ): U; +} + +/** +* Performs bitwise shift to the right on a 64-bit unsigned integer. +* +* @param a - 64-bit unsigned integer +* @param shift - number of bits to shift (0-63) +* @returns result +* +* @example +* var Uint64 = require( '@stdlib/number/uint64/ctor' ); +* +* var a = new Uint64( 10 ); +* +* var v = rightShift( a, 1 ); +* // returns [ 5n ] +* +* @example +* var Uint32Array = require( '@stdlib/array/uint32' ); +* +* var out = rightShift.assign( 2, 4, 1, new Uint32Array( 2 ), 1, 0 ); +* // returns [ 1, 2 ] +* +* @example +* var Uint32Array = require( '@stdlib/array/uint32' ); +* +* var a = new Uint32Array( [ 2, 4 ] ); +* +* var out = rightShift.strided( a, 1, 0, 1, new Uint32Array( 2 ), 1, 0 ); +* // returns [ 1, 2 ] +*/ +declare var rightShift: RightShift; + + +// EXPORTS // + +export = rightShift; diff --git a/lib/node_modules/@stdlib/number/uint64/base/right-shift/docs/types/test.ts b/lib/node_modules/@stdlib/number/uint64/base/right-shift/docs/types/test.ts new file mode 100644 index 000000000000..c8ed1471eb7f --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/right-shift/docs/types/test.ts @@ -0,0 +1,297 @@ +/* +* @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 rightShift = require( './index' ); + + +// TESTS // + +// The function returns a 64-bit unsigned integer... +{ + const a = new Uint64( 5 ); + + rightShift( a, 1 ); // $ExpectType Uint64 +} + +// The compiler throws an error if the function is provided a first argument which is not a 64-bit unsigned integer... +{ + rightShift( true, 1 ); // $ExpectError + rightShift( false, 1 ); // $ExpectError + rightShift( null, 1 ); // $ExpectError + rightShift( undefined, 1 ); // $ExpectError + rightShift( '5', 1 ); // $ExpectError + rightShift( [], 1 ); // $ExpectError + rightShift( {}, 1 ); // $ExpectError + rightShift( ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const a = new Uint64( 5 ); + + rightShift( a, true ); // $ExpectError + rightShift( a, false ); // $ExpectError + rightShift( a, null ); // $ExpectError + rightShift( a, undefined ); // $ExpectError + rightShift( a, '5' ); // $ExpectError + rightShift( a, [] ); // $ExpectError + rightShift( a, {} ); // $ExpectError + rightShift( a, ( 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 ); + + rightShift(); // $ExpectError + rightShift( a ); // $ExpectError + rightShift( a, 1, 2 ); // $ExpectError +} + +// Attached to the main export is an `assign` method which returns a collection... +{ + rightShift.assign( 1, 2, 3, new Uint32Array( 2 ), 1, 0 ); // $ExpectType Uint32Array + rightShift.assign( 1, 2, 3, new Float64Array( 2 ), 1, 0 ); // $ExpectType Float64Array + rightShift.assign( 1, 2, 3, [ 0, 0 ], 1, 0 ); // $ExpectType number[] +} + +// The compiler throws an error if the `assign` method is provided a first argument which is not a number... +{ + const out = new Uint32Array( 2 ); + + rightShift.assign( true, 2, 3, out, 1, 0 ); // $ExpectError + rightShift.assign( false, 2, 3, out, 1, 0 ); // $ExpectError + rightShift.assign( null, 2, 3, out, 1, 0 ); // $ExpectError + rightShift.assign( undefined, 2, 3, out, 1, 0 ); // $ExpectError + rightShift.assign( '5', 2, 3, out, 1, 0 ); // $ExpectError + rightShift.assign( [], 2, 3, out, 1, 0 ); // $ExpectError + rightShift.assign( {}, 2, 3, out, 1, 0 ); // $ExpectError + rightShift.assign( ( x: number ): number => x, 2, 3, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a second argument which is not a number... +{ + const out = new Uint32Array( 2 ); + + rightShift.assign( 1, true, 3, out, 1, 0 ); // $ExpectError + rightShift.assign( 1, false, 3, out, 1, 0 ); // $ExpectError + rightShift.assign( 1, null, 3, out, 1, 0 ); // $ExpectError + rightShift.assign( 1, undefined, 3, out, 1, 0 ); // $ExpectError + rightShift.assign( 1, '5', 3, out, 1, 0 ); // $ExpectError + rightShift.assign( 1, [], 3, out, 1, 0 ); // $ExpectError + rightShift.assign( 1, {}, 3, out, 1, 0 ); // $ExpectError + rightShift.assign( 1, ( x: number ): number => x, 3, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a third argument which is not a number... +{ + const out = new Uint32Array( 2 ); + + rightShift.assign( 1, 2, true, out, 1, 0 ); // $ExpectError + rightShift.assign( 1, 2, false, out, 1, 0 ); // $ExpectError + rightShift.assign( 1, 2, null, out, 1, 0 ); // $ExpectError + rightShift.assign( 1, 2, undefined, out, 1, 0 ); // $ExpectError + rightShift.assign( 1, 2, '5', out, 1, 0 ); // $ExpectError + rightShift.assign( 1, 2, [], out, 1, 0 ); // $ExpectError + rightShift.assign( 1, 2, {}, out, 1, 0 ); // $ExpectError + rightShift.assign( 1, 2, ( x: number ): number => x, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fourth argument which is not a collection... +{ + rightShift.assign( 1, 2, 3, 1, 1, 0 ); // $ExpectError + rightShift.assign( 1, 2, 3, true, 1, 0 ); // $ExpectError + rightShift.assign( 1, 2, 3, false, 1, 0 ); // $ExpectError + rightShift.assign( 1, 2, 3, null, 1, 0 ); // $ExpectError + rightShift.assign( 1, 2, 3, undefined, 1, 0 ); // $ExpectError + rightShift.assign( 1, 2, 3, '5', 1, 0 ); // $ExpectError + rightShift.assign( 1, 2, 3, [ '5' ], 1, 0 ); // $ExpectError + rightShift.assign( 1, 2, 3, {}, 1, 0 ); // $ExpectError + rightShift.assign( 1, 2, 3, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... +{ + const out = new Uint32Array( 2 ); + + rightShift.assign( 1, 2, 3, out, true, 0 ); // $ExpectError + rightShift.assign( 1, 2, 3, out, false, 0 ); // $ExpectError + rightShift.assign( 1, 2, 3, out, null, 0 ); // $ExpectError + rightShift.assign( 1, 2, 3, out, undefined, 0 ); // $ExpectError + rightShift.assign( 1, 2, 3, out, '5', 0 ); // $ExpectError + rightShift.assign( 1, 2, 3, out, [], 0 ); // $ExpectError + rightShift.assign( 1, 2, 3, out, {}, 0 ); // $ExpectError + rightShift.assign( 1, 2, 3, out, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... +{ + const out = new Uint32Array( 2 ); + + rightShift.assign( 1, 2, 3, out, 1, true ); // $ExpectError + rightShift.assign( 1, 2, 3, out, 1, false ); // $ExpectError + rightShift.assign( 1, 2, 3, out, 1, null ); // $ExpectError + rightShift.assign( 1, 2, 3, out, 1, undefined ); // $ExpectError + rightShift.assign( 1, 2, 3, out, 1, '5' ); // $ExpectError + rightShift.assign( 1, 2, 3, out, 1, [] ); // $ExpectError + rightShift.assign( 1, 2, 3, out, 1, {} ); // $ExpectError + rightShift.assign( 1, 2, 3, out, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... +{ + const out = new Uint32Array( 2 ); + + rightShift.assign(); // $ExpectError + rightShift.assign( 1 ); // $ExpectError + rightShift.assign( 1, 2 ); // $ExpectError + rightShift.assign( 1, 2, 3 ); // $ExpectError + rightShift.assign( 1, 2, 3 ); // $ExpectError + rightShift.assign( 1, 2, 3, out ); // $ExpectError + rightShift.assign( 1, 2, 3, out, 1 ); // $ExpectError + rightShift.assign( 1, 2, 3, out, 1, 0, {} ); // $ExpectError +} + +// Attached to the main export is a `strided` method which returns a collection... +{ + const a = new Uint32Array( 2 ); + + rightShift.strided( a, 1, 0, 1, new Uint32Array( 2 ), 1, 0 ); // $ExpectType Uint32Array + rightShift.strided( a, 1, 0, 1, new Float64Array( 2 ), 1, 0 ); // $ExpectType Float64Array + rightShift.strided( a, 1, 0, 1, [ 0, 0 ], 1, 0 ); // $ExpectType number[] +} + +// The compiler throws an error if the `strided` method is provided a first argument which is not a collection... +{ + const out = new Uint32Array( 2 ); + + rightShift.strided( true, 1, 0, 1, out, 1, 0 ); // $ExpectError + rightShift.strided( false, 1, 0, 1, out, 1, 0 ); // $ExpectError + rightShift.strided( null, 1, 0, 1, out, 1, 0 ); // $ExpectError + rightShift.strided( undefined, 1, 0, 1, out, 1, 0 ); // $ExpectError + rightShift.strided( '5', 1, 0, 1, out, 1, 0 ); // $ExpectError + rightShift.strided( [ '5' ], 1, 0, 1, out, 1, 0 ); // $ExpectError + rightShift.strided( {}, 1, 0, 1, out, 1, 0 ); // $ExpectError + rightShift.strided( ( x: number ): number => x, 1, 0, 1, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided a second argument which is not a number... +{ + const a = new Uint32Array( 2 ); + const out = new Uint32Array( 2 ); + + rightShift.strided( a, true, 0, 1, out, 1, 0 ); // $ExpectError + rightShift.strided( a, false, 0, 1, out, 1, 0 ); // $ExpectError + rightShift.strided( a, null, 0, 1, out, 1, 0 ); // $ExpectError + rightShift.strided( a, undefined, 0, 1, out, 1, 0 ); // $ExpectError + rightShift.strided( a, '5', 0, 1, out, 1, 0 ); // $ExpectError + rightShift.strided( a, [], 0, 1, out, 1, 0 ); // $ExpectError + rightShift.strided( a, {}, 0, 1, out, 1, 0 ); // $ExpectError + rightShift.strided( a, ( x: number ): number => x, 0, 1, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided a third argument which is not a number... +{ + const a = new Uint32Array( 2 ); + const out = new Uint32Array( 2 ); + + rightShift.strided( a, 1, true, 1, out, 1, 0 ); // $ExpectError + rightShift.strided( a, 1, false, 1, out, 1, 0 ); // $ExpectError + rightShift.strided( a, 1, null, 1, out, 1, 0 ); // $ExpectError + rightShift.strided( a, 1, undefined, 1, out, 1, 0 ); // $ExpectError + rightShift.strided( a, 1, '5', 1, out, 1, 0 ); // $ExpectError + rightShift.strided( a, 1, [], 1, out, 1, 0 ); // $ExpectError + rightShift.strided( a, 1, {}, 1, out, 1, 0 ); // $ExpectError + rightShift.strided( a, 1, ( x: number ): number => x, 1, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided a fourth argument which is not a number... +{ + const a = new Uint32Array( 2 ); + const out = new Uint32Array( 2 ); + + rightShift.strided( a, 1, 0, true, out, 1, 0 ); // $ExpectError + rightShift.strided( a, 1, 0, false, out, 1, 0 ); // $ExpectError + rightShift.strided( a, 1, 0, null, out, 1, 0 ); // $ExpectError + rightShift.strided( a, 1, 0, undefined, out, 1, 0 ); // $ExpectError + rightShift.strided( a, 1, 0, '5', out, 1, 0 ); // $ExpectError + rightShift.strided( a, 1, 0, [], out, 1, 0 ); // $ExpectError + rightShift.strided( a, 1, 0, {}, out, 1, 0 ); // $ExpectError + rightShift.strided( a, 1, 0, ( x: number ): number => x, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided a fifth argument which is not a collection... +{ + const a = new Uint32Array( 2 ); + + rightShift.strided( a, 1, 0, 1, 1, 1, 0 ); // $ExpectError + rightShift.strided( a, 1, 0, 1, true, 1, 0 ); // $ExpectError + rightShift.strided( a, 1, 0, 1, false, 1, 0 ); // $ExpectError + rightShift.strided( a, 1, 0, 1, null, 1, 0 ); // $ExpectError + rightShift.strided( a, 1, 0, 1, undefined, 1, 0 ); // $ExpectError + rightShift.strided( a, 1, 0, 1, '5', 1, 0 ); // $ExpectError + rightShift.strided( a, 1, 0, 1, [ '5' ], 1, 0 ); // $ExpectError + rightShift.strided( a, 1, 0, 1, {}, 1, 0 ); // $ExpectError + rightShift.strided( a, 1, 0, 1, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided an sixth argument which is not a number... +{ + const a = new Uint32Array( 2 ); + const out = new Uint32Array( 2 ); + + rightShift.strided( a, 1, 0, 1, out, true, 0 ); // $ExpectError + rightShift.strided( a, 1, 0, 1, out, false, 0 ); // $ExpectError + rightShift.strided( a, 1, 0, 1, out, null, 0 ); // $ExpectError + rightShift.strided( a, 1, 0, 1, out, undefined, 0 ); // $ExpectError + rightShift.strided( a, 1, 0, 1, out, '5', 0 ); // $ExpectError + rightShift.strided( a, 1, 0, 1, out, [], 0 ); // $ExpectError + rightShift.strided( a, 1, 0, 1, out, {}, 0 ); // $ExpectError + rightShift.strided( a, 1, 0, 1, out, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided a seventh argument which is not a number... +{ + const a = new Uint32Array( 2 ); + const out = new Uint32Array( 2 ); + + rightShift.strided( a, 1, 0, 1, out, 1, true ); // $ExpectError + rightShift.strided( a, 1, 0, 1, out, 1, false ); // $ExpectError + rightShift.strided( a, 1, 0, 1, out, 1, null ); // $ExpectError + rightShift.strided( a, 1, 0, 1, out, 1, undefined ); // $ExpectError + rightShift.strided( a, 1, 0, 1, out, 1, '5' ); // $ExpectError + rightShift.strided( a, 1, 0, 1, out, 1, [] ); // $ExpectError + rightShift.strided( a, 1, 0, 1, out, 1, {} ); // $ExpectError + rightShift.strided( a, 1, 0, 1, out, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided an unsupported number of arguments... +{ + const a = new Uint32Array( 2 ); + const out = new Uint32Array( 2 ); + + rightShift.strided(); // $ExpectError + rightShift.strided( a ); // $ExpectError + rightShift.strided( a, 1 ); // $ExpectError + rightShift.strided( a, 1, 0 ); // $ExpectError + rightShift.strided( a, 1, 0, 1 ); // $ExpectError + rightShift.strided( a, 1, 0, 1, out ); // $ExpectError + rightShift.strided( a, 1, 0, 1, out, 1 ); // $ExpectError + rightShift.strided( a, 1, 0, 1, out, 1, 0, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/number/uint64/base/right-shift/examples/index.js b/lib/node_modules/@stdlib/number/uint64/base/right-shift/examples/index.js new file mode 100644 index 000000000000..829745a4f0c0 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/right-shift/examples/index.js @@ -0,0 +1,32 @@ +/** +* @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 zeroTo = require( '@stdlib/array/zero-to' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var rightShift = require( './../lib' ); + +var a = Uint64.of( 0xdeadbeef, 0x0badf00d ); +// returns + +var shifts = zeroTo( 64, 'uint32' ); +// returns + +logEachMap( 'rightShift(%x, %s) = %b', a, shifts, rightShift ); diff --git a/lib/node_modules/@stdlib/number/uint64/base/right-shift/lib/assign.js b/lib/node_modules/@stdlib/number/uint64/base/right-shift/lib/assign.js new file mode 100644 index 000000000000..eaa84c6ef781 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/right-shift/lib/assign.js @@ -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'; + +// VARIABLES // + +// Shift mask: 0x3f => 00000000000000000000000000111111 +var MAX_SHIFT = 63 >>> 0; + + +// MAIN // + +/** +* Performs bitwise shift to the right on a 64-bit unsigned integer and assigns results to a provided output array. +* +* @param {uinteger32} ah - high 32-bit word of the 64-bit unsigned integer +* @param {uinteger32} al - low 32-bit word of the 64-bit unsigned integer +* @param {uinteger32} shift - number of bits to shift (0-63) +* @param {Collection} out - output array +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - starting index +* @returns {Collection} output array +* +* @example +* var Uint32Array = require( '@stdlib/array/uint32' ); +* +* var out = assign( 2, 4, 1, new Uint32Array( 2 ), 1, 0 ); +* // returns [ 1, 2 ] +*/ +function assign( ah, al, shift, out, stride, offset ) { + ah >>>= 0; + al >>>= 0; + shift &= MAX_SHIFT; + + if ( shift === 0 ) { + out[ offset ] = ah >>> 0; + out[ offset + stride ] = al >>> 0; + } else if ( shift < 32 ) { + out[ offset ] = ah >>> shift; + out[ offset + stride ] = ( ( al >>> shift ) | ( ah << ( 32 - shift ) ) ) >>> 0; // eslint-disable-line max-len + } else { + out[ offset ] = 0; + out[ offset + stride ] = ah >>> ( shift - 32 ); + } + return out; +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/number/uint64/base/right-shift/lib/index.js b/lib/node_modules/@stdlib/number/uint64/base/right-shift/lib/index.js new file mode 100644 index 000000000000..9b602bca0aa3 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/right-shift/lib/index.js @@ -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'; + +/** +* Perform bitwise shift to the right on a 64-bit unsigned integer. +* +* @module @stdlib/number/uint64/base/right-shift +* +* @example +* var Uint64 = require( '@stdlib/number/uint64/ctor' ); +* var rightShift = require( '@stdlib/number/uint64/base/right-shift' ); +* +* var a = new Uint64( 10 ); +* +* var v = rightShift( a, 1 ); +* // returns [ 5n ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var assign = require( './assign.js' ); +var strided = require( './strided.js' ); + + +// MAIN // + +setReadOnly( main, 'assign', assign ); +setReadOnly( main, 'strided', strided ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "assign": "main.assign", "strided": "main.strided" } diff --git a/lib/node_modules/@stdlib/number/uint64/base/right-shift/lib/main.js b/lib/node_modules/@stdlib/number/uint64/base/right-shift/lib/main.js new file mode 100644 index 000000000000..9f51b7dc044b --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/right-shift/lib/main.js @@ -0,0 +1,60 @@ +/** +* @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 toWords = require( '@stdlib/number/uint64/base/to-words' ).assign; +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var assign = require( './assign.js' ); + + +// VARIABLES // + +var WORKSPACE = new Uint32Array( 4 ); + + +// MAIN // + +/** +* Performs bitwise shift to the right on a 64-bit unsigned integer. +* +* @param {Uint64} a - 64-bit unsigned integer +* @param {uinteger32} shift - number of bits to shift (0-63) +* @returns {Uint64} result +* +* @example +* var Uint64 = require( '@stdlib/number/uint64/ctor' ); +* +* var a = new Uint64( 10 ); +* +* var v = rightShift( a, 1 ); +* // returns [ 5n ] +*/ +function rightShift( a, shift ) { + toWords( a, WORKSPACE, 1, 0 ); + assign( WORKSPACE[0], WORKSPACE[1], shift, WORKSPACE, 1, 2 ); + return Uint64.of( WORKSPACE[2], WORKSPACE[3] ); +} + + +// EXPORTS // + +module.exports = rightShift; diff --git a/lib/node_modules/@stdlib/number/uint64/base/right-shift/lib/strided.js b/lib/node_modules/@stdlib/number/uint64/base/right-shift/lib/strided.js new file mode 100644 index 000000000000..6dd7db0c0f57 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/right-shift/lib/strided.js @@ -0,0 +1,56 @@ +/** +* @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 assign = require( './assign.js' ); + + +// MAIN // + +/** +* 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. +* +* @param {Collection} a - 64-bit unsigned integer strided array view containing interleaved 32-bit unsigned integer high and low order words +* @param {integer} sa - stride length for `a` +* @param {NonNegativeInteger} oa - starting index for `a` +* @param {uinteger32} shift - number of bits to shift (0-63) +* @param {Collection} out - output array +* @param {integer} so - stride length for `out` +* @param {NonNegativeInteger} oo - starting index for `out` +* @returns {Collection} output array +* +* @example +* var Uint32Array = require( '@stdlib/array/uint32' ); +* +* var a = new Uint32Array( [ 2, 4 ] ); +* +* var out = strided( a, 1, 0, 1, new Uint32Array( 2 ), 1, 0 ); +* // returns [ 1, 2 ] +*/ +function strided( a, sa, oa, shift, out, so, oo ) { + assign( a[ oa ], a[ oa+sa ], shift, out, so, oo ); + return out; +} + + +// EXPORTS // + +module.exports = strided; diff --git a/lib/node_modules/@stdlib/number/uint64/base/right-shift/package.json b/lib/node_modules/@stdlib/number/uint64/base/right-shift/package.json new file mode 100644 index 000000000000..c726e809e28c --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/right-shift/package.json @@ -0,0 +1,64 @@ +{ + "name": "@stdlib/number/uint64/base/right-shift", + "version": "0.0.0", + "description": "Perform bitwise shift to the right on a 64-bit unsigned integer.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "bitwise", + "shift", + "right", + "shiftr", + "rshift", + "uint64", + "64-bit", + "unsigned", + "integer" + ] +} diff --git a/lib/node_modules/@stdlib/number/uint64/base/right-shift/test/test.assign.js b/lib/node_modules/@stdlib/number/uint64/base/right-shift/test/test.assign.js new file mode 100644 index 000000000000..9ac9dd6cb665 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/right-shift/test/test.assign.js @@ -0,0 +1,71 @@ +/** +* @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 tape = require( 'tape' ); +var isEqualUint32Array = require( '@stdlib/assert/is-equal-uint32array' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var rightShift = require( './../lib/assign.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof rightShift, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function performs bitwise shift to the right on a 64-bit unsigned integer', function test( t ) { + var expected; + var out; + var v; + + // Trivial stride and offset: + out = new Uint32Array( 2 ); + v = rightShift( 2, 4, 1, out, 1, 0 ); + expected = new Uint32Array( [ 1, 2 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isEqualUint32Array( out, expected ), true, 'returns expected value' ); + + // Positive stride: + out = new Uint32Array( 4 ); + v = rightShift( 2, 4, 1, out, 2, 0 ); + expected = new Uint32Array( [ 1, 0, 2, 0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isEqualUint32Array( out, expected ), true, 'returns expected value' ); + + // Positive stride and non-zero offset: + out = new Uint32Array( 4 ); + v = rightShift( 2, 4, 1, out, 2, 1 ); + expected = new Uint32Array( [ 0, 1, 0, 2 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isEqualUint32Array( out, expected ), true, 'returns expected value' ); + + // Negative stride and non-zero offset: + out = new Uint32Array( 2 ); + v = rightShift( 2, 4, 1, out, -1, 1 ); + expected = new Uint32Array( [ 2, 1 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isEqualUint32Array( out, expected ), true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/number/uint64/base/right-shift/test/test.js b/lib/node_modules/@stdlib/number/uint64/base/right-shift/test/test.js new file mode 100644 index 000000000000..4ebf4c3d1e21 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/right-shift/test/test.js @@ -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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isMethod = require( '@stdlib/assert/is-method' ); +var rightShift = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof rightShift, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( rightShift, 'assign' ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main export is a `strided` method', function test( t ) { + t.strictEqual( isMethod( rightShift, 'strided' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/number/uint64/base/right-shift/test/test.main.js b/lib/node_modules/@stdlib/number/uint64/base/right-shift/test/test.main.js new file mode 100644 index 000000000000..9f163475fc75 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/right-shift/test/test.main.js @@ -0,0 +1,152 @@ +/** +* @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 tape = require( 'tape' ); +var hasBigIntSupport = require( '@stdlib/assert/has-bigint-support' ); +var BigInt = require( '@stdlib/bigint/ctor' ); +var UINT32_MAX = require( '@stdlib/constants/uint32/max' ); +var isEqual = require( '@stdlib/number/uint64/base/assert/is-equal' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var rightShift = require( './../lib' ); + + +// VARIABLES // + +// Shift mask: 0x3f => 00000000000000000000000000111111 +var MAX_SHIFT = 63 >>> 0; + +var opts = { + 'skip': !hasBigIntSupport() +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof rightShift, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function performs bitwise shift to the right on a 64-bit unsigned integer', function test( t ) { + var expected; + var out; + var a; + + // Zero shift: + a = new Uint64( 1234 ); + out = rightShift( a, 0 ); + expected = new Uint64( 1234 ); + t.strictEqual( isEqual( out, expected ), true, 'returns expected value' ); + + // Small shift: + a = new Uint64( 1234 ); + out = rightShift( a, 1 ); + expected = new Uint64( 617 ); + t.strictEqual( isEqual( out, expected ), true, 'returns expected value' ); + + a = new Uint64( 1234 ); + out = rightShift( a, 2 ); + expected = new Uint64( 308 ); + t.strictEqual( isEqual( out, expected ), true, 'returns expected value' ); + + a = new Uint64( 0xffffffff ); + out = rightShift( a, 31 ); + expected = new Uint64( 1 ); + t.strictEqual( isEqual( out, expected ), true, 'returns expected value' ); + + // Large shift: + a = new Uint64( 0xffffffff ); + out = rightShift( a, 32 ); + expected = new Uint64( 0 ); + t.strictEqual( isEqual( out, expected ), true, 'returns expected value' ); + + a = new Uint64( 9876543210 ); + out = rightShift( a, 32 ); + expected = new Uint64( 2 ); + t.strictEqual( isEqual( out, expected ), true, 'returns expected value' ); + + a = Uint64.of( 0x12345678, 0x90abcdef ); + out = rightShift( a, 48 ); + expected = Uint64.of( 0, 0x1234 ); + t.strictEqual( isEqual( out, expected ), true, 'returns expected value' ); + + a = Uint64.of( 0xffffffff, 0xffffffff ); + out = rightShift( a, 63 ); + expected = Uint64.of( 0, 1 ); + t.strictEqual( isEqual( out, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs bitwise shift to the right on a 64-bit unsigned integer (random values)', opts, function test( t ) { + var big64shifted; + var expected; + var values; + var shift; + var out; + var a; + var x; + var i; + + x = discreteUniform( 100, 0, UINT32_MAX, { + 'dtype': 'uint32' + }); + values = []; + for ( i = 0; i < x.length; i++ ) { + values.push( Uint64.of( x[ i ], x[ (i+1)%x.length ] ) ); + } + + for ( i = 0; i < values.length; i++ ) { + a = values[ i ]; + for ( shift = 0; shift < 64; shift++ ) { + out = rightShift( a, shift ); + big64shifted = BigInt.asUintN( 64, a.valueOf() >> BigInt( shift ) ); + expected = new Uint64( big64shifted ); + t.strictEqual( isEqual( out, expected ), true, 'returns expected value' ); + } + } + + t.end(); +}); + +tape( 'if provided a shift less than `0` or greater than `63`, the function performs a bitwise right shift based on the `6` least significant bits', function test( t ) { + var expected; + var shift; + var out; + var a; + + a = Uint64.of( 0x12345678, 0x90abcdef ); + + for ( shift = -100; shift < 0; shift++ ) { + out = rightShift( a, shift ); + expected = rightShift( a, shift&MAX_SHIFT ); + t.strictEqual( isEqual( out, expected ), true, 'returns expected value' ); + } + for ( shift = 64; shift < 150; shift++ ) { + out = rightShift( a, shift ); + expected = rightShift( a, shift&MAX_SHIFT ); + t.strictEqual( isEqual( out, expected ), true, 'returns expected value' ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/number/uint64/base/right-shift/test/test.strided.js b/lib/node_modules/@stdlib/number/uint64/base/right-shift/test/test.strided.js new file mode 100644 index 000000000000..d9b69d3d21bb --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/right-shift/test/test.strided.js @@ -0,0 +1,76 @@ +/** +* @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 tape = require( 'tape' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var isEqualUint32Array = require( '@stdlib/assert/is-equal-uint32array' ); +var rightShift = require( './../lib/strided.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof rightShift, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function performs bitwise shift to the right on a 64-bit unsigned integer', function test( t ) { + var expected; + var out; + var a; + var v; + + // Trivial stride and offset: + a = new Uint32Array( [ 2, 4 ] ); + out = new Uint32Array( 2 ); + v = rightShift( a, 1, 0, 1, out, 1, 0 ); + expected = new Uint32Array( [ 1, 2 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isEqualUint32Array( out, expected ), true, 'returns expected value' ); + + // Positive stride: + a = new Uint32Array( [ 2, 0, 0, 4, 0, 0 ] ); + out = new Uint32Array( 2 ); + v = rightShift( a, 3, 0, 1, out, 1, 0 ); + expected = new Uint32Array( [ 1, 2 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isEqualUint32Array( out, expected ), true, 'returns expected value' ); + + // Positive stride and non-zero offset: + a = new Uint32Array( [ 0, 0, 2, 0, 0, 4 ] ); + out = new Uint32Array( 2 ); + v = rightShift( a, 3, 2, 1, out, 1, 0 ); + expected = new Uint32Array( [ 1, 2 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isEqualUint32Array( out, expected ), true, 'returns expected value' ); + + // Negative stride and non-zero offset: + a = new Uint32Array( [ 0, 0, 4, 0, 0, 2 ] ); + out = new Uint32Array( 2 ); + v = rightShift( a, -3, 5, 1, out, 1, 0 ); + expected = new Uint32Array( [ 1, 2 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isEqualUint32Array( out, expected ), true, 'returns expected value' ); + + t.end(); +});