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

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

-->

# setLowWord

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

<section class="usage">

## Usage

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

#### setLowWord( x, low )

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

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

var a = new Uint64( 4294967296 );
// returns <Uint64>[ 4294967296n ]

var b = setLowWord( a, 2 );
// returns <Uint64>[ 4294967298n ]

var w = getLowWord( b );
// returns 2
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- The function returns a new [64-bit unsigned integer][@stdlib/number/uint64/ctor] instance without modifying the input value.

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

```javascript
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var UINT32_MAX = require( '@stdlib/constants/uint32/max' );
var Uint64 = require( '@stdlib/number/uint64/ctor' );
var logEachMap = require( '@stdlib/console/log-each-map' );
var setLowWord = require( '@stdlib/number/uint64/base/set-low-word' );

var a = new Uint64( 4294967296 );
// returns <Uint64>

var words = discreteUniform( 100, 0, UINT32_MAX, {
'dtype': 'uint32'
});

logEachMap( 'setLowWord(%s, %s) = %s', a, words, setLowWord );
```

</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,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 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 pkg = require( './../package.json' ).name;
var setLowWord = require( './../lib' );


// MAIN //

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

N = 100;
values = discreteUniform( N, 0, UINT32_MAX, {
'dtype': 'uint32'
});

a = new Uint64( 0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
z = setLowWord( a, values[ i % N ] );
if ( typeof z !== 'object' ) {
b.fail( 'should return a Uint64 instance' );
}
}
b.toc();
if ( !( z instanceof Uint64 ) ) {
b.fail( 'should return a Uint64 instance' );
}
b.pass( 'benchmark finished' );
b.end();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

{{alias}}( a, low )
Sets the low 32-bit word of a 64-bit unsigned integer.

The function returns a new Uint64 instance without modifying the input
value.

Parameters
----------
a: Uint64
64-bit unsigned integer.

low: integer
32-bit unsigned integer to replace the low 32-bit word.

Returns
-------
out: Uint64
64-bit unsigned integer.

Examples
--------
> var a = new {{alias:@stdlib/number/uint64/ctor}}( 4294967296 )
<Uint64>[ 4294967296n ]
> var b = {{alias}}( a, 2 )
<Uint64>[ 4294967298n ]
> var w = {{alias:@stdlib/number/uint64/base/get-low-word}}( b )
2

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 { Uint64 } from '@stdlib/types/number';

/**
* Sets the low 32-bit word of a 64-bit unsigned integer.
*
* @param a - 64-bit unsigned integer
* @param low - 32-bit unsigned integer to replace the low 32-bit word
* @returns 64-bit unsigned integer
*
* @example
* var getLowWord = require( '@stdlib/number/uint64/base/get-low-word' );
* var Uint64 = require( '@stdlib/number/uint64/ctor' );
*
* var a = new Uint64( 4294967296 );
* // returns <Uint64>[ 4294967296n ]
*
* var b = setLowWord( a, 2 );
* // returns <Uint64>[ 4294967298n ]
*
* var w = getLowWord( b );
* // returns 2
*/
declare function setLowWord( a: Uint64, low: number ): Uint64;


// EXPORTS //

export = setLowWord;
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* @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 setLowWord = require( './index' );


// TESTS //

// The function returns a Uint64 instance...
{
const a = new Uint64( 5 );
setLowWord( a, 2 ); // $ExpectType Uint64
}

// The compiler throws an error if the function is provided a first argument that is not a Uint64 instance...
{
setLowWord( 'abc', 2 ); // $ExpectError
setLowWord( true, 2 ); // $ExpectError
setLowWord( false, 2 ); // $ExpectError
setLowWord( [], 2 ); // $ExpectError
setLowWord( {}, 2 ); // $ExpectError
setLowWord( ( x: number ): number => x, 2 ); // $ExpectError
}

// The compiler throws an error if the function is provided a second argument that is not a number...
{
const a = new Uint64( 5 );
setLowWord( a, 'abc' ); // $ExpectError
setLowWord( a, true ); // $ExpectError
setLowWord( a, false ); // $ExpectError
setLowWord( a, [] ); // $ExpectError
setLowWord( a, {} ); // $ExpectError
setLowWord( 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 );
setLowWord(); // $ExpectError
setLowWord( a ); // $ExpectError
setLowWord( a, 2, 0 ); // $ExpectError
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var UINT32_MAX = require( '@stdlib/constants/uint32/max' );
var Uint64 = require( '@stdlib/number/uint64/ctor' );
var logEachMap = require( '@stdlib/console/log-each-map' );
var setLowWord = require( './../lib' );

var a = new Uint64( 4294967296 );
// returns <Uint64>

var words = discreteUniform( 100, 0, UINT32_MAX, {
'dtype': 'uint32'
});

logEachMap( 'setLowWord(%s, %s) = %s', a, words, setLowWord );
Loading